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 TouchToneTommy 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
May 15, 2002
98
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
 
Sorry for the typo, replace LatestProcess by objLatestProcess

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That did it

Thank you again for everyone's patience

any Idea about the dictionary?

I like the Idea of adding names to a file, that way anyone in IT can be tagged with updating list.

RITec
 
The problem with the dictionary version of the script should be the same, just the first section missing:

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

[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]
 
Tom,
This is what I have

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 
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("exclusions.txt")
Set oExcludeDict = CreateObject("Scripting.Dictionary")

While oFile.AtEndOfStream <> True
    strName = oFile.ReadLine
    On Error Resume Next
    oExcludeDict.Add strFile, 1
    On Error Goto 0
Wend
oFIle.close
Set oFso = Nothing
Set oFile = Nothing
Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    if oExcludeDict.Exists(objLatestProcess.TargetInstance.Name) = True 

then
            objLatestProcess.TargetInstance.Terminate
        End if
Loop

No errors

application stay open

text file in same folder named exclusions.txt

inside text file is

sol.exe
freecell.exe
winmine.exe

RITec
 
Replace this:
oExcludeDict.Add strFile, 1
by this:
oExcludeDict.Add strName, 1
To avoid this sort of things you may consider add this line at front of your script:
Option Explicit

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It worked

Thanks again

I added Option explicit to the top

you guys are great

[2thumbsup]
[cheers]
 
Hi everyone

I have now been instructed to uninstall all the games. not fun considering we have almost 300 computers.

Is there a script that will uninstall Win2K games? if so will it remove it from XP too?

I thought about using a script to delete the exe files for the games. Would that be a bad idea?

Should I start another thread for this?
 
I don't think you need another thread, but feel free to start one if you want. There are a few points that I'd like to make:

1) There is already software in existence that is designed specifically to address these sorts of needs. SMS will do it to some extent. Altiris and On technologies both do it well.

2) Removing the .exes will prevent the game from running and should not have any adverse affect.

3) Games that were installed using MSI packages are easily removed completely and safely in a programatic fashion.

4) Who is going to compile the list of banned games and determine how to detect them and remove them. As new games come out, this could potentially become a full time job. Which brings me to...

5) If you go the route of brute force removal, then you have made playing games in and of itself a game. I think a better solution would be to detect the presence of games and have an official reprimand process that ends in termination for repeat offenses.

Just my $2.00E-2

[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]
 
Tom,
1) We talked about SMS but, with city budget cuts were not getting a favorable answer. Altiris and On technologies is something I will have to look into.

2) Glad to hear removing the .exes should not have any adverse affect.

3) For the most part employees are not allowed to install games. though some have managed to install one or two. (The one who issues new machines has not been taking off the games like he was instructed to).

4) for now just standard games.

5) I agree with you on an official reprimand process that ends in termination for repeat offenses and one is place. I think I don't want to go into that. There is about 15 remote locations and some use a generic login.

I will be away from my desk for about an hour.


 
Well the first thing I would eliminate is generic logins or if that is not possible, then lock down the generic users to the point where they couldn't possibly install a game.

[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]
 
Can't eliminate the generic logins we have we have over a 100 part timers using these logins. which means more licenses.

I will get back to you when the bosses have made their decision. (they are discussing this0

Thank you again
for you time and patience

RITec
 
TomThumbKP and RITec,
There usually are no problems deleting the .exe's of the games. However, I have found that pinball is the worst thing to get rid of, as it seems to like to come back. Personally, I would have the individual who forgot to NOT install the games, go around and remove them, as he didn't completely fulfill his job like instructed. I know I stated this before, but 2003 and XP made it so much easier because of the restriced programs policy in Group Policy. I have not attempted to find out if there is a way to add the restricted programs within a 2000 system, and unfortuneatly, I don't have a 2000 system handy to play with. If at all possible, upgrade everything you can, as 2000 will soon be out of Microsoft's "upgrade/patch" system soon enough.....
 
Agreed with respect to upgrading. Using any builtin tools (i.e. Group Policies) is almost always better than trying to do it yourself. I also agree that whoever didn't do their job in the first place should bear the brunt of cleaning up the mess.

[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]
 
Unfortunatly I have the job of cleaning up. I can't go into specifics just that it's politics.

I will check into 2003 and XP restriced programs policy in Group Policy.

May take me some time because I don't have XP. But I can install it on an older machine to test.

I have not heard anything about 2000 being out of Microsoft's "upgrade/patch" system. any idea when?

I am going to lunch and have a meeting that will keep me out of the office this afternoon. I will check back when I get home.

Thanks for your help.

RITec
 
I would say 2005, but, with Microsoft getting so much heat over "dumping" 98, then reinstating it, who knows what Microsoft will do. Their logic is usually two OS's, so I would think when "longhorn" comes out, 2000 will soon follow.
 
I'm working on a similar script to close unwanted programs. I'm using a dictionary object to hold the list of exe's.

If I put a list of computers on the domain into another dictionary object, how can I monitor/kill processes on all the computers instead of just the local (".")?
 
Are you using Active Directory?

Maybe setup group policy for domain.
 
OK Here's what I ended up with - it works great.
Code:
if ucase(WScript.Arguments.Item(0)) = "Q" then
  WScript.echo "Running in quiet mode - no notification of terminations."
  QuietMode = True
else
  QuietMode = False
end if


Set objFSO = CreateObject("Scripting.FileSystemObject")

'BUILD THE COMPUTER LIST FROM FILE 

Set objComputers = CreateObject("Scripting.Dictionary")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\ComputerList.txt", 1)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objComputers.Add strNextLine, strNextLine
Loop


'BUILD THE UNWANTED SERVICE LIST FROM FILE

set objServices = CreateObject("Scripting.Dictionary")
    objServices.CompareMode = 1   'Text Compare
set objTextFile = objFSO.OpenTextFile _
     ("c:\scripts\BadProcesses.txt",1)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objServices.Add strNextLine, strNextLine
Loop

'CONTINUAL LOOP TO TERMINATE PROCESSES

do
    For each objComputer in objComputers
    strComputer = objComputers.Item(objComputer)
      Set objWMIService = GetObject("winmgmts:\\" & _
        strComputer & "\root\cimv2")
      Set colItems = objWMIService.ExecQuery("Select * from Win32_Process",,48)

      For Each objItem in colItems
          if objServices.Exists(objItem.Name) then
	      objItem.Terminate()
              if QuietMode = False then
                Wscript.echo now() & " - Terminated " & _
                    objItem.Name & " on " & strComputer
	      end if
	  end if
      Next 'objItem
    Next 'objComputer

   'Pause a bit
   WScript.Sleep 10000

loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top