By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

VBscript to delete games

P: 5
Hi to all,

I'm the newly appointed network administrator in our office, and upon scanning all the PCs that are connected to the network, (by the way we're using a windows 2000 server) almost all of them have games. It was the department policy that no games must be installed in each PC. Can you guys help me with this? or can you modify this VBscript?

Expand|Select|Wrap|Line Numbers
  1. dim strExcludedPC
  2.  
  3. ServerFileSave="\\S1-admin-06\User Area\Save\"
  4. strComputer = "."
  5. ctr=0
  6.  
  7. arExcludedPCs=Array("PC1","PC2")
  8.  
  9. Set objNetwork = Wscript.CreateObject("Wscript.Network")
  10. objComputerName = objNetwork.ComputerName
  11.  
  12. '===Check for computers that are excluded, then quit script===
  13. for Each strExcludedPC in arExcludedPCs
  14.     if objComputerName=strExcludedPC then
  15.         wscript.quit
  16.     end if
  17. Next
  18.  
  19. Set objWMIService = GetObject("winmgmts:" _
  20.  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  21.  
  22. Set colFiles = objWMIService.ExecQuery _
  23.  ("SELECT * FROM CIM_DataFile WHERE " _
  24.     & "FileName='bounce' AND Extension='exe' OR " _
  25.     & "FileName='avseq1' AND Extension='dat' OR " _
  26.     & "FileName='zagu' AND Extension='exe' OR " _
  27.     & "FileName='zagu1' AND Extension='exe' OR " _
  28.     & "FileName='zagu2' AND Extension='exe' OR " _
  29.     & "FileName='zagu3' AND Extension='exe' OR " _
  30.     & "FileName='MCFHuntsville' AND Extension='exe' OR " _
  31.     & "FileName='picachu' AND Extension='exe' OR " _
  32.     & "FileName='fight9' AND Extension='exe' OR " _
  33.     & "FileName='unfolding' AND Extension='exe' OR " _
  34.     & "FileName='wackywordsearch' AND Extension='exe' OR " _
  35.     & "FileName='sudoku' AND Extension='exe' OR " _
  36.     & "FileName='gridlock' AND Extension='exe' OR " _
  37.     & "FileName='cubedelic' AND Extension='exe' OR " _
  38.     & "FileName='magnetism' AND Extension='exe' OR " _
  39.     & "FileName='plumber' AND Extension='exe' OR " _
  40.     & "FileName='simon' AND Extension='exe' OR " _
  41.     & "FileName='plumber2' AND Extension='exe' OR " _
  42.     & "FileName='millionaire' AND Extension='exe' OR " _
  43.     & "FileName='xraye' AND Extension='exe' OR " _
  44.     & "FileName='Flash Games' AND Extension='exe' OR " _
  45.     & "FileName='acad' AND Extension='exe' OR " _
  46.     & "FileName='bou' AND Extension='exe' OR " _
  47.     & "FileName='scrabout' AND Extension='exe' OR " _
  48.     & "FileName='ttw' AND Extension='exe' OR " _
  49.     & "FileName='texttwist' AND Extension='exe' OR " _
  50.     & "FileName='hangaroo' AND Extension='exe' OR " _
  51.     & "FileName='hangman' AND Extension='exe' OR " _
  52.     & "FileName='same' AND Extension='exe' OR " _
  53.     & "FileName='zuma' AND Extension='exe' OR " _
  54.     & "FileName='zuma deluxe' AND Extension='exe' OR " _
  55.     & "FileName='zuma deluxe' AND Extension='zip' OR " _
  56.     & "FileName='bookworm' AND Extension='exe' OR " _
  57.     & "FileName='BookwormAdventures' AND Extension='exe' OR " _
  58.     & "FileName='BookWorm Adventures Deluxe From GameHouse By TFT-TEAM' AND Extension='exe' OR " _
  59.     & "FileName='pyramid' AND Extension='exe' OR " _
  60.     & "FileName='dynomite' AND Extension='exe' OR " _
  61.     & "FileName='riveriqgame' AND Extension='exe' OR " _
  62.     & "FileName='ra2' AND Extension='exe' OR " _
  63.     & "FileName='game' AND Extension='exe' OR " _
  64.     & "FileName='collapse' AND Extension='exe' OR " _
  65.     & "FileName='arcanoid' AND Extension='exe' OR " _
  66.     & "FileName='ptanks' AND Extension='exe' OR " _
  67.     & "FileName='feedingfrenzy' AND Extension='exe' OR " _
  68.     & "FileName='feedingfrenzy' AND Extension='zip' OR " _
  69.     & "FileName='scrabble' AND Extension='exe' OR " _
  70.     & "FileName='pool' AND Extension='exe' OR " _
  71.     & "FileName='blocks' AND Extension='exe' OR " _
  72.     & "FileName='allout' AND Extension='exe' OR " _
  73.     & "FileName='winamp' AND Extension='exe' OR " _
  74.     & "FileName='milyonaryo' AND Extension='exe' OR " _
  75.     & "FileName='tumblebugs' AND Extension='exe' OR " _
  76.     & "FileName='bob' AND Extension='exe' OR " _
  77.     & "FileName='bob' AND Extension='rwg' OR " _
  78.     & "FileName='MysteryCaseFiles' AND Extension='rwg' OR " _
  79.     & "FileName='PrimeSuspects' AND Extension='rwg' OR " _
  80.     & "Extension='mp3' OR Extension='mp4' or Extension='mpeg' OR Extension='wma'")
  81.  
  82.  
  83. '===Check if files found===
  84. For Each objFile in colFiles
  85.    ctr=ctr+1
  86. Next
  87.  
  88. '===Quit if no files found===
  89. if ctr=0 then
  90.     WScript.Quit
  91. end if
  92.  
  93. '===else write the text file==================================================================> games found
  94. objUserName = objNetwork.UserName
  95. mySaveFile="C:\" & objComputerName & ".txt"
  96.  
  97. Set fs = CreateObject("Scripting.FileSystemObject")
  98.  
  99. '===if server save folder does not exist, quit program===
  100. if NOT fs.FolderExists(ServerFileSave) then
  101. '======    msgbox "folder does not exist"
  102.     WScript.Quit
  103. end if
  104.  
  105. '===else determine if for appending or new create===
  106. if fs.FileExists(ServerFileSave & objComputerName & ".txt") then
  107.      Set myScriptFile = fs.OpenTextFile(mySaveFile, 8, True)
  108. else
  109.      Set myScriptFile = fs.CreateTextFile(mySaveFile, True)
  110. end if
  111.  
  112.  myScriptFile.WriteLine("-----------------------------------------------------------")
  113.  myScriptFile.WriteLine("The Network Administrator")
  114.  myScriptFile.WriteLine("Games and music files found at " & objComputerName & "@" & objUserName)
  115.  myScriptFile.WriteLine("Date: " & date() & "    Time: " & Time())
  116.  myScriptFile.WriteLine("===========================================================")
  117.  myScriptFile.WriteLine("NOTE: The following files are prohibited from our network")
  118.  myScriptFile.WriteLine("      and will be deleted automatically:")
  119.  myScriptFile.WriteLine("")
  120.  
  121.  
  122. '===Delete the files found===
  123. For Each objFile in colFiles
  124.  objFile.Delete
  125.  myScriptFile.WriteLine(objFile.Name)
  126.  ctr=ctr+1
  127. Next
  128.  
  129.    myScriptFile.WriteLine("")
  130.    myScriptFile.Close
  131.  
  132. '===Copy listing file to server===
  133. fs.CopyFile mySaveFile, ServerFileSave
  134. 'fs.DeleteFile mySaveFile (do not delete save files)
  135.  
  136. '===if games found, open txt file as warning to the user===        
  137. Set WshShell = WScript.CreateObject("WScript.Shell")
  138. WshShell.Run mySaveFile
  139.  
  140.  
  141. '    & "FileName='sol' AND Extension='lnk' OR " _
  142. '    & "FileName='freecell' AND Extension='lnk' OR " _
  143. '    & "FileName='winmine' AND Extension='lnk' OR " _
  144. '    & "FileName='msheart' AND Extension='lnk' OR " _
  145. '    & "FileName='pinball' AND Extension='lnk' OR " _
  146.  
  147.  
  148.  
  149.  
  150. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  151. Function CheckTrend()
  152.  
  153. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  154.     strComputer = "."
  155.     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  156.  
  157.     Set colFiles2 = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE FileName='lpt$vpn'")
  158.  
  159.     '===Check if files found===
  160.     For Each objFile in colFiles2
  161.        ctr=ctr+1
  162.     Next
  163.  
  164.     '===Quit if no files found===
  165.     if ctr=0 then
  166.      myScriptFile.WriteLine("No TrendMicro virus pattern found!!!")
  167.     end if
  168.  
  169.     Dim fso, f
  170.     Set fso = CreateObject("Scripting.FileSystemObject")
  171.  
  172.     '===Write files found===
  173.     For Each objFile in colFiles2
  174.      myScriptFile.WriteLine(objFile.Name)
  175.      Set f = fso.GetFile(objFile.Name)
  176.      myScriptFile.WriteLine("   date created: " & f.DateCreated)
  177.      myScriptFile.WriteLine("")
  178.      ctr=ctr+1
  179.     Next
  180.  
  181. End Function
Sep 11 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
Can you be more specific as to what help you need?
Sep 12 '07 #2

P: 5
sir,

the script doesn't seem to work. I have made also a logon batch file that will call the script that everytime that a user log-in, the script executes, but it wo'nt. the games are still there.
Sep 12 '07 #3

Expert 5K+
P: 8,434
Well, I'm not familiar with VBScript, but I do wonder whether your conditions might need to be grouped with parentheses.
For instances...

Expand|Select|Wrap|Line Numbers
  1. Set colFiles = objWMIService.ExecQuery _
  2. ("SELECT * FROM CIM_DataFile WHERE " _
  3. & "FileName='bounce' AND Extension='exe' OR " _
  4. & "FileName='avseq1' AND Extension='dat' OR " _
  5. & "FileName='zagu' AND Extension='exe' OR " _
  6.  
  7. ' Could become...
  8.  
  9. Set colFiles = objWMIService.ExecQuery _
  10. ("SELECT * FROM CIM_DataFile WHERE " _
  11. & "(FileName='bounce' AND Extension='exe') OR " _
  12. & "(FileName='avseq1' AND Extension='dat') OR " _
  13. & "(FileName='zagu' AND Extension='exe') OR " _
Sep 12 '07 #4

Expert 5K+
P: 8,434
Ok, I'm just having a read through the script now, and a few things come to mind...
  • Collections have a .Count property, so you shouldn't need to do a For Each loop just to count the items.
  • As standard debugging practice, you should determine what happens at each step in your script. For instance, what is returned by the ExecQuery? What is returned if you leave out the WHERE clause, or make it something more broad such as just 'TXT' in the extension?
  • Is the query case-sensitive? (I have no experience with WMI.)
  • Does CreateTextFile() also open the file? (Perhaps that's what the True parameter means?)
  • Is it possible the person logged on doesn't have permission to see the ServerFileSave folder?
  • In the call to GetObject() is it intentional using strComputer which just contains "."? I wondered whether perhaps it should be objComputerName. Not suggesting, just asking.
  • As a safety measure, wouldn't it be a good idea to copy each file to some backup location on the network before deleting it? (Preferably one where the user can't just retrieve it themselves, of course).
  • I have to admit, I'm probably more on the side of the user - I hate this sort of Nazi approach on networks. But I just can't resist a programming challenge. :)
  • You're using ctr as a counter in a number of places, but without clearing it in between. So the later checks for If ctr = 0 can never be true. I think.
Sep 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.