/build/static/layout/Breadcrumb_cap_w.png

Where to add system reboot after program uninstalls...

I am a newb who can't use Google Search... Howdy folks, the More Details contains a.vbs script I crippled together but can't seem to find the method in which to get the script to force system reboot after program uninstallation. Just wasn't getting it... Thanks

 


'

  ==============================================================================
Dim objWshShell,objEnv,strPath,strAppName,strAppTask,OSBIT,ExitCode,strCmd,intReturn,objFSO,objFile,DestinationPath,ParentFolderPath,SourcePath,CopyDirFunction,SourceFile,DestinationFile,CopyFileFunction,sPath,iPos,ScriptPath, strInstPath,AllUsersStartMenu
Dim objWMIService, objItem, objService,colListOfServices, strComputer, strService, intSleep, strWinDir, strProgramFiles, processor

' Application Name for event Log
strAppName = "Uninstall Carrot Professional 7.x" 'This is the name of the application.


' =============== Global Objects ==================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = objWshShell.Environment("Process")
strInstPath = Replace(Wscript.ScriptFullName, "\" & Wscript.ScriptName, "")
strWinDir = objEnv("WINDIR")
AllUsersStartMenu = objWshShell.SpecialFolders("AllUsersStartMenu")
Set processor =GetObject("winmgmts:\\.\root\cimv2:Win32_Processor='cpu0'")
If (processor.AddressWidth = 32) Then
    strProgramFiles = objEnv("PROGRAMFILES")
Else
    strProgramFiles = objEnv("PROGRAMFILES(x86)")
End If


' =============== Installation Tasks ==============
' Start
strAppTask = "Start " & strAppName
'wscript.echo Err.Number
ExitCode = Err.Number
LogEvent(ExitCode)


' Task 1 - Uninstall Carrot 7.0
strAppTask = "Uninstall Carrot 7.0"
strCmd = "cmd /c msiexec /x {86868FB7-07DA-4F88-AE5C-48C058854F26} /qn"
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)
ExitCode = intReturn
If ExitCode <> 0 Then
    If ExitCode <> 1605 Then
        CleanEnv 1
    End If
End If

' Task 2 - Uninstall Carrot 7.5
strAppTask = "Uninstall Carrot 7.5"
strCmd = "cmd /c msiexec /x {8686EC18-6282-4AA9-92AC-2865B972E244} /qn"
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)
ExitCode = intReturn
If ExitCode <> 0 Then
    If ExitCode <> 1605 Then
        CleanEnv 2
    End If
End If

' Task 3 - Uninstall Carrot PDF Converter
strAppTask = "Uninstall Carrot PDF Converter"
strCmd = "cmd /c msiexec /x {D8E0BC34-B11A-498E-BA01-C23B99E52287} /qn"
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)
If ExitCode <> 0 Then
    If ExitCode <> 1605 Then
        CleanEnv 3
    End If
End If

' Task 4 - Delete HKCU registry keys
strAppTask = "Delete HKCU registry keys"
strCmd = "CMD /C REG DELETE HKCU\Software\Carrot /f"
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Task 5 - Delete HKLM registry keys
strAppTask = "Delete HKLM registry keys"
strCmd = "CMD /C REG DELETE HKLM\Software\Carrot /reg:32 /f"
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Task 6 - Delete User Carrot files
strAppTask = "Delete User Carrot file"
strCmd = "CMD /C IF EXIST " & Chr(34) & "%APPDATA%\Carrot" & Chr(34) & " RD /S /Q " & Chr(34) & "%APPDATA%\Carrot" & Chr(34)
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Task 7 - Delete User Carrot Upgrade files
strAppTask = "Delete User Carrot Upgrade file"
strCmd = "CMD /C IF EXIST " & Chr(34) & "%APPDATA%\Carrot Upgrade" & Chr(34) & " RD /S /Q " & Chr(34) & "%APPDATA%\Carrot Upgrade" & Chr(34)
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Task 8 - Delete ProgramFiles files
strAppTask = "Delete ProgramFiles files"
strCmd = "CMD /C IF EXIST " & Chr(34) & strProgramFiles & "\Carrot" & Chr(34) & " RD /S /Q " & Chr(34) & strProgramFiles & "\Carrot" & Chr(34)
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Task 9 - Delete ProgramData files
strAppTask = "Delete ProgramData files"
strCmd = "CMD /C IF EXIST " & Chr(34) & "C:\ProgramData\Carrot" & Chr(34) & " RD /S /Q " & Chr(34) & "C:\ProgramData\Carrot" & Chr(34)
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Task 10 - Delete Public files
strAppTask = "Delete ProgramData files"
strCmd = "CMD /C IF EXIST " & Chr(34) & "C:\Users\Public\Documents\Carrot" & Chr(34) & " RD /S /Q " & Chr(34) & "C:\Users\Public\Documents\Carrot" & Chr(34)
'MsgBox(strCmd)
intReturn = objWshShell.run(strCmd, 0, True)

' Exit
Set objWshShell = Nothing
Set objFSO = Nothing
Set objENV = Nothing
WScript.Quit(0)


'=====================================================
'      FUNCTIONS  -- DO NOT DELETE OR MODIFY
'=====================================================
Function FolderExists(strPath)
'checks if file (strpath) exists and return true if it does, False if it doesn't
   If objFSO.FolderExists(strPath) Then
      FolderExists = TRUE
   Else
      FolderExists = FALSE
   End If
End Function

Function FileExists(strPath)
'checks if file (strpath) exists and return true if it does, False if it doesn't
   If objFSO.FileExists(strPath) Then
      FileExists = TRUE
   Else
      FileExists = FALSE
   End If
End Function

Function LogEvent(ExitCode)
   If ExitCode = "0" OR ExitCode = "3010" OR ExitCode = "" Then
      objWshShell.LogEvent 0, strAppName & " - Task: " & strAppTask & " - SUCCESSFUL"
      Err.Clear
   Else
      objWshShell.LogEvent 1, strAppName & " - Task: " & strAppTask & " - FAILED.  Exit Code: " & ExitCode
      Wscript.Quit(ExitCode)
   End If
End Function

Function CopyDir(SourcePath,DestinationPath)
   Const OverWriteFiles = True
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.GetFile(wscript.ScriptFullName)
   ParentFolderPath = objFSO.GetParentFolderName(objFile)
   'MsgBox SourcePath
   'MsgBox DestinationPath
   objFSO.CopyFolder SourcePath , DestinationPath , OverWriteFiles
End Function

Function CopyFile(SourceFile,DestinationFile)
  Const OverWriteFiles = True
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile(wscript.ScriptFullName)
  ParentFolderPath = objFSO.GetParentFolderName(objFile)

  sPath = DestinationFile ' Trailing \ is required
  iPos = InStr(4, sPath, "\", 0) ' Skip drive letter check
  While(iPos <> 0)
          If(Not(objFSO.FolderExists(Left(sPath, iPos)))) Then
                  objFSO.CreateFolder(Left(sPath, iPos))
          End If
          iPos = InStr(iPos+1, sPath, "\", 0)
  Wend
  objFSO.CopyFile SourceFile , sPath , TRUE
End Function


Sub CleanEnv(intExitCode)
    On Error Resume Next: Err.Clear
    If bDEBUG Then Wscript.Echo "Debugging Exit Code: " & intExitCode
    LogEvent(intExitCode)
    Set objWshShell = Nothing
    Set objFSO = Nothing
    Set objENV = Nothing
    WScript.Quit(intExitCode)
End Sub

 


2 Comments   [ + ] Show comments
  • Errrrr...why not use the .Run method to run 'shutdown.exe', which is part of Windows XP and upwards? - anonymous_9363 10 years ago
  • Hello - tried replacing WScript.Quit(0) with c:\windows\system 32\shutdown -r -t 5 but received a line/character error. Not sure what or where you were referring to Thanks. - rbell96k 10 years ago

Answers (0)

Be the first to answer this question

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ