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

New to Scripting need help closing games 2

Status
Not open for further replies.

RITec

MIS
Joined
May 15, 2002
Messages
98
Location
US
Hi Everyone,

I am new to scripting so any help much appreciated.

I ran across a script to close an application modified it to close Sol.exe,

Worked great

Created separate scripts to close winmine, and freecell, etc

I tried my luck at creating an array (never done that before)to just have one script but only the first instance close can someone let me know what I am doing wrong.

This works

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & 

"\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("select * from __instancecreationevent " _
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    if objLatestProcess.TargetInstance.Name = "sol.exe" then
    objLatestProcess.TargetInstance.Terminate
    End if
Loop

This closes sol.exe, and freecell.exe, but not winmine.exe

Code:
'Attemp to stop or shut down local games
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & 

"\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("select * from __instancecreationevent " _
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Tapps = Array("freecell.exe","sol.exe","winmine.exe")
For each tapp in tapps
Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    if objLatestProcess.TargetInstance.Name = tapps then
    objLatestProcess.TargetInstance.Terminate
    End if
Loop
next
Thank You

RITec
 
Looks good. Assuming that this is all of your code, then there are two suggestions that I would make.
1) Close any open files when you finish reading from them. This reduces the chance of the file being accidentally corrupted.
2) Set objects equal to nothing when you don't need them anymore. For a script this small, it really doesn't make a difference, but it is a good habit IMO.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Thanks for those pointers - I'll modify my code to include them!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top