Workstation cleanup

Author Message
tokiwoki

  • Total Posts : 8
  • Scores: 0
  • Reward points : 0
  • Joined: 3/3/2007
  • Status: offline
Workstation cleanup Saturday, March 03, 2007 6:36 PM (permalink)
0
Hi everyone, My boss asked me to write a script that silently uninstalls some software apps on workstations on our domain, so I wrote the following
 
'Option Explicit
 On Error Resume Next
 
 'define our variables
 Dim str_base_registry, str_path, flag_debug
  
 'enable debug mode?
 flag_debug = 0
  
 'create a command shell for use below
 Set CommandShell = createobject("wscript.shell")
  
 'WinRAR (fs)
 str_path = "%ProgramFiles%\WinRAR" 'get the application's path
 'execute its uninstaller
 cmdline = chr(34) & str_path & "\Uninstall.exe" & chr(34) &  " /s"
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True
 
 'SpyBotSnD (fs)
 str_path = "%ProgramFiles%\Spybot - Search & Destroy"
 cmdline = chr(34) & str_path & "\unins000.exe" & chr(34) & " /SILENT"
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True
 
 'Spy Sweeper (fs)
 str_path = "%ProgramFiles%\Webroot\Spy Sweeper"
 cmdline = chr(34) & str_path & "\unins000.exe" & chr(34) & " /SP- /VERYSILENT /NORESTART"
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True
 
 'Skype (fs)
 str_path = "%ProgramFiles%\Skype\Phone"
 cmdline = chr(34) & str_path & "\unins000.exe" & chr(34) & " /SILENT /NORESTART /SUPPRESSMSGBOXES"
 'TODO: kill the process iu14D2N.tmp
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True
 
 'Partition Magic 8 (msiexec)
 cmdline = "msiexec /X {6BE2A4A4-99FB-48ED-AE1E-4E850389F804} /qn"
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True
 
 'Ad-Aware (msiexec)
 cmdline = "msiexec /X {78CC3BAB-DE2A-4FB4-8FBB-E4DADDC26747} /qn"
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True
 
 'Norton Ghost 2003 (9) (msiexec)
 cmdline = "msiexec /X {3C759736-8347-4031-BB9C-D75ADFE6B1013} /qn /norestart"
 If flag_debug = 1 Then WScript.Echo cmdline End If
 CommandShell.Run cmdline, 1, True

 
Any comments or suggestions would be great since this is my first vbs script.  I noticed that trying to silently uninstall WinRar on one machine didn't do anything, but removing the /s flag asked the user for confirmation and then proceeded as normal.
 
#1
    DiGiTAL.SkReAM

    • Total Posts : 1259
    • Scores: 7
    • Reward points : 0
    • Joined: 9/7/2005
    • Location: Clearwater, FL, USA
    • Status: offline
    RE: Workstation cleanup Monday, March 05, 2007 2:24 AM (permalink)
    0
    Very nice for a first script.
    My only suggestions would be:
    1.) Use Option Explicit
         -It forces you to Dim your variables, and helps promote good coding practices
    2.) Don't use On Error Resume Next unless you have to.
         -It hides any error messages that might be needed for debugging/troubleshooting
    3.) Try condensing your code a little.
         -It makes it easier to read, and easier to maintain.  For example, if you wanted to run all of your commands in the background, with no windows, with your original script, you would have to change the ,1,true to ,0,true about 7 times.  With the below script, just change it in one place.

     Option Explicit
      
     'Only use On Error Resume Next when absolutely necessary
     'On Error Resume Next
      
     'define our variables
     Dim flag_debug, CommandShell, cmdline, oCmdDic
      
     'enable debug mode?
     'This is apparently used to just echo back the commandline you are using for each software uninstall.
     flag_debug = 0
      
     'create a command shell for use below
     Set CommandShell = createobject("wscript.shell")
      
     'create a dictionary object to hold your data pairs
     Set oCmdDic = CreateObject("Scripting.Dictionary")
      
     'using a dictionary allows you to add additional software packages with little to no recoding required.
     'oCmdDic.Add "Package name", "uninstall commandline"
     oCmdDic.Add "WinRAR (fs)", chr(34) & "%ProgramFiles%\WinRAR\Uninstall.exe" & chr(34) &  " /s"
     oCmdDic.Add "SpyBotSnD (fs)", chr(34) & "%ProgramFiles%\Spybot - Search & Destroy\unins000.exe" & chr(34) & " /SILENT"
     oCmdDic.Add "Spy Sweeper (fs)", chr(34) & "%ProgramFiles%\Webroot\Spy Sweeper\unins000.exe" & chr(34) & " /SP- /VERYSILENT /NORESTART"
     oCmdDic.Add "Skype (fs)", chr(34) & "%ProgramFiles%\Skype\Phone\unins000.exe" & chr(34) & " /SILENT /NORESTART /SUPPRESSMSGBOXES"
     oCmdDic.Add "Partition Magic 8 (msiexec)", "msiexec /X {6BE2A4A4-99FB-48ED-AE1E-4E850389F804} /qn"
     oCmdDic.Add "Ad-Aware (msiexec)", "msiexec /X {78CC3BAB-DE2A-4FB4-8FBB-E4DADDC26747} /qn"
     oCmdDic.Add "Norton Ghost 2003 (9) (msiexec)", "msiexec /X {3C759736-8347-4031-BB9C-D75ADFE6B1013} /qn /norestart"
      
     'Iterate through each of the packages listed, running the same commands for each package
      For Each cmdline In oCmdDic.Items 
        If flag_debug = 1 Then WScript.Echo cmdline 
       CommandShell.Run cmdline, 1, True
      Next
     

     
    "Would you like to touch my monkey?" - Dieter (Mike Meyers)

    "It is better to die like a tiger, than to live like a pussy."
    -Master Wong, from Balls of Fury
     
    #2
      tokiwoki

      • Total Posts : 8
      • Scores: 0
      • Reward points : 0
      • Joined: 3/3/2007
      • Status: offline
      RE: Workstation cleanup Monday, March 05, 2007 11:45 PM (permalink)
      0
      Cool thanks, that was very helpful!
       
      #3
        kirrilian

        • Total Posts : 629
        • Scores: 3
        • Reward points : 0
        • Joined: 3/15/2005
        • Location:
        • Status: offline
        RE: Workstation cleanup Tuesday, March 06, 2007 4:49 PM (permalink)
        0

        ORIGINAL: DiGiTAL.SkReAM

        2.) Don't use On Error Resume Next unless you have to.
        -It hides any error messages that might be needed for debugging/troubleshooting


        except when you want to do your own error handling...

        Have you searched [url="http://www.google.com"]here [/url]?
        [url="http://tinyurl.com/as7xm"]VBScript Fundamentals[/url]
        [url="http://kirrilian.dyndns.org/projects/code/"]My Site[/url]
         
        #4
          DiGiTAL.SkReAM

          • Total Posts : 1259
          • Scores: 7
          • Reward points : 0
          • Joined: 9/7/2005
          • Location: Clearwater, FL, USA
          • Status: offline
          RE: Workstation cleanup Wednesday, March 07, 2007 1:50 AM (permalink)
          0

          ORIGINAL: kirrilian


          ORIGINAL: DiGiTAL.SkReAM

          2.) Don't use On Error Resume Next unless you have to.
          -It hides any error messages that might be needed for debugging/troubleshooting


          except when you want to do your own error handling...



           
          I believe that would fall under the heading of "unless you have to".
          "Would you like to touch my monkey?" - Dieter (Mike Meyers)

          "It is better to die like a tiger, than to live like a pussy."
          -Master Wong, from Balls of Fury
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9