VBScript code produces an Expected Statement error???
Hi, this is the VBScript code for the program described in this thread: http://www.codeguru.com/forum/showthread.php?t=433810
Code:
rem This application allows a user to run only one program (in this case "game.exe")
rem In case other programs are running, it terminates them
rem The same action will be taken with newly-executed programs
rem Set mandatory variables and objects
strComputer = "."
sec = 0
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery (" Select * from Win32_Process Where Name = 'game.exe' " )
rem Count how many processes where found (should be one as we compared only against 'game.exe')
rem This is done to check whether the game is started
colProcessListCounter = 0
For Each objProcess in colProcessList
colProcessListCounter = colProcessListCounter + 1
Next
rem Game is started? Good, let's go:
If colProcessListCounter = 1 Then
While colProcessListCounter = 1
rem The next three lines form an interval mechanism which
rem makes the process scanning below happen every 2 seconds
sec = Second(Time)
sec = sec / 2
If InStr(sec, ".") = 0 Then
rem Here we scan for rebellious applicationds which are not Game.exe and must be terminated:
Set colProcessList = objWMIService.ExecQuery (" Select * from Win32_Process Where Name <> 'game.exe' " )
For Each objProcess in colProcessList
rem Kill!
objProcess.Terminate()
Next
rem Now we check again whether Game.exe is still on - otherwise, we can end the script.
Set colProcessList = objWMIService.ExecQuery (" Select * from Win32_Process Where Name = 'game.exe' " )
colProcessListCounter = 0
For Each objProcess in colProcessList
colProcessListCounter = colProcessListCounter + 1
Next
end if
Wend
end if
End
However, the code produces an 'Expected Statement' error, and is not working. I'd really like to find out why
Thanks you for your kind help!
Re: VBScript code produces an Expected Statement error???
take out the end statement on the last line
how do you know it is not working?
Re: VBScript code produces an Expected Statement error???
Okay, now it's working, but I have a problem - My time mechanism isn't good, as it's consuming a lot of CPU because the loop goes on and on.
Maybe you have a suggestion fr a beter interval code?
Re: VBScript code produces an Expected Statement error???
you should always make a way to exit from the loop and stop the script
Re: VBScript code produces an Expected Statement error???