Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS return code

Status
Not open for further replies.

alfie002

Technical User
Mar 3, 2004
121
GB
Dear all,

I have a script to individually copy a series of files from one location to another. I want to be able to check the return code of the copy command in order to write a successful copy message to a log file.

Does anyone have an example of this ?

Thanks

Alf
 
thanks RhythmAddict112.

Currently, I used this type of method, which is fine, however, with most scriting languages that I have used, they returns an exit code, which if 0, confirms a successful action.

Ideally, I like to stick with this. If I find anything, I'll post it.

Thanks again

Alf

 
If the copy operation fails in a detectable manner an exception will be raised. Just use proper exception handling logic and you'll have what you need.
 
This worked for me to return the result of a call to the 'fc' command to compare two files. It captures the exit code from 'fc' as the return value from the call to wscript.run:

function CompareFiles(file1, file2)
Dim objWshShell ' Windows script host shell object
dim nRetVal ' Applcation return value

set objWshShell = WScript.CreateObject("WScript.Shell")
nRetVal = objWshShell.run("fc /b " + chr(34) + file1 + chr(34) + " " + chr(34) + file2 + chr(34), 2, true)

CompareFiles = nRetVal
end function

Note:
Parameters passed to wscript.run
Param(1) - The command to be executed
Param(2) - sets the type of window in which the command runs (1=nromal, 2=minimised,.. - many other options)
Param(3) - true = wait for command completion (must be true if you want to capture the return value from the command)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top