26 April 2012

Java Runtime Environment Installation Script

This VB script I wrote will uninstall all previous versions of Java Runtime Environment. It will also install both the x86 and x64 versions, depending on whether the OS is 64-bit compatible. It uses the msi installer, which can only be obtained by capturing it at %APPDATA\LocalLow\Sun\Java\<Version Number> by running the installation executable and before you click install, the msi has been extracted to the above directory. I got both the x86 and x64 versions, which I placed in separate sub-directories, due to the same names. The switches I used in this script are to activate auto updating of the software and opens up the display of all tabs in the java control panel applet.

Here is a link to download the script.


 '*******************************************************************************  
 '     Program: Install.vbs  
 '      Author: Mick Pletcher  
 '        Date: 26 April 2012  
 '    Modified:   
 '  
 '     Program: Java Runtime Environment  
 '     Version: 7u4  
 ' Description: This will uninstall previous versions and then installs  
 '                 the current version  
 '                 1) Define the relative installation path  
 '                 2) Create the Log Folder  
 '                 3) Uninstall all previous versions  
 '                 4) Install Current Version  
 '                 5) Cleanup Global Variables  
 '*******************************************************************************  
 Option Explicit  

 REM Define Constants  
 CONST TempFolder    = "c:\temp\"  
 CONST LogFolderName = "JavaRuntime"  

 REM Define Global Variables  
 DIM Architecture : Set Architecture = Nothing  
 DIM LogFolder    : LogFolder        = TempFolder & LogFolderName & "\"  
 DIM RelativePath : Set RelativePath = Nothing  

 REM Define the relative installation path  
 DefineRelativePath()  
 REM Create the Log Folder  
 CreateLogFolder()  
 REM Determine Architecture  
 DetermineArchitecture()  
 REM Uninstall all Previous Versions  
 Uninstall()  
 REM Installx86  
 Installx86()  
 If Architecture = "x64" Then  
      REM Installx64   
      Installx64()  
 End If  
 REM Cleanup Global Variables  
 GlobalVariableCleanup()  

 '*******************************************************************************  
 '*******************************************************************************  

 Sub DefineRelativePath()  

      REM Get File Name with full relative path  
      RelativePath = WScript.ScriptFullName  
      REM Remove file name, leaving relative path only  
      RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))  

 End Sub  

 '*******************************************************************************  

 Sub CreateLogFolder()  

      REM Define Local Objects  
      DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")  

      If NOT FSO.FolderExists(TempFolder) then  
           FSO.CreateFolder(TempFolder)  
      End If  
      If NOT FSO.FolderExists(LogFolder) then  
           FSO.CreateFolder(LogFolder)  
      End If  

      REM Cleanup Local Variables  
      Set FSO = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub DetermineArchitecture()  

      REM Define Local Objects  
      DIM WshShell : Set WshShell = CreateObject("WScript.Shell")  

      REM Define Local Variables  
      DIM OsType : OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")  

      If OsType = "x86" then  
           Architecture = "x86"  
      elseif OsType = "AMD64" then  
           Architecture = "x64"  
      end if  

      REM Cleanup Local Variables
      Set WshShell = Nothing
      Set OsType   = Nothing

 End Sub  

 '*******************************************************************************  

 Sub Uninstall()  

      REM Define Local Objects  
      DIM oShell : SET oShell = CreateObject("Wscript.Shell")  

      REM Define Local Variables  
      DIM Parameters      : Parameters      = Chr(32) & "/qb- /norestart"  
      DIM Uninstall01     : Uninstall01     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160010}" & Parameters  
      DIM Uninstall02     : Uninstall02     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160020}" & Parameters  
      DIM Uninstall03     : Uninstall03     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160030}" & Parameters  
      DIM Uninstall04     : Uninstall04     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160040}" & Parameters  
      DIM Uninstall05     : Uninstall05     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160050}" & Parameters  
      DIM Uninstall06     : Uninstall06     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160060}" & Parameters  
      DIM Uninstall07     : Uninstall07     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160070}" & Parameters  
      DIM Uninstall08     : Uninstall08     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160080}" & Parameters  
      DIM Uninstall09     : Uninstall09     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160090}" & Parameters  
      DIM Uninstall10     : Uninstall10     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160060}" & Parameters  
      DIM Uninstall11     : Uninstall11     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160110}" & Parameters  
      DIM Uninstall12     : Uninstall12     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160120}" & Parameters  
      DIM Uninstall13     : Uninstall13     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160130}" & Parameters  
      DIM Uninstall14     : Uninstall14     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160140}" & Parameters  
      DIM Uninstall15     : Uninstall15     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160150}" & Parameters  
      DIM Uninstall16     : Uninstall16     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160160}" & Parameters  
      DIM Uninstall17     : Uninstall17     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160170}" & Parameters  
      DIM Uninstall18     : Uninstall18     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160180}" & Parameters  
      DIM Uninstall19     : Uninstall19     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160190}" & Parameters  
      DIM Uninstall20     : Uninstall20     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160200}" & Parameters  
      DIM Uninstall21     : Uninstall21     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160210}" & Parameters  
      DIM Uninstall22     : Uninstall22     = "msiexec.exe /x {3248F0A8-6813-11D6-A77B-00B0D0160220}" & Parameters  
      DIM Uninstall23     : Uninstall23     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216023FF}" & Parameters  
      DIM Uninstall23x64  : Uninstall23x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416023FF}" & Parameters  
      DIM Uninstall24     : Uninstall24     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216024FF}" & Parameters  
      DIM Uninstall24x64  : Uninstall24x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416024FF}" & Parameters  
      DIM Uninstall25     : Uninstall25     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216025FF}" & Parameters  
      DIM Uninstall25x64  : Uninstall25x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416025FF}" & Parameters  
      DIM Uninstall26     : Uninstall26     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216026FF}" & Parameters  
      DIM Uninstall26x64  : Uninstall26x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416026FF}" & Parameters  
      DIM Uninstall27     : Uninstall27     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216027FF}" & Parameters  
      DIM Uninstall27x64  : Uninstall27x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416027FF}" & Parameters  
      DIM Uninstall28     : Uninstall28     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216028FF}" & Parameters  
      DIM Uninstall28x64  : Uninstall28x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416028FF}" & Parameters  
      DIM Uninstall29     : Uninstall29     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216029FF}" & Parameters  
      DIM Uninstall29x64  : Uninstall29x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416029FF}" & Parameters  
      DIM Uninstall30     : Uninstall30     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216030FF}" & Parameters  
      DIM Uninstall30x64  : Uninstall30x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416030FF}" & Parameters  
      DIM Uninstall31     : Uninstall31     = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83216031FF}" & Parameters  
      DIM Uninstall31x64  : Uninstall31x64  = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86416031FF}" & Parameters  
      DIM Uninstall7_1    : Uninstall7_1    = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217001FF}" & Parameters  
      DIM Uninstall7_1x64 : Uninstall7_1x64 = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417001FF}" & Parameters  
      DIM Uninstall7_2    : Uninstall7_2    = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217002FF}" & Parameters  
      DIM Uninstall7_2x64 : Uninstall7_2x64 = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417002FF}" & Parameters  
      DIM Uninstall7_3    : Uninstall7_3    = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217003FF}" & Parameters  
      DIM Uninstall7_3x64 : Uninstall7_3x64 = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417003FF}" & Parameters  
      DIM Uninstall7_4    : Uninstall7_4    = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F83217004FF}" & Parameters  
      DIM Uninstall7_4x64 : Uninstall7_4x64 = "msiexec.exe /x {26A24AE4-039D-4CA4-87B4-2F86417004FF}" & Parameters  

      oShell.Run Uninstall01,     7, True  
      oShell.Run Uninstall02,     7, True  
      oShell.Run Uninstall03,     7, True  
      oShell.Run Uninstall04,     7, True  
      oShell.Run Uninstall05,     7, True  
      oShell.Run Uninstall06,     7, True  
      oShell.Run Uninstall07,     7, True  
      oShell.Run Uninstall08,     7, True  
      oShell.Run Uninstall09,     7, True  
      oShell.Run Uninstall10,     7, True  
      oShell.Run Uninstall11,     7, True  
      oShell.Run Uninstall12,     7, True  
      oShell.Run Uninstall13,     7, True  
      oShell.Run Uninstall14,     7, True  
      oShell.Run Uninstall15,     7, True  
      oShell.Run Uninstall16,     7, True  
      oShell.Run Uninstall17,     7, True  
      oShell.Run Uninstall18,     7, True  
      oShell.Run Uninstall19,     7, True  
      oShell.Run Uninstall20,     7, True  
      oShell.Run Uninstall21,     7, True  
      oShell.Run Uninstall22,     7, True  
      oShell.Run Uninstall23,     7, True  
      oShell.Run Uninstall23x64,  7, True  
      oShell.Run Uninstall24,     7, True  
      oShell.Run Uninstall24x64,  7, True  
      oShell.Run Uninstall25,     7, True  
      oShell.Run Uninstall25x64,  7, True  
      oShell.Run Uninstall26,     7, True  
      oShell.Run Uninstall26x64,  7, True  
      oShell.Run Uninstall27,     7, True  
      oShell.Run Uninstall27x64,  7, True  
      oShell.Run Uninstall28,     7, True  
      oShell.Run Uninstall28x64,  7, True  
      oShell.Run Uninstall29,     7, True  
      oShell.Run Uninstall29x64,  7, True  
      oShell.Run Uninstall30,     7, True  
      oShell.Run Uninstall30x64,  7, True  
      oShell.Run Uninstall31,     7, True  
      oShell.Run Uninstall31x64,  7, True  
      oShell.Run Uninstall7_1,    7, True  
      oShell.Run Uninstall7_1x64, 7, True  
      oShell.Run Uninstall7_2,    7, True  
      oShell.Run Uninstall7_2x64, 7, True  
      oShell.Run Uninstall7_3,    7, True  
      oShell.Run Uninstall7_3x64, 7, True  
      oShell.Run Uninstall7_4,    7, True  
      oShell.Run Uninstall7_4x64, 7, True  

      REM Cleanup Local Variables  
      Set oShell          = Nothing  
      Set Parameters      = Nothing  
      Set Uninstall01     = Nothing  
      Set Uninstall02     = Nothing  
      Set Uninstall03     = Nothing  
      Set Uninstall04     = Nothing  
      Set Uninstall05     = Nothing  
      Set Uninstall06     = Nothing  
      Set Uninstall07     = Nothing  
      Set Uninstall08     = Nothing  
      Set Uninstall09     = Nothing  
      Set Uninstall10     = Nothing  
      Set Uninstall11     = Nothing  
      Set Uninstall12     = Nothing  
      Set Uninstall13     = Nothing  
      Set Uninstall14     = Nothing  
      Set Uninstall15     = Nothing  
      Set Uninstall16     = Nothing  
      Set Uninstall17     = Nothing  
      Set Uninstall18     = Nothing  
      Set Uninstall19     = Nothing  
      Set Uninstall20     = Nothing  
      Set Uninstall21     = Nothing  
      Set Uninstall22     = Nothing  
      Set Uninstall23     = Nothing  
      Set Uninstall23x64  = Nothing  
      Set Uninstall24     = Nothing  
      Set Uninstall24x64  = Nothing  
      Set Uninstall25     = Nothing  
      Set Uninstall25x64  = Nothing  
      Set Uninstall26     = Nothing  
      Set Uninstall26x64  = Nothing  
      Set Uninstall27     = Nothing  
      Set Uninstall27x64  = Nothing  
      Set Uninstall28     = Nothing  
      Set Uninstall28x64  = Nothing  
      Set Uninstall29     = Nothing  
      Set Uninstall29x64  = Nothing  
      Set Uninstall30     = Nothing  
      Set Uninstall30x64  = Nothing  
      Set Uninstall31     = Nothing  
      Set Uninstall31x64  = Nothing  
      Set Uninstall7_1    = Nothing  
      Set Uninstall7_1x64 = Nothing  
      Set Uninstall7_2    = Nothing  
      Set Uninstall7_2x64 = Nothing  
      Set Uninstall7_3    = Nothing  
      Set Uninstall7_3x64 = Nothing  
      Set Uninstall7_4    = Nothing  
      Set Uninstall7_4x64 = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub Installx86()  

      REM Define Local Objects  
      DIM oShell : SET oShell = CreateObject("Wscript.Shell")  

      REM Define Local Variables  
      DIM File       : File       = Chr(32) & RelativePath & "x86\jre1.7.0_04.msi"  
      DIM Parameters : Parameters = Chr(32) & "/qb- ADDLOCAL=ALL IEXPLORER=1 MOZILLA=1 SYSTRAY=1 JAVAUPDATE=1 JU=0 AUTOUPDATECHECK=1 /norestart"  
      DIM Install    : Install    = "msiexec.exe /i" & File & Parameters  

      oShell.Run Install, 1, True  

      REM Cleanup Local Variables  
      Set File       = Nothing  
      Set Install    = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub Installx64()  

      REM Define Local Objects  
      DIM oShell : SET oShell = CreateObject("Wscript.Shell")  

      REM Define Local Variables  
      DIM File       : File       = Chr(32) & RelativePath & "x64\jre1.7.0_04.msi"  
      DIM Parameters : Parameters = Chr(32) & "/qb- ADDLOCAL=ALL IEXPLORER=1 MOZILLA=1 SYSTRAY=1 JAVAUPDATE=1 JU=0 AUTOUPDATECHECK=1 /norestart"  
      DIM Install    : Install    = File & Parameters  

      oShell.Run Install, 1, True  

      REM Cleanup Local Variables  
      Set File       = Nothing  
      Set Install    = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub GlobalVariableCleanup()  

      Set Architecture = Nothing  
      Set LogFolder    = Nothing  
      Set RelativePath = Nothing  

 End Sub  

17 April 2012

USMT 4.0 PC-to-PC Migration Script


This script will execute the USMT, migrating data from the old machine to the new machine. Both PCs must be on the network. You will be prompted to enter the old computer name, new computer name, and the username. This is the only interaction required. A status window will appear giving the status of each state of the migration. Error checking has been included in the coding and returns an error if one if generated. The USMT has been customized for the command prompt window to be minimized so that it can be restored if need be for troubleshooting/status purposes.

The global variable, USMTLocation , contains the network location of where the USMT 4.0 is located, specifically this VBScript. It must have a backslash at the end of the network location. Both USMT 4.0 x86 and x64 must be located at %USMTLocation%\x86 and %USMTLocation%\x64, as this script is set to automatically determine the architecture of the old machine and runs the appropriate USMT version. PSTools also needs to be installed at %USMTLocation%\PSTools so that PsExec is available to run. This is used to run the scanstate, robocopy, and loadstate locally on the machines so that bandwidth and speed are not compromised.

NOTE: Robocopy does not exist on XP machines. I deployed robocopy.exe to all XP machines in the c:\windows\system32 directories. If robocopy is not on the machine, the script will fail.


NOTE: Before you take this script and use it, you must know the ins and outs of USMT, which requires a great deal of knowledge of it. There will be several XML files that you will have to write to control the USMT process. Without knowing how this works, this script will be useless. This script has to be customized to your environment, as it is not an off-the-shelf product ready to run on just any system. The PsExec is very touchy and requires a lot of time and knowledge to get it working correctly. I probably spent about two days just trying to get this function to work correctly. I have written the code to try and make it as simple as possible to customize it to each environment's demands.

Here is a link where users were troubleshooting this script to meet the needs and required configurations of their environment:



You can download a copy of this script from here.


 REM ***************************************************************************   
 REM ***      Program: USMT_New_Computer.vbs   
 REM ***       Author: Mick Pletcher   
 REM ***      Created: 21 February 2010   
 REM ***       Edited: 22 July 2010   
 REM ***   
 REM ***  Description: This script will execute the USMT, migrating data from   
 REM ***               the old machine to the new machine. Both PCs must be on   
 REM ***               the network. You will be prompted to enter the old   
 REM ***               computer name, new computer name, and the username.   
 REM ***               This is the only interaction required. A status window   
 REM ***               will appear giving the status of each state of the   
 REM ***               migration. Error checking has been included in the   
 REM ***               coding and returns an error if one if generated. The USMT   
 REM ***               has been customized for the command prompt window to be   
 REM ***               minimized so that it can be restored if need be for   
 REM ***               troubleshooting/status purposes.   
 REM ***   
 REM ***               The global variable, USMTLocation , contains the network   
 REM ***               location of where the USMT 4.0 is located, specifically   
 REM ***               this VBScript. Both USMT 4.0 x86 and x64 must be located   
 REM ***               at % USMTLocation%\x86 and % USMTLocation%\x64, as this   
 REM ***               script is set to automatically determine the architecture   
 REM ***               of the old machine and runs the appropriate USMT version.   
 REM ***               PSTools also needs to be installed at   
 REM ***               %USMTLocation%\PSTools so that PsExec is available to run.   
 REM ***               This is used to run the scanstate, robocopy, and loadstate   
 REM ***               locally on the machines so that bandwidth and speed are   
 REM ***               not compromised.   
 REM ***               1) Create HTML Display Status Window   
 REM ***               2) Enter Source PC, Destination PC, and Username   
 REM ***               3) Delete Old USMT folders and Create New USMT Folders   
 REM ***               4) Determine if the system is x86 or x64   
 REM ***               5) Perform USMT Migration on Old Machine   
 REM ***               6) Exit Script if USMT Migration Failed   
 REM ***               7) Copy Migrated USMT data to New Machine   
 REM ***               8) Load Migrated USMT data on New Machine   
 REM ***               9) Verify USMT   
 REM ***              10) Cleanup Global Variables   
 REM ***   
 REM ***************************************************************************   
 Option Explicit   

 REM Define Global Constants   
 CONST USMTLocation = "\\global.gsp\data\special\Deploy\USMT40\"   

 REM Define Global Objects   
 DIM objIE : Set objIE = CreateObject("InternetExplorer.Application")   

 REM Define Global Variables   
 DIM OldComputer   : Set OldComputer = Nothing   
 DIM NewComputer   : Set NewComputer = Nothing   
 DIM ReturnCode    : Set ReturnCode  = Nothing   
 DIM UserName      : Set UserName    = Nothing   
 DIM USMTSourceCMD : USMTSourceCMD   = "0"   
 DIM USMTDestCMD   : USMTDestCMD     = "0"   

 REM Create HTML Display Status Window   
 CreateDisplayWindow()   
 REM Enter Source PC, Destination PC, and Username   
 GetComputerInfo()   
 REM Delete Old USMT folders and Create New USMT Folders   
 CreateUSMTFolders()   
 REM Determine if the system is x86 or x64   
 DetermineArchitecture()   
 REM Perform USMT Migration on Old Machine   
 USMTMigrate()   
 REM Exit Script if USMT Migration Failed   
 VerifyScanState()   
 REM Copy Migrated USMT data to New Machine   
 CopyUSMTData()   
 REM Load Migrated USMT data on New Machine   
 LoadUSMTData()   
 REM Verify USMT   
 VerifyLoadState()   
 REM Cleanup Global Variables   
 GlobalVariableCleanUp()   

 '******************************************************************************   
 '******************************************************************************   

 Sub CreateDisplayWindow()   

   REM Define Local Constants   
   CONST strComputer = "."   

   REM Define Local Objects   
   DIM objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")   
   DIM colItems      : Set colItems      = objWMIService.ExecQuery ("Select PelsWidth,PelsHeight From Win32_DisplayConfiguration")   
   DIM objItem       : Set objItem       = Nothing   

   REM Define Local Variables   
   DIM intWidth        : intWidth            = 320   
   DIM intHeight       : intHeight           = 240   
   DIM intScreenWidth  : Set intScreenWidth  = Nothing   
   DIM intScreenHeight : Set intScreenHeight = Nothing   

   For Each objItem in colItems   
     intScreenWidth = objItem.PelsWidth   
     intScreenHeight = objItem.PelsHeight   
   Next   
   objIE.Navigate "about:blank"   
   objIE.Toolbar    = 0   
   objIE.StatusBar  = 0   
   objIE.AddressBar = 0   
   objIE.MenuBar    = 0   
   objIE.Resizable  = 0   
   While objIE.ReadyState <> 4   
     WScript.Sleep 100   
   Wend   
   objIE.Left    = (intScreenWidth / 2) - (intWidth / 2)   
   objIE.Top     = (intScreenHeight / 2) - (intHeight / 2)   
   objIE.Visible = True  
 
   REM Cleanup Local Variables   
   Set colItems        = Nothing   
   Set intScreenWidth  = Nothing   
   Set intScreenHeight = Nothing   
   Set intWidth        = Nothing   
   Set intHeight       = Nothing   
   Set objItem         = Nothing   
   Set objWMIService   = Nothing   

 End Sub   

 '******************************************************************************   

 Sub GetComputerInfo()   

   OldComputer = InputBox( "Enter the old computer name:" )   
   NewComputer = InputBox( "Enter the new computer name:" )   
   UserName    = InputBox( "Enter the username:" )   
   objIE.Document.WriteLn "<FONT SIZE=8>USMT migration of " & UserName & " from " & OldComputer & " to " & NewComputer & "</FONT><BR><BR><BR>"   

 End Sub   

 '******************************************************************************   

 Sub CreateUSMTFolders()   

   On Error Resume Next   

   REM Define Local Objects   
   DIM FSO : SET FSO = CreateObject("Scripting.FileSystemObject")   

   REM Define Local Variables   
   DIM comp         : Set comp         = Nothing   
   DIM DeleteFolder : Set DeleteFolder = Nothing   
   DIM TMP          : TMP              = "\\" & OldComputer & "\c$\Temp"   
   DIM MigData      : MigData          = TMP & "\MigData"   
   DIM USMTPath     : USMTPath         = MigData & "\" & UserName & "\" & OldComputer   

   objIE.Document.WriteLn "Creating USMT Folders....."   
   REM Delete old USMTPATH, if exists   
   If FSO.FolderExists(USMTPath) then   
     Set DeleteFolder = FSO.GetFolder(USMTPath)   
     DeleteFolder.Delete   
   End If   
   If FSO.FolderExists(MigData & "\" & UserName) then   
     Set DeleteFolder = FSO.GetFolder(MigData & "\" & UserName )   
     DeleteFolder.Delete   
   End If   
   If FSO.FolderExists(MigData) then   
     Set DeleteFolder = FSO.GetFolder(MigData)   
     DeleteFolder.Delete   
   End If   
   REM Create USMTPATH   
   If NOT FSO.FolderExists(TMP) then   
     FSO.CreateFolder(TMP)   
   End If   
   FSO.CreateFolder(MigData)   
   FSO.CreateFolder(MigData & "\" & UserName)   
   FSO.CreateFolder(MigData & "\" & UserName & "\" & OldComputer)   
   If FSO.FolderExists(USMTPath) then   
     objIE.Document.WriteLn "Success" & "<BR><BR>"   
   else   
     objIE.Document.WriteLn "Failure" & "<BR><BR>"   
   End If   

   REM Cleanup Local Variables   
   Set FSO          = Nothing   
   Set comp         = Nothing   
   Set TMP          = Nothing   
   Set TMP          = Nothing   
   Set MigData      = Nothing   
   Set USMTPath     = Nothing   
   Set DeleteFolder = Nothing   

 End Sub   

 '******************************************************************************   

 Sub DetermineArchitecture()   

   REM Define Local Objects   
   DIM FSO                 : SET FSO                 = CreateObject("Scripting.FileSystemObject")   
   DIM objWMIService       : Set objWMIService       = Nothing   
   DIM objWMIServiceSet    : Set objWMIServiceSet    = Nothing   
   DIM colOperatingSystems : Set colOperatingSystems = Nothing   
   DIM objOperatingSystem  : Set objOperatingSystem  = Nothing   

   REM Define Local Variables   
   DIM x86RUNPATH   : x86RUNPATH    = USMTLocation & "x86"   
   DIM x64RUNPATH   : x64RUNPATH    = USMTLocation & "x64"   
   DIM OSSourceType : OSSourceType  = "\\" & OldComputer & "\c$\Program Files (x86)"   
   DIM OSDestType   : OSDestType    = "\\" & NewComputer & "\c$\Program Files (x86)"   
   DIM msgSource    : Set msgSource = Nothing   
   DIM msgDest      : Set msgDest   = Nothing   

   Set objWMIService = GetObject("winmgmts:\\" & OldComputer & "\root\cimv2")       
   Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")   
   For Each objOperatingSystem in colOperatingSystems   
     msgSource = objOperatingSystem.Caption   
   Next   
   objIE.Document.WriteLn "Determining Source Architecture....."   
   If FSO.FolderExists(OSSourceType) Then   
     USMTSourceCMD = x64RUNPATH   
   else   
     USMTSourceCMD = x86RUNPATH   
   End IF   
   If NOT USMTSourceCMD = "0" then   
     objIE.Document.WriteLn "Success" & "<BR>"   
   else   
     objIE.Document.WriteLn "Failure(" & ReturnCode & ")" & "<BR>"   
   End If   
   objIE.Document.WriteLn "Determining Destination Architecture....."   
   Set objWMIService = GetObject("winmgmts:\\" & NewComputer & "\root\cimv2")       
   Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")   
   For Each objOperatingSystem in colOperatingSystems   
     msgDest = objOperatingSystem.Caption   
   Next   
   If FSO.FolderExists(OSDestType) Then   
     USMTDestCMD = x64RUNPATH   
   else   
     USMTDestCMD = x86RUNPATH   
   End IF   
   If NOT USMTDestCMD = "0" then   
     objIE.Document.WriteLn "Success" & "<BR>"   
   else   
     objIE.Document.WriteLn "Failure(" & ReturnCode & ")" & "<BR>"   
   End If   
   objIE.Document.WriteLn "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Source:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " & msgSource &_   
               Chr(32) & Right(USMTSourceCMD,3) & "<BR>"   
   objIE.Document.WriteLn "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Destination: " & msgDest & Chr(32) & Right(USMTDestCMD,3) & "<BR><BR>"   

   REM Cleanup Variables   
   Set colOperatingSystems = Nothing   
   Set FSO                 = Nothing   
   Set msgDest             = Nothing   
   Set msgSource           = Nothing   
   Set x86RUNPATH          = Nothing   
   Set x64RUNPATH          = Nothing   
   Set objWMIService       = Nothing   
   Set objWMIServiceSet    = Nothing   
   Set OSSourceType        = Nothing   
   Set OSDestType          = Nothing   
   Set objOperatingSystem  = Nothing   

 End Sub   

 '******************************************************************************   

 Sub USMTMigrate()   

   REM Define Local Objects   
   DIM oShell : SET oShell = CreateObject("Wscript.Shell")   

   REM Define Local Variables   
   DIM Debug      : Debug      = "13"   
   DIM TMP        : TMP        = "c:\Temp"   
   DIM MigData    : MigData    = TMP & "\MigData"   
   DIM LOGPATH    : LOGPATH    = MigData & "\" & UserName   
   DIM StorePATH  : StorePATH  = MigData & "\" & UserName & "\" & OldComputer   
   DIM RemoteExec : RemoteExec = USMTLocation & "PSTools\PsExec.exe \\" & OldComputer &_   
                                 Chr(32) & "-s" & Chr(32)   
   DIM USMT       : USMT       = RemoteExec & USMTSourceCMD & "\scanstate.exe " & StorePATH & " /v:" & Debug & " /i:" & USMTSourceCMD &_   
                                 "\Migapp.xml /i:" & USMTSourceCMD & "\MigDocs.xml /i:" & USMTSourceCMD & "\miguser.xml /progress:" & LOGPATH &_   
                                 "\ScanStateProg.log /l:" & LOGPATH & "\ScanState.log /ui:Nash\" & UserName & " /c /vsc"   

   objIE.Document.WriteLn "Executing Scanstate on " & OldComputer & "....."   
   ReturnCode = oShell.Run(USMT, 7, True)   
   If ReturnCode = "0" then   
     objIE.Document.WriteLn "Success" & "<BR><BR>"   
   else   
     objIE.Document.WriteLn "Failure(" & ReturnCode & ")" & "<BR><BR>"   
   End If   

   REM Cleanup Variables   
   Set Debug      = Nothing   
   SET oShell     = Nothing   
   SET TMP        = Nothing   
   SET MigData    = Nothing   
   SET LOGPATH    = Nothing   
   Set RemoteExec = Nothing   
   SET StorePATH  = Nothing   
   Set USMT       = Nothing   

 End Sub   

 '******************************************************************************   

 Sub VerifyScanState()   

   If NOT ReturnCode = "0" then   
     MsgBox("The data migration on " & OldComputer & " failed due to error" & ReturnCode &_   
         ". Please check the log file located at & \\" & OldComputer & "\c$\Temp\MigData\ScanLog.log.")   
     GlobalVariableCleanUp()   
     WScript.Quit   
   Else   
     Set ReturnCode = Nothing   
   End If   

 End Sub   

 '******************************************************************************   

 Sub CopyUSMTData()   

   REM Define Local Objects   
   DIM FSO    : SET FSO    = CreateObject("Scripting.FileSystemObject")   
   DIM oShell : SET oShell = CreateObject("Wscript.Shell")   

   REM Define Local Variables   
   DIM SourceUSMTPath : SourceUSMTPath = "\\" & OldComputer & "\c$\Temp\MigData"   
   DIM DestUSMTPath   : DestUSMTPath   = "\\" & NewComputer & "\c$\Temp\MigData"   
   DIM Parameters     : Parameters     = "/e /eta /mir"   
   DIM RemoteExec     : RemoteExec     = USMTLocation & "PSTools\PsExec.exe \\" & OldComputer &_   
                                         Chr(32) & "-s" & Chr(32)   
   DIM RoboCopyCMD    : RoboCopyCMD    = RemoteExec & "RoboCopy.exe" & Chr(32) & SourceUSMTPath & Chr(32) & DestUSMTPath &_   
                                         Chr(32) & Parameters   

   objIE.Document.WriteLn "Copying USMT folder from " & OldComputer & " to " & NewComputer & "....."   
   oShell.Run RoboCopyCMD, 7, True   
   If FSO.FolderExists(DestUSMTPath) then   
     objIE.Document.WriteLn "Success" & "<BR><BR>"   
   else   
     objIE.Document.WriteLn "Failure" & "<BR><BR>"   
   End If   

   REM Cleanup Variables   
   Set FSO            = Nothing   
   Set oShell         = Nothing   
   SET SourceUSMTPath = Nothing   
   SET DestUSMTPath   = Nothing   
   Set Parameters     = Nothing   
   Set RemoteExec     = Nothing   
   Set RoboCopyCMD    = Nothing   

 End Sub   

 '******************************************************************************   

 Sub LoadUSMTData()   

   REM Define Local Objects   
   DIM oShell : SET oShell = CreateObject("Wscript.Shell")   

   REM Define Local Variables   
   DIM Debug      : Debug      = "13"   
   DIM TMP        : TMP        = "c:\Temp"   
   DIM MigData    : MigData    = TMP & "\MigData"   
   DIM LOGPATH    : LOGPATH    = MigData & "\" & UserName   
   DIM StorePATH  : StorePATH  = MigData & "\" & UserName & "\" & OldComputer   
   DIM RemoteExec : RemoteExec = USMTLocation & "PSTools\PsExec.exe \\" & NewComputer &_   
                                 Chr(32) & "-s" & Chr(32)   
   DIM USMT       : USMT       = RemoteExec & USMTDestCMD & "\loadstate.exe " & StorePATH & " /v:" & Debug & " /i:" & USMTDestCMD &_   
                                 "\Migapp.xml /i:" & USMTDestCMD & "\MigDocs.xml /i:" & USMTDestCMD & "\miguser.xml /progress:" &_   
                                 LOGPATH & "\LoadStateProg.log /l:" & LOGPATH & "\LoadState.log /ui:Nash\" & UserName & " /c"   

   objIE.Document.WriteLn "Executing Loadstate on " & NewComputer & "....."   
   ReturnCode = oShell.Run(USMT, 7, True)   
   If ReturnCode = "0" then   
     objIE.Document.WriteLn "Success" & "<BR><BR>"   
   else   
     objIE.Document.WriteLn "Failure(" & ReturnCode & ")" & "<BR><BR>"   
   End If   

   REM Cleanup Variables   
   Set Debug      = Nothing   
   SET oShell     = Nothing   
   SET TMP        = Nothing   
   SET MigData    = Nothing   
   SET LOGPATH    = Nothing   
   Set RemoteExec = Nothing   

 End Sub   

 '******************************************************************************   

 Sub VerifyLoadState()   

   If NOT ReturnCode = "0" then   
     MsgBox("The data migration on " & NewComputer & " failed due to error " & ReturnCode & ". Please check the log file located at & \\" &_   
       NewComputer & "\c$\Temp\MigData\LoadState.log.")   
     GlobalVariableCleanUp()   
     objIE.Quit   
     WScript.Quit   
   Else   
     MsgBox("The data successfully migrated from " & OldComputer & " to " & NewComputer & ".")   
   End If   

 End Sub   

 '******************************************************************************   

 Sub GlobalVariableCleanUp()   

   objIE.Quit   
   Set OldComputer   = Nothing   
   Set objIE         = Nothing   
   Set NewComputer   = Nothing   
   Set ReturnCode    = Nothing   
   Set UserName      = Nothing   
   Set USMTSourceCMD = Nothing   
   Set USMTDestCMD   = Nothing   

 End Sub  

12 April 2012

Customizing the ZTIBiosCheck.wsf file for MDT/SCCM

As there is not much documentation on how to use the ZTIBiosCheck.wsf file with MDT/SCCM, I had to figure a lot of it out. The WSF file retrieves the BIOS data via WMI queries to compare against the data stored in the ZTIBIOSCheck.xml file. The XML file comes with a blank template at the top and one prefilled example. It also has a script at the bottom that can be used to retrieve the information required by the XML file, but it is not clean. That is why I took that script and heavily modified it to output cleaner data and be SMS/SCCM deploy friendly by naming the output file to the computer model it was run on.

The first thing you will want to do is run the VBScript I rewrote, the link is at the bottom, on all of the model machines in your environment. That will return a text file on each system. Gather all of the text files and now you are ready to populate the ZTIBIOSCheck.xml file. Open up the XML file. You can delete the example in there, but leave the blank template. Copy the blank template and paste it directly underneath. Open up your first text file and you will see all of the necessary fields are there for you to fill in the data.

NOTE: In the output text files, you will notice that I put a less than (<) and greater than (>) symbols in front and  behind each of the data output fields. I did this because there will be spaces sometimes before and/or after the output data. Those spaces are important to include when populating the data in the XML file. So when you copy a field, be sure to copy from the less than to the greater than symbols, but not including them, otherwise the WSF file will not see the field as the same as what it read from the system.

Here is the VBScript I rewrote, along with a link to download it:






   
 REM ***************************************************************************  
 REM ***     Program: ZTIBIOS.vbs  
 REM ***      Author: Mick Pletcher  
 REM ***     Created: 12 April 2012  
 REM ***      Edited:   
 REM ***  
 REM *** Description: This script will retrieve the information required for   
 REM ***              populating the ZTIBIOSCheck.xml fields, located in   
 REM ***              c:\deploymentshare\scripts\ of the MDT server. It's  
 REM ***              output is stored in a file in the same directory as the  
 REM ***              script with the filename of the computer model.txt. This  
 REM ***              was done to accomodate using this script with SMS/SCCM on  
 REM ***              multiple models of machines to differentiate the outputs.  
 REM ***              This text file contains all of the necessary  
 REM ***              fields required for populating the information for a  
 REM ***              new system. There is a template field at the top of  
 REM ***              the xml file that you can copy and populate with the  
 REM ***              output data from this script. It is suggested that you  
 REM ***              update the BIOS to the latest version first before  
 REM ***              running this script, as that will update the information  
 REM ***              acquired by this script.   
 REM ***************************************************************************  
 Option Explicit  
   
 REM Define Objects  
 DIM FSO           : Set FSO           = CreateObject("Scripting.FileSystemObject")  
 DIM objFile       : Set objFile       = Nothing  
 DIM objHotfixFile : Set objHotfixFile = Nothing  
   
 REM Define Variables  
 DIM BIOS     : Set BIOS     = Nothing  
 DIM Computer : Set Computer = Nothing  
   
 For each Computer in GetObject("winmgmts:\\.\root\cimv2").InstancesOf("Win32_ComputerSystemProduct")  
      For each BIOS in GetObject("winmgmts:\\.\root\cimv2").InstancesOf("Win32_BIOS")  
           Set objFile = FSO.CreateTextFile(Trim(Computer.Name) & ".txt", True)  
           Set objHotfixFile = FSO.OpenTextFile(Trim(Computer.Name) & ".txt", 1,True)  
           objFile.WriteLine("Lookup Name:" & Chr(32) & Chr(60) & BIOS.Description & Chr(62))  
           objFile.WriteLine("Computer Manufacturer:" & Chr(32) & Chr(60) & Computer.Vendor & Chr(62))  
           objFile.WriteLine("Model:" & Chr(32) & Chr(60) & Computer.Name & Chr(62))  
           objFile.WriteLine("Date:" & Chr(32) & Chr(60) & BIOS.ReleaseDate & Chr(62))  
      next  
 next  
 
 objFile.Close  
 
 REM Cleanup  
 Set FSO           = Nothing  
 Set objFile       = Nothing  
 Set objHotfixFile = Nothing  
 Set BIOS          = Nothing  
 Set Computer      = Nothing  
   

List Installed Windows 7 Updates

You are looking for a list of all installed updates on a machine for either identifying what has not been installed, or like myself, to find the list so that you know what is needed to download to include in the MDT/SCCM build. I have written this VBScript that will parse through and output all installed updates on a Windows 7 machine. The output is in csv format so that it can easily be opened up in Microsoft Excel.

Here is a link to the file for downloading and the code is just below:

   
 '*******************************************************************************  
 '     Program: ListUpdates.vbs  
 '      Author: Mick Pletcher  
 '        Date: 12 April 2012  
 '    Modified:  
 '  
 ' Description: This will output a list of all installed updates to a csv file  
 '*******************************************************************************  
 REM Define Local Variables  
 DIM strComputer : strComputer = "."  
    
 REM Define Local Objects  
 DIM FSO           : Set FSO = CreateObject("Scripting.FileSystemObject")  
 DIM objFile       : Set objFile = FSO.CreateTextFile("Updates.csv", True)  
 DIM objHotfixFile : Set objHotfixFile = FSO.OpenTextFile("Updates.csv", 1,True)  
 DIM objWMIService : Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _  
                     & strComputer & "\root\cimv2")  
 DIM colQuickFixes : Set colQuickFixes = objWMIService.ExecQuery _  
                     ("Select * from Win32_QuickFixEngineering")  
   
    
 For Each objQuickFix in colQuickFixes  
      objFile.WriteLine(objQuickFix.Description & Chr(44) & objQuickFix.HotFixID)  
 Next  
 Wscript.Echo "Done"  
 objFile.Close  
   
 REM Cleanup Local Objects and Variables  
 Set colQuickFixes = Nothing  
 Set FSO           = Nothing  
 Set objFile       = Nothing  
 Set objHotfixFile = Nothing  
 Set objWMIService = Nothing  
 Set strComputer   = Nothing