VBscript to delete games

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viper888
    New Member
    • Sep 2007
    • 5

    VBscript to delete games

    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?

    [CODE=vb]dim strExcludedPC

    ServerFileSave= "\\S1-admin-06\User Area\Save\"
    strComputer = "."
    ctr=0

    arExcludedPCs=A rray("PC1","PC2 ")

    Set objNetwork = Wscript.CreateO bject("Wscript. Network")
    objComputerName = objNetwork.Comp uterName

    '===Check for computers that are excluded, then quit script===
    for Each strExcludedPC in arExcludedPCs
    if objComputerName =strExcludedPC then
    wscript.quit
    end if
    Next

    Set objWMIService = GetObject("winm gmts:" _
    & "{impersonation Level=impersona te}!\\" & strComputer & "\root\cimv 2")

    Set colFiles = objWMIService.E xecQuery _
    ("SELECT * FROM CIM_DataFile WHERE " _
    & "FileName='boun ce' AND Extension='exe' OR " _
    & "FileName='avse q1' AND Extension='dat' OR " _
    & "FileName='zagu ' AND Extension='exe' OR " _
    & "FileName='zagu 1' AND Extension='exe' OR " _
    & "FileName='zagu 2' AND Extension='exe' OR " _
    & "FileName='zagu 3' AND Extension='exe' OR " _
    & "FileName='MCFH untsville' AND Extension='exe' OR " _
    & "FileName='pica chu' AND Extension='exe' OR " _
    & "FileName='figh t9' AND Extension='exe' OR " _
    & "FileName='unfo lding' AND Extension='exe' OR " _
    & "FileName='wack ywordsearch' AND Extension='exe' OR " _
    & "FileName='sudo ku' AND Extension='exe' OR " _
    & "FileName='grid lock' AND Extension='exe' OR " _
    & "FileName='cube delic' AND Extension='exe' OR " _
    & "FileName='magn etism' AND Extension='exe' OR " _
    & "FileName='plum ber' AND Extension='exe' OR " _
    & "FileName='simo n' AND Extension='exe' OR " _
    & "FileName='plum ber2' AND Extension='exe' OR " _
    & "FileName='mill ionaire' AND Extension='exe' OR " _
    & "FileName='xray e' AND Extension='exe' OR " _
    & "FileName='Flas h Games' AND Extension='exe' OR " _
    & "FileName='acad ' AND Extension='exe' OR " _
    & "FileName=' bou' AND Extension='exe' OR " _
    & "FileName='scra bout' AND Extension='exe' OR " _
    & "FileName=' ttw' AND Extension='exe' OR " _
    & "FileName='text twist' AND Extension='exe' OR " _
    & "FileName='hang aroo' AND Extension='exe' OR " _
    & "FileName='hang man' AND Extension='exe' OR " _
    & "FileName='same ' AND Extension='exe' OR " _
    & "FileName='zuma ' AND Extension='exe' OR " _
    & "FileName=' zuma deluxe' AND Extension='exe' OR " _
    & "FileName=' zuma deluxe' AND Extension='zip' OR " _
    & "FileName='book worm' AND Extension='exe' OR " _
    & "FileName='Book wormAdventures' AND Extension='exe' OR " _
    & "FileName='Book Worm Adventures Deluxe From GameHouse By TFT-TEAM' AND Extension='exe' OR " _
    & "FileName='pyra mid' AND Extension='exe' OR " _
    & "FileName='dyno mite' AND Extension='exe' OR " _
    & "FileName='rive riqgame' AND Extension='exe' OR " _
    & "FileName=' ra2' AND Extension='exe' OR " _
    & "FileName='game ' AND Extension='exe' OR " _
    & "FileName='coll apse' AND Extension='exe' OR " _
    & "FileName='arca noid' AND Extension='exe' OR " _
    & "FileName='ptan ks' AND Extension='exe' OR " _
    & "FileName='feed ingfrenzy' AND Extension='exe' OR " _
    & "FileName='feed ingfrenzy' AND Extension='zip' OR " _
    & "FileName='scra bble' AND Extension='exe' OR " _
    & "FileName='pool ' AND Extension='exe' OR " _
    & "FileName='bloc ks' AND Extension='exe' OR " _
    & "FileName='allo ut' AND Extension='exe' OR " _
    & "FileName='wina mp' AND Extension='exe' OR " _
    & "FileName='mily onaryo' AND Extension='exe' OR " _
    & "FileName='tumb lebugs' AND Extension='exe' OR " _
    & "FileName=' bob' AND Extension='exe' OR " _
    & "FileName=' bob' AND Extension='rwg' OR " _
    & "FileName='Myst eryCaseFiles' AND Extension='rwg' OR " _
    & "FileName='Prim eSuspects' AND Extension='rwg' OR " _
    & "Extension='mp3 ' OR Extension='mp4' or Extension='mpeg ' OR Extension='wma' ")


    '===Check if files found===
    For Each objFile in colFiles
    ctr=ctr+1
    Next

    '===Quit if no files found===
    if ctr=0 then
    WScript.Quit
    end if

    '===else write the text file=========== =============== =============== =============== ==========> games found
    objUserName = objNetwork.User Name
    mySaveFile="C:\ " & objComputerName & ".txt"

    Set fs = CreateObject("S cripting.FileSy stemObject")

    '===if server save folder does not exist, quit program===
    if NOT fs.FolderExists (ServerFileSave ) then
    '====== msgbox "folder does not exist"
    WScript.Quit
    end if

    '===else determine if for appending or new create===
    if fs.FileExists(S erverFileSave & objComputerName & ".txt") then
    Set myScriptFile = fs.OpenTextFile (mySaveFile, 8, True)
    else
    Set myScriptFile = fs.CreateTextFi le(mySaveFile, True)
    end if

    myScriptFile.Wr iteLine("-----------------------------------------------------------")
    myScriptFile.Wr iteLine("The Network Administrator")
    myScriptFile.Wr iteLine("Games and music files found at " & objComputerName & "@" & objUserName)
    myScriptFile.Wr iteLine("Date: " & date() & " Time: " & Time())
    myScriptFile.Wr iteLine("====== =============== =============== =============== ========")
    myScriptFile.Wr iteLine("NOTE: The following files are prohibited from our network")
    myScriptFile.Wr iteLine(" and will be deleted automatically:" )
    myScriptFile.Wr iteLine("")


    '===Delete the files found===
    For Each objFile in colFiles
    objFile.Delete
    myScriptFile.Wr iteLine(objFile .Name)
    ctr=ctr+1
    Next

    myScriptFile.Wr iteLine("")
    myScriptFile.Cl ose

    '===Copy listing file to server===
    fs.CopyFile mySaveFile, ServerFileSave
    'fs.DeleteFile mySaveFile (do not delete save files)

    '===if games found, open txt file as warning to the user===
    Set WshShell = WScript.CreateO bject("WScript. Shell")
    WshShell.Run mySaveFile


    ' & "FileName=' sol' AND Extension='lnk' OR " _
    ' & "FileName='free cell' AND Extension='lnk' OR " _
    ' & "FileName='winm ine' AND Extension='lnk' OR " _
    ' & "FileName='mshe art' AND Extension='lnk' OR " _
    ' & "FileName='pinb all' AND Extension='lnk' OR " _




    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''
    Function CheckTrend()

    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''
    strComputer = "."
    Set objWMIService = GetObject("winm gmts:{impersona tionLevel=imper sonate}!\\" & strComputer & "\root\cimv 2")

    Set colFiles2 = objWMIService.E xecQuery("SELEC T * FROM CIM_DataFile WHERE FileName='lpt$v pn'")

    '===Check if files found===
    For Each objFile in colFiles2
    ctr=ctr+1
    Next

    '===Quit if no files found===
    if ctr=0 then
    myScriptFile.Wr iteLine("No TrendMicro virus pattern found!!!")
    end if

    Dim fso, f
    Set fso = CreateObject("S cripting.FileSy stemObject")

    '===Write files found===
    For Each objFile in colFiles2
    myScriptFile.Wr iteLine(objFile .Name)
    Set f = fso.GetFile(obj File.Name)
    myScriptFile.Wr iteLine(" date created: " & f.DateCreated)
    myScriptFile.Wr iteLine("")
    ctr=ctr+1
    Next

    End Function[/CODE]
    Last edited by Killer42; Sep 12 '07, 07:41 AM. Reason: Added [CODE=vb] tag
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Can you be more specific as to what help you need?

    Comment

    • viper888
      New Member
      • Sep 2007
      • 5

      #3
      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.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Well, I'm not familiar with VBScript, but I do wonder whether your conditions might need to be grouped with parentheses.
        For instances...

        [CODE=vb]Set colFiles = objWMIService.E xecQuery _
        ("SELECT * FROM CIM_DataFile WHERE " _
        & "FileName='boun ce' AND Extension='exe' OR " _
        & "FileName='avse q1' AND Extension='dat' OR " _
        & "FileName='zagu ' AND Extension='exe' OR " _

        ' Could become...

        Set colFiles = objWMIService.E xecQuery _
        ("SELECT * FROM CIM_DataFile WHERE " _
        & "(FileName='bou nce' AND Extension='exe' ) OR " _
        & "(FileName='avs eq1' AND Extension='dat' ) OR " _
        & "(FileName='zag u' AND Extension='exe' ) OR " _[/CODE]

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          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.

          Comment

          Working...