iqzer0
iqzer0

Reputation: 163

VBScript Issue + I am trying to make it work on Windows XP

state = 1
While state = 1
    Set WshShell = WScript.CreateObject ("WScript.Shell")
    Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")
    Set oShell = CreateObject ("Wscript.Shell")
    For Each objProcess in colProcessList
        if objProcess.Name = "server.exe" And objProcess.Name = "cmd.exe" then
            vFound = True
        End if
    Next
    If vFound = True then
        wscript.sleep 10000
    Else
        Dim strArg, strArgs
        strArg = "pskill /accepteula cmd.exe"
        strArgs = "%windir%\psexec /accepteula \\server test.exe"
        oShell.Run strArg & oShell.Run strArgs, 0, false
        wscript.sleep 10000
    End If
    vFound = False
Wend

Please help me run this script properly, what I am trying to do is, if the 'server.exe' and 'cmd.exe' is not found in process, run the Dim strArg and strArgs.

Upvotes: 1

Views: 312

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

You get this error is that you're making a nested call to the Run method here:

oShell.Run strArg & oShell.Run strArgs, 0, false

To make this work you must put the parameter list of the nested call in parentheses:

oShell.Run strArg & oShell.Run(strArgs, 0, false)

However, it's not quite clear to me what you're trying to achieve here. Why are you concatenating the return value of one Run call with the command string of another Run call? Are you perhaps trying to run both commands in parallel? If so, you'd just have to do this:

oShell.Run strArg, 0, False
oShell.Run strArgs, 0, False

To run the commands sequentially, wait for each command to return:

oShell.Run strArg, 0, True
oShell.Run strArgs, 0, True

Upvotes: 3

Related Questions