CreateProcess Method

Creates a new Windows NT process, optionally waits for the process to exit and returns the exit code. If the process does not end within the specified timeout period, it can be forcefully terminated.


obj.CreateProcess(ExePath String, CommandLine String, Wait Boolean, [TimeOut Long], [ForceTermination Boolean], [ExitCode Long])
Where obj is an OpScrUtil.Utility object.


ExePath Specifies the module to execute. Can be NULL, in which case the module name must be the first white space-delimited token in ExePath.
CommandLine Specifies the command line to execute. Can be NULL, in which case the ExePath is used as the command line.
Wait Specifies whether the function waits for the launched process to terminate.
TimeOut Specifies the length of time in seconds to wait for the launched process if Wait was specified. This parameter is optional. Defaults to 120 (default is adjustable in the registry).
ForceTermination Specifies whether the function terminates the launched process after the timeout has been reached. This parameter is optional. This parameter returns True or False on return to indicate whether the process was forcibly terminated.
ExitCode Returns the exit code of the launched process. This parameter is optional. Not available if Wait = False

Return Type



To launch the ping command and retrieve the exit code, terminating the process if it runs longer than 60 seconds, enter:

Dim obj, bForceTerminate, ExitCode
Set obj = CreateObject("OpScrUtil.Utility")
bOK = obj.CreateProcess("", "ping", True, 60, bForceTerminate, ExitCode)
If bOK Then
strMsg = "The exit code was " & ExitCode
If bForceTerminate Then strMsg = strMsg & "The process was forcibly terminated."
strMsg = "CreateProcess failed: " & obj.GetError()
End If