|
-
Sep 13th, 2007, 04:45 AM
#1
Thread Starter
Junior Member
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!
Last edited by pilau; Sep 13th, 2007 at 04:48 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|