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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a remote script and pausing.

Status
Not open for further replies.
Apr 27, 1999
705
US
Hello,

I'm trying to run a script remotely, but need to know when the script completes before moving on to the next execution in VBScript. Does anyone have any ideas?

Thanks.

fengshui1998


' ****************************************
Function Remote_Cmd(Server, accnt, pwd, strCmd)
' ****************************************
' On Error Resume Next
Set Locator = CreateObject("WbemScripting.SWbemLocator")

Set Service = Locator.ConnectServer(Server, "root\cimv2", accnt, pwd)
Service.Security_.impersonationlevel = 3
Set Process = Service.Get("Win32_Process")
intStatus = Process.Create(strCmd, null, null, intProcessId)
' response.write err.number & " " & err.description
If err.number <> 0 then
Remote_Cmd = err.number & &quot; &quot; & err.description
else
Remote_Cmd = 0
End If
End Function
 
?????

The script Ends!

What comes after the End!

DO NOT USE END!
 
tbushmaker,

Actually what I gave you is a function. I'm calling the function that executes a command on a remote machine. The command searches for a sequence in a file and outputs it to
another file called found.txt. I don't want to continue execution until the &quot;find&quot; command is complete because of the huge file search. BTW, the function and search does work correctly.

fengshui1998
Thanks.

strcmd = &quot;cmd /C &quot;&quot;find /I &quot;&quot;string&quot;&quot; C:\temp\users.txt > c:\temp\found.txt&quot;&quot; &quot;
x = Remote_Cmd(&quot;servername&quot;, &quot;myaccnt&quot;, &quot;mypwd&quot;, strcmd)
 
If the Create method of Win32_Process successfully creates the process, your intProcessID will contain the Process ID (PID) of the established process on the remote PC. You will need to poll until this process terminates.

If intStatus = 0 Then
Do While True
Set oProc = Service.ExecQuery(&quot;Select * From Win32_Process Where ProcessID = &quot; & intProcessID)
If oProc.Count = 0 Then Exit Do
WScript.Sleep 100
Loop
End If Jon Hawkins
 
jonscott,

Thanks for your help. I already found out about the PROCESSID and have the script executing from a web page. Too bad wscript.sleep doesn't work in an ASP page but I can understand their reasoning with network timing.

fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top