none
vb script - Run uninstall from 32 bit or 64 bit RRS feed

  • Question

  • Hey gang - I have an issue that maybe someone can help with.  I know very little about scripting.  I have this script running on XP and Win 7 machines using 2 separate scripts with different paths (PROGRA~2 and PROGRA~1) and I would like to combine them.  The scripts run the silent uninstalls /S switch for hotpot.  Thoughts? Please bear in mind I'm a total newb.

    'Objects
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set shl = CreateObject("WScript.Shell")

    path="c:\PROGRA~2\Hotspo~1\"   
    exists = fso.FolderExists(path)

    if (exists) then
        program="uninstall.exe /S"
        shl.Run(path & program)
    end if

    Thanks

    Monday, January 6, 2014 1:10 PM

Answers

  • Try this one instead:


    Dim FSO, WshShell, WshEnvironment
    Dim ProgramFiles32, InstallPath, Command
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    Set WshEnvironment = WshShell.Environment("PROCESS")
    
    If WshEnvironment.Item("ProgramFiles(x86)") = "" Then
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles")
    Else
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles(x86)")
    End If
    
    InstallPath = ProgramFiles32 & "\Hotspot"
    If FSO.FolderExists(InstallPath) Then
      Command = """" & InstallPath & "\uninstall.exe"" /S"
      'WScript.Echo Command
      WshShell.Run Command, 1
    End If
    

    Bill

    • Marked as answer by ravenous3 Wednesday, January 8, 2014 12:50 PM
    Tuesday, January 7, 2014 6:01 PM
    Moderator

All replies

  • I assume you have a problem with the paths
    c:\Program Files
    and
    c:\Program Files (x86)

    If so then you should replace
    path="c:\PROGRA~2\Hotspo~1\" 
    with
    path = shl.ExpandEnvironmentStrings("%ProgramFiles(x86)%\Hotspo~1\")

    Monday, January 6, 2014 1:30 PM
  • Thanks for the quick response!!

    I am having problems with the paths and I may need to go about it in a different way.  I made the change that you suggested and it did not uninstall the program on XP or Win 7.  Thoughts?

    Monday, January 6, 2014 2:54 PM
  • I am having problems with the paths and I may need to go about it in a different way.  I made the change that you suggested and it did not uninstall the program on XP or Win 7.  Thoughts?

    Sorry, can't tell without seeing screen messages. The way you're doing things you can't see any screen messages either. Since, as you say, you know little about scripting, why not simplify things and do this:

    • Put the uninstall command into a batch file (e.g. ravenous.bat) like so:
      @echo off
      "%ProgramFiles(x86)%\Hotspo~1\unistall.exe" /S
    • Open a Command Prompt.
    • Invoke the batch file from the Command Prompt.

    You can now see exactly what's going on.

    Monday, January 6, 2014 3:28 PM
  • Thanks for the help. The echo message was "the system cannot find the path specified". 

    The path to the uninstall is c:\program files\hotspot\uninstall.exe for XP and c:\program files (x86) \hotspot\uninstall.exe for win 7. 

    When I replace "%Program Files(x86)%\Hotspo~1\uninstall.exe" /S  with the line "c:\PROGRA~1\Hotspo~1\uninstall.exe" /S - it works great. 

    Monday, January 6, 2014 4:17 PM
  • You should get away from 8.1 folder paths. They cause a lot of confusion to you. Try this:

    1. Open a Command Prompt on a WinXP machine.
    2. Find out where the Hotsp... folder resides and what its full name is. Use these commands:
      dir  "c:\Program Files\Hot*.*"
      dir  "c:\Program Files (x86)\Hot*"
    3. Repeat Steps 1 and to on a Windows 7 machine.
    4. Report the results here.

    Monday, January 6, 2014 4:28 PM
  • The folder is located on the c:\program files\hotspot for xp 32 bit and in c:\program files (x86)\hotspot on my 64 bit win 7 machine.  Im trying to execute an uninstall from either of these folders with one script instead of the 2 which I have been using.

    Monday, January 6, 2014 4:47 PM
  • The folder is located on the c:\program files\hotspot for xp 32 bit and in c:\program files (x86)\hotspot on my 64 bit win 7 machine.  Im trying to execute an uninstall from either of these folders with one script instead of the 2 which I have been using.

    OK, use copy and paste this code:
    @echo off
    set x86= (x86)
    if exist "c:\Program Files\Hotspot" set x86=
    "C:\Program Files%x86%\Hotspot\unistall.exe" /S

    BTW, I don't think that your folder is called Hotspot. If it was then its 8.3 name would not be Hotspo~1.


    Monday, January 6, 2014 5:15 PM
  • You can accomplish this by detecting in your script whether you are running in WoW (Windows on Windows, i.e., the 32-bit emulator on x64 Windows). For example:


    @echo off
    setlocal enableextensions
    set PF=
    if defined PROCESSOR_ARCHITEW6432 (
      set PF=%ProgramFiles%
    ) else (
      set PF=%ProgramFiles(x86):)=^)%
    )
    echo "%PF%\Hotspot"
    endlocal
    

    The string substitution in (x86) is needed to capture the closing ) character.

    For more information, see the following Windows documentation:

    Running 32-bit Applications

    Bill

    Monday, January 6, 2014 5:17 PM
    Moderator
  • That worked great in a .bat file.  I tried it on both 32 and 64 bit machines and it worked flawlessly.  Many, many thanks.  How can I utilize this is a vbscript file?

    Thanks

    Monday, January 6, 2014 6:08 PM
  • How can I utilize this is a vbscript file?

    Same way as shell script (batch). Example:


    Dim WshShell, WshEnvironment, ProgramFiles32
    Set WshShell = CreateObject("WScript.Shell")
    Set WshEnvironment = WshShell.Environment("PROCESS")
    If WshEnvironment.Item("PROCESSOR_ARCHITEW6432") <> "" Then
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles")
    Else
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles(x86)")
    End If
    WScript.Echo ProgramFiles32 & "\Hotspot"
    

    Bill

    Monday, January 6, 2014 6:18 PM
    Moderator
  • The folder is located on the c:\program files\hotspot for xp 32 bit and in c:\program files (x86)\hotspot on my 64 bit win 7 machine.  Im trying to execute an uninstall from either of these folders with one script instead of the 2 which I have been using.

    OK, use copy and paste this code:
    @echo off
    set x86= (x86)
    if exist "c:\Program Files\Hotspot" set x86=
    "C:\Program Files%x86%\Hotspot\unistall.exe" /S

    BTW, I don't think that your folder is called Hotspot. If it was then its 8.3 name would not be Hotspo~1.


    That worked great in a .bat file.  I tried it on both 32 and 64 bit machines and it worked flawlessly.  Many, many thanks.  How can I utilize this is a vbscript file?

    Thanks Forest


    Monday, January 6, 2014 6:58 PM
  • Complete uninstall example:


    Dim FSO, WshShell, WshEnvironment
    Dim ProgramFiles32, InstallPath, Command
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    Set WshEnvironment = WshShell.Environment("PROCESS")
    
    If WshEnvironment.Item("PROCESSOR_ARCHITEW6432") <> "" Then
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles")
    Else
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles(x86)")
    End If
    
    InstallPath = ProgramFiles32 & "\Hotspot"
    If FSO.FolderExists(InstallPath) Then
      Command = """" & InstallPath & "\uninstall.exe"" /S"
      WshShell.Run Command, 0
    End If
    

    Bill

    Monday, January 6, 2014 7:05 PM
    Moderator
  • It didn't work, Bill - it came up with an error in line 10 character 1.

    Monday, January 6, 2014 7:15 PM
  • My bad - I didn't copy and paste properly....the script you sent did not show any errors this time but it failed to uninstall. 
    Monday, January 6, 2014 7:23 PM
  • Complete uninstall example:


    Dim FSO, WshShell, WshEnvironment
    Dim ProgramFiles32, InstallPath, Command
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    Set WshEnvironment = WshShell.Environment("PROCESS")
    
    If WshEnvironment.Item("PROCESSOR_ARCHITEW6432") <> "" Then
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles")
    Else
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles(x86)")
    End If
    
    InstallPath = ProgramFiles32 & "\Hotspot"
    If FSO.FolderExists(InstallPath) Then
      Command = """" & InstallPath & "\uninstall.exe"" /S"
      WshShell.Run Command, 0
    End If
    

    Bill


    It is successfull on a x64 machine but does not uninstall on a 32bit xp machine.  Thoughts?
    Monday, January 6, 2014 7:48 PM
  • Replace this line:


    WshShell.Run Command, 0

    With this:


    WScript.Echo Command

    What is the output?

    Bill

    Monday, January 6, 2014 7:50 PM
    Moderator
  • It is successfull on a x64 machine but does not uninstall on a 32bit xp machine.  Thoughts?

    You cannot debug code unless you see what is happening. Use this script, then have a look at the log file D:\Log.txt (or whatever file you set as a log file in the last line):

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oWshShell = CreateObject("WScript.Shell")
    sProg32 = "C:\Program Files\Hotspot\"
    sProg64 = "C:\Program Files (x86)\Hotspot\"

    If oFSO.FolderExists(sProg32) _
    Then sProg = sProg32 _
    Else sProg = sProg64
    oWshShell.Run "cmd /c """ & sProg & "Uninstall.exe"" /S 1> d:\Log.txt 2>&1" , 0, True

    Monday, January 6, 2014 7:54 PM
  • Forest, your bat file worked great.  I'm really thinking I'm just gonna use that instead of a vbscript.  I was hoping to get your .bat file turned into a vbscript but I can live with it as a bat file.

    @echo off
    set x86= (x86)
    if exist "c:\Program Files\Hotspot" set x86=
    "C:\Program Files%x86%\Hotspot\uninstall.exe" /S

    The output of the script you just posted is

    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file.

    Monday, January 6, 2014 8:03 PM
  • The output of the script you just posted is

    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file.

    My script is a loose translation of my batch file. If you get the above message then you probably retyped my VBScript instead of copying/pasting it. You can get more details by running this variant. What do you see in the pop-up box?

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oWshShell = CreateObject("WScript.Shell")
    sProg32 = "C:\Program Files\Hotspot\"
    sProg64 = "C:\Program Files (x86)\Hotspot\"

    If oFSO.FolderExists(sProg32) _
    Then sProg = sProg32 _
    Else sProg = sProg64
    MsgBox "cmd /c """ & sProg & "Uninstall.exe"" /S 1> d:\Log.txt 2>&1"
    oWshShell.Run "cmd /c """ & sProg & "Uninstall.exe"" /S 1> d:\Log.txt 2>&1" , 0, True

    Monday, January 6, 2014 8:13 PM
  • Just curious... is this an MSI by chance? If it is just look in the Uninstall Registry key for the uninstall string...

    Not to over complicate, I check for CPU AddressWidth in WMI

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colCPU = objWMIService.ExecQuery("Select * from Win32_Processor")
    For each objItem in colCPU
    	If objItem.AddressWidth = 32 Then
    		varArch = "x86"
    	ElseIf objItem.AddressWidth = 64 Then
    		varArch = "x64"
    	End if
    Next

    Here is the whole script. I don't use it anymore since 2012 is much more flexible and I don't need to create as much validation on my own, and is for an install.

    Set objShell = CreateObject("Wscript.Shell")
    Set ObjEnv = objShell.Environment("Process")
    Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
    Set objNet = CreateObject("Wscript.Network")
    objEnv("SEE_NET_NOZONECHECKS") = 1
    
    strComputer = objNet.ComputerName
    
    wscript.echo "Checking CPU Architecture"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colCPU = objWMIService.ExecQuery("Select * from Win32_Processor")
    For each objItem in colCPU
    	If objItem.AddressWidth = 32 Then
    		varArch = "x86"
    	ElseIf objItem.AddressWidth = 64 Then
    		varArch = "x64"
    	End if
    Next
    
    If varArch = "x86" Then
    	iRetVal = objshell.run ("msiexec.exe /i DataProtectionAgent.en-US.msi /Passive", 1, True)
    ElseIf varArch = "x64" Then
    	iRetVal = objshell.run ("msiexec.exe /i DataProtectionAgent_x64.en-US.msi /Passive", 1, True)
    End If

    If you could use the Uninstall String from the registry it might be easier since it should be the same for x86/x64. In the above just replace the If/ElseIf/End If with iRetVal = objShell.Run ("uninstall string value", 0, True). You can report the success to SCCM using wscript.quit(iRetVal).

    Edit - Just realized this isn't an SCCM forum, however the above still applies, minus the wscript.quit(iRetVal) is not needed since you don't need to report back to a management system.

    • Edited by RCCMG Monday, January 6, 2014 8:33 PM
    Monday, January 6, 2014 8:28 PM
  • The output of the script you just posted is

    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file.

    My script is a loose translation of my batch file. If you get the above message then you probably retyped my VBScript instead of copying/pasting it. You can get more details by running this variant. What do you see in the pop-up box?

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oWshShell = CreateObject("WScript.Shell")
    sProg32 = "C:\Program Files\Hotspot\"
    sProg64 = "C:\Program Files (x86)\Hotspot\"

    If oFSO.FolderExists(sProg32) _
    Then sProg = sProg32 _
    Else sProg = sProg64
    MsgBox "cmd /c """ & sProg & "Uninstall.exe"" /S 1> d:\Log.txt 2>&1"
    oWshShell.Run "cmd /c """ & sProg & "Uninstall.exe"" /S 1> d:\Log.txt 2>&1" , 0, True


    No, I copied and pasted it.  I did it again and I still get the same message in the log file.  The message box reads - cmd /c "C:\program files (x86)\hotspot\uninstall.exe" /S1> d:\log.txt 2>&1
    Monday, January 6, 2014 8:54 PM
  • Replace this line:


    WshShell.Run Command, 0

    With this:


    WScript.Echo Command

    What is the output?

    Bill

    Bill, Your script returns the correct path within windows 64-bit but it is missing the "c:\program files\" in 32-bit and simply reads hotspot\uninstall.exe and it won't uninstall.

    Thoughts?

     

    Tuesday, January 7, 2014 4:34 PM
  • Set objShell = CreateObject("Wscript.Shell")
    Set ObjEnv = objShell.Environment("Process")
    Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
    Set objNet = CreateObject("Wscript.Network")
    objEnv("SEE_NET_NOZONECHECKS") = 1
    
    strComputer = objNet.ComputerName
    
    wscript.echo "Checking CPU Architecture"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colCPU = objWMIService.ExecQuery("Select * from Win32_Processor")
    For each objItem in colCPU
    	If objItem.AddressWidth = 32 Then
    		varArch = "x86"
    	ElseIf objItem.AddressWidth = 64 Then
    		varArch = "x64"
    	End if
    Next
    
    If varArch = "x86" Then
    	varHotSpot = "C:\Program Files\Hotspot\uninstall.exe /S d:\log.txt"
    	iRetVal = objshell.run(varHotSpot, 0, True)
    ElseIf varArch = "x64" Then
    	varHotSpot = "C:\Program Files (x86)\Hotspot\uninstall.exe /S d:\log.txt"
    	iRetVal = objshell.run(varHotSpot, 0, True)
    End If
    Copy, past into notepad and save as <somename>.vbs, open the command prompt cd to where you saved it the cscript.exe <somename>.vbs. Should work.
    Tuesday, January 7, 2014 5:27 PM
  • Try this one instead:


    Dim FSO, WshShell, WshEnvironment
    Dim ProgramFiles32, InstallPath, Command
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    Set WshEnvironment = WshShell.Environment("PROCESS")
    
    If WshEnvironment.Item("ProgramFiles(x86)") = "" Then
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles")
    Else
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles(x86)")
    End If
    
    InstallPath = ProgramFiles32 & "\Hotspot"
    If FSO.FolderExists(InstallPath) Then
      Command = """" & InstallPath & "\uninstall.exe"" /S"
      'WScript.Echo Command
      WshShell.Run Command, 1
    End If
    

    Bill

    • Marked as answer by ravenous3 Wednesday, January 8, 2014 12:50 PM
    Tuesday, January 7, 2014 6:01 PM
    Moderator
  • No, I copied and pasted it.  I did it again and I still get the same message in the log file.  The message box reads - cmd /c "C:\program files (x86)\hotspot\uninstall.exe" /S1> d:\log.txt 2>&1
    I compared the script that you sent me with my own script. The two are identical. Since both scripts run perfectly on my machine, I must assume that you ran a different script than the one that you thought you were running.
    Tuesday, January 7, 2014 9:49 PM
  • Try this one instead:


    Dim FSO, WshShell, WshEnvironment
    Dim ProgramFiles32, InstallPath, Command
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    Set WshEnvironment = WshShell.Environment("PROCESS")
    
    If WshEnvironment.Item("ProgramFiles(x86)") = "" Then
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles")
    Else
      ProgramFiles32 = WshEnvironment.Item("ProgramFiles(x86)")
    End If
    
    InstallPath = ProgramFiles32 & "\Hotspot"
    If FSO.FolderExists(InstallPath) Then
      Command = """" & InstallPath & "\uninstall.exe"" /S"
      'WScript.Echo Command
      WshShell.Run Command, 1
    End If
    

    Bill


    Bill - this worked great!  Many thanks
    Wednesday, January 8, 2014 12:50 PM
  • No, I copied and pasted it.  I did it again and I still get the same message in the log file.  The message box reads - cmd /c "C:\program files (x86)\hotspot\uninstall.exe" /S1> d:\log.txt 2>&1

    I compared the script that you sent me with my own script. The two are identical. Since both scripts run perfectly on my machine, I must assume that you ran a different script than the one that you thought you were running.

    That would be an incorrect assumption.  Obviously your machine differs from the machines that I am working on in some fashion. Bill's script worked great.  Your bat file is awesome and I appreciate the help. Thanks.
    Wednesday, January 8, 2014 1:00 PM