30 May 2012

Cannot Install .NET Framework 4 Updates and Security Updates

If you are seeing a backlog of security packs and updates pertaining to .NET Framework 4 due to an Unknown error during the Windows Updates, then this just might fix your issue like it did mine. This was caused by the corruption of both Microsoft .NET Framework 4 Client Profile and Microsoft .NET Framework 4 Extended. Neither can be uninstalled because they are both corrupted. If you try to uninstall the Extended, it will show that it was uninstalled, but it does not disappear in the add/remove programs. That is why it has to be repaired. Once they are repaired, there is no need to uninstall either. In order to fix the issue, you will first have to do the following steps in the exact order:

  1. Repair the Microsoft .NET Framework 4 Extended from the Programs and Features
  2. Repair the .NET Framework 4 Client Profile from the Programs and Features
  3. Under Services, stop the Windows Update service
  4. Delete all of the contents in the c:\windows\SoftwareDistribution folder
  5. Under Services, start the Windows Update service
  6. Reboot the PC
  7. Rerun the Windows Updates

15 May 2012

Adobe Flash Installation Script

This script will install both the x86 and x64 versions of Flash Player 11.x. It uninstalls all previous versions of Flash first. Flash 11.x is then installed, and finally the mms.cfg file is copied over to set Flash to automatically update. Both x86 and x64 versions of Flash are installed on 64-bit machines because those machines contain both x86 and x64 browsers.

Here is a link to download the script and here is a link for the mms.cfg file


 '*******************************************************************************  
 '     Program: InstallFlash.vbs  
 '      Author: Mick Pletcher  
 '        Date: 11 April 2012  
 '    Modified:  
 '  
 '   Publisher: Adobe  
 '     Program: Flash  
 '     Version: 11.x  
 ' Description: Adobe Flash Installation  
 '                 1) Define Relative Installation Path  
 '                 2) Determine Architecture  
 '                 3) Create Logs Folder  
 '                 4) Uninstall all old versions of Flash  
 '                 5) Install Flash  
 '                 6) Copy MMS File  
 '                 6) Initiate SMS Hardware Inventory  
 '                 7) Cleanup Global Variables  
 '                 8) Exit Installation  
 '*******************************************************************************  
 Option Explicit  

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

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

 DefineRelativePath()  
 REM Determine Architecture  
 DetermineArchitecture()  
 REM Create Logs Folder  
 CreateLogFolder()  
 REM Uninstall Old Version of Flash  
 UninstallOldFlash()  
 REM Install Flash  
 InstallFlash()  
 REM Copy MMS File  
 CopyMMS()  
 REM Initiate SMS Hardware Inventory  
 InitiateSMSHardwareInventory()  
 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 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 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 Objects & Variables  
      Set FSO = Nothing  

 End Sub  

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

 Sub UninstallOldFlash()  

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

      REM Define Local Variables  
      DIM oAPPDATA     : oAPPDATA     = oShell.ExpandEnvironmentStrings("%APPDATA%")  
      DIM Parameters   : Parameters   = Chr(32) & "-uninstall activex"  
      DIM Uninstallx86 : Uninstallx86 = RelativePath & "uninstall_flash_player_32bit.exe" & Parameters  
      DIM Uninstallx64 : Uninstallx64 = RelativePath & "uninstall_flash_player_64bit.exe" & Parameters  

      If Architecture = "x86" then  
           oShell.Run Uninstallx86, 1, True  
      Else  
           oShell.Run Uninstallx64, 1, True  
      End If  
      If FSO.FolderExists("C:\Windows\system32\Macromed\Flash\") then  
           FSO.DeleteFile "C:\Windows\system32\Macromed\Flash\*.*", True  
           FSO.DeleteFolder "C:\Windows\system32\Macromed\Flash", True  
      End If  
      If FSO.FolderExists("C:\Windows\SysWOW64\Macromed\Flash\") then  
           FSO.DeleteFile("C:\Windows\SysWOW64\Macromed\Flash\*.*")  
           FSO.DeleteFolder "C:\Windows\system32\Macromed\Flash", True  
      End If  
      If FSO.FolderExists(oAPPDATA & "\Adobe\Flash Player\") then  
           FSO.DeleteFile(oAPPDATA & "\Adobe\Flash Player\*.*")  
           FSO.DeleteFolder oAPPDATA & "\Adobe\Flash Player", True  
      End If  
      If FSO.FolderExists(oAPPDATA & "\Macromedia\Flash Player\") then  
           FSO.DeleteFile(oAPPDATA & "\Macromedia\Flash Player\*.*")  
           FSO.DeleteFolder oAPPDATA & "\Macromedia\Flash Player", True  
      End If  

      REM Cleanup Local Objects & Variables  
      Set FSO          = Nothing  
      Set oShell       = Nothing  
      Set Parameters   = Nothing  
      Set Uninstallx86 = Nothing  
      Set Uninstallx64 = Nothing  

 End Sub  

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

 Sub InstallFlash()  

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

      REM Define Local Variables  
      DIM Filex86    : Filex86    = Chr(32) & RelativePath & "install_flash_player_11_active_x_32bit.msi"  
      DIM Filex64    : Filex64    = Chr(32) & RelativePath & "install_flash_player_11_active_x_64bit.msi"  
      DIM LogFilex86 : LogFilex86 = Chr(32) & "/lvx" & Chr(32) & LogFolder & "Flash11x86.log"  
      DIM LogFilex64 : LogFilex64 = Chr(32) & "/lvx" & Chr(32) & LogFolder & "Flash11x64.log"  
      DIM Parameters : Parameters = Chr(32) & "/qb- /norestart"  
      DIM Install32  : Install32  = "msiexec.exe /i" & Filex86 & LogFilex86 & Parameters  
      DIM Install64  : Install64  = "msiexec.exe /i" & Filex64 & LogFilex64 & Parameters  

      oShell.Run Install32, 1, True  
      If Architecture = "x64" Then  
           oShell.Run Install64, 1, True  
      End If  

      REM Cleanup Local Variables  
      Set Filex86    = Nothing  
      Set Filex64    = Nothing  
      Set LogFilex86 = Nothing  
      Set LogFilex64 = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  
      Set Install32  = Nothing  
      Set Install64  = Nothing  

 End Sub  

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

 Sub CopyMMS()  

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

      If Architecture = "x86" then  
           If FSO.FileExists("C:\Windows\system32\Macromed\Flash") then  
                FSO.DeleteFile "C:\Windows\system32\Macromed\Flash\mms.cfg", True  
           End If  
           FSO.CopyFile RelativePath & "mms.cfg", "C:\Windows\system32\Macromed\Flash\", True  
      Else  
           If FSO.FileExists("C:\Windows\SysWow64\Macromed\Flash") then  
                FSO.DeleteFile "C:\Windows\SysWow64\Macromed\Flash\mms.cfg", True  
           End If  
           FSO.CopyFile RelativePath & "mms.cfg", "C:\Windows\SysWow64\Macromed\Flash\", True  
      End If  

      REM Cleanup Local Variables
      Set FSO = Nothing

 End Sub  

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

 Sub InitiateSMSHardwareInventory()  

      On Error Resume Next  

      REM Define Local Objects
      DIM oCPAppletMgr   : Set oCPAppletMgr   = CreateObject("CPApplet.CPAppletMgr")  
      DIM oClientAction  : Set oClientAction  = Nothing  
      DIM oClientActions : Set oClientActions = oCPAppletMgr.GetClientActions()  

      For Each oClientAction In oClientActions  
           If oClientAction.Name = "Hardware Inventory Collection Cycle" Then  
                oClientAction.PerformAction  
           End If  
      Next  

      REM Cleanup Local Objects
      Set oCPAppletMgr   = Nothing
      Set oClientAction  = Nothing  
      Set oClientActions = Nothing

 End Sub  

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

 Sub GlobalVariableCleanup()  

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

 End Sub  

14 May 2012

Adobe Reader X Installation Script with Previous Version Uninstaller Scripts

This script will uninstall all previous versions of Adobe Reader back to 4.x, thanks to this user's list of GUIDs that I took and expanded into a script. Some of the versions in there encompass all the previous versions before, so you won't see every single version listed. The reason for the direct uninstalls is because there have been issues with the Reader X uninstaller working correctly with previous versions, and leaving the old version present, along with installing Reader X. The are two reason I stopped at version 4.x: 1) The firm I work for is in the process of refreshing all machines to Windows 7, which will do away with all previous older versions of Reader, and 2) 4.x is the furthest back where a simple command line can be run with the available uninstaller present on the OS to zip through it if it is not installed. The last thing the script will do is enable automatic updates.

As you can see in the installation portion, I included a transform file. When you download the installation executable from Adobe, you can use 7-Zip to open it up and extract all of the files out for an easier installation and customization using the Adobe Customization Wizard.

NOTE: I am not sure why this occurs, but sometimes the registry key was not set on some machines. The ensure it got set, I created a .reg file with the key and put it into the .ipf file that I use to wrap around the VBScript. I normally use .ipf files to execute the VBScript file that gives evidence of when the script is actually running. Plus, it makes it easier to use executables with MDT/SMS/SCCM.

Here is a copy of the script available for download.


 '*******************************************************************************  
 '     Program: InstallReaderX.vbs  
 '      Author: Mick Pletcher  
 '        Date: 11 May 2012  
 '    Modified:   
 '  
 '     Program: Adobe Reader  
 '     Version: X  
 ' Description: This will install   
 '                 1) Define the relative installation path  
 '                 2) Create the Log Folder  
 '                 3) Uninstall Previous Versions  
 '                 4) Install Current Version  
 '                 5) Configure Automatic Update  
 '                 6) Cleanup Global Variables  
 '*******************************************************************************  
 Option Explicit  

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

 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 Determine Architecture  
 DetermineArchitecture()  
 REM Create the Log Folder  
 CreateLogFolder()  
 REM Uninstall Previous Version  
 Uninstall()  
 REM Install Current Version  
 Install()  
 REM Configure Automatic Update  
 AutoUpdate()  
 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 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 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 Uninstall()  

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

      REM Define Local Variables  
      DIM Parameters      : Parameters      = Chr(32) & "/qb- /norestart"  
      DIM Uninstall4x     : Uninstall4x     = "C:\WINDOWS\IsUninst.exe -a -f" & Chr(34) &_  
                                              "C:\Program Files\Common Files\Adobe\Acrobat 4.0\NT\Uninst.isu" &_  
                                              Chr(34) & Chr(32) & "-c" & Chr(34) &_  
                                              "C:\Program Files\Common Files\Adobe\Acrobat 4.0\NT\Uninst.dll" & Chr(34)  
      DIM Uninstall5x     : Uninstall5x     = "C:\WINDOWS\IsUninst.exe -a -f" & Chr(34) &_  
                                              "C:\Program Files\Common Files\Adobe\Acrobat 5.0\NT\Uninst.isu" &_  
                                              Chr(34) & Chr(32) & "-c" & Chr(34) &_  
                                              "C:\Program Files\Common Files\Adobe\Acrobat 5.0\NT\Uninst.dll" & Chr(34)  
      DIM Uninstall60     : Uninstall60     = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-000000000001}" & Parameters  
      DIM Uninstall601    : Uninstall601    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A00000000001}" & Parameters  
      DIM Uninstall602    : Uninstall602    = "msiexec.exe /x {AC76BA86-0000-0000-0000-6028747ADE01}" & Parameters  
      DIM Uninstall603    : Uninstall603    = "msiexec.exe /x {AC76BA86-0000-7EC8-7489-000000000603}" & Parameters  
      DIM Uninstall604    : Uninstall604    = "msiexec.exe /x {AC76BA86-0000-7EC8-7489-000000000604}" & Parameters  
      DIM Uninstall605    : Uninstall605    = "msiexec.exe /x {AC76BA86-0000-7EC8-7489-000000000605}" & Parameters  
      DIM Uninstall606    : Uninstall606    = "msiexec.exe /x {AC76BA86-0000-7EC8-7489-000000000606}" & Parameters  
      DIM Uninstall705    : Uninstall705    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A70500000002}" & Parameters  
      DIM Uninstall707    : Uninstall707    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A70700000002}" & Parameters  
      DIM Uninstall708    : Uninstall708    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A70800000002}" & Parameters  
      DIM Uninstall709    : Uninstall709    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A70900000002}" & Parameters  
      DIM Uninstall71x    : Uninstall71x    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A71000000002}" & Parameters  
      DIM Uninstall8DICT1 : Uninstall8DICT1 = "msiexec.exe /x {AC76BA86-7AD7-5464-3428-800000000003}" & Parameters  
      DIM Uninstall8DICT2 : Uninstall8DICT2 = "msiexec.exe /x {AC76BA86-7AD7-5464-3428-800000000004}" & Parameters  
      DIM Uninstall80     : Uninstall80     = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A80000000002}" & Parameters  
      DIM Uninstall81x    : Uninstall81x    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A81000000003}" & Parameters  
      DIM Uninstall811    : Uninstall811    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A81100000003}" & Parameters  
      DIM Uninstall812    : Uninstall812    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A81200000003}" & Parameters  
      DIM Uninstall812U   : Uninstall812U   = "msiexec.exe /x {6846389C-BAC0-4374-808E-B120F86AF5D7}" & Parameters  
      DIM Uninstall81xx   : Uninstall81xx   = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A81300000003}" & Parameters  
      DIM Uninstall82x    : Uninstall82x    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A82000000003}" & Parameters  
      DIM Uninstall830    : Uninstall830    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A83000000003}" & Parameters  
      DIM Uninstall9DICT  : Uninstall9DICT  = "msiexec.exe /x {AC76BA86-7AD7-5464-3428-900000000004}" & Parameters  
      DIM Uninstall91x    : Uninstall91x    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A81000000003}" & Parameters  
      DIM Uninstall920    : Uninstall920    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A92000000001}" & Parameters  
      DIM Uninstall93x    : Uninstall93x    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A93000000001}" & Parameters  
      DIM Uninstall940    : Uninstall940    = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-A94000000001}" & Parameters  
      DIM UninstallXDICT  : UninstallXDICT  = "msiexec.exe /x {AC76BA86-7AD7-5464-3428-A00000000004}" & Parameters  
      DIM Uninstall1000   : Uninstall1000   = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-AA0000000001}" & Parameters  
      DIM Uninstall101x   : Uninstall101x   = "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-AA1000000001}" & Parameters  

     'oShell.Run Uninstall4x,     1, True  
      oShell.Run Uninstall60,     1, True  
      oShell.Run Uninstall601,    1, True  
      oShell.Run Uninstall602,    1, True  
      oShell.Run Uninstall603,    1, True  
      oShell.Run Uninstall604,    1, True  
      oShell.Run Uninstall605,    1, True  
      oShell.Run Uninstall606,    1, True  
      oShell.Run Uninstall705,    1, True  
      oShell.Run Uninstall707,    1, True  
      oShell.Run Uninstall708,    1, True  
      oShell.Run Uninstall709,    1, True  
      oShell.Run Uninstall71x,    1, True  
      oShell.Run Uninstall8DICT1, 1, True  
      oShell.Run Uninstall8DICT2, 1, True  
      oShell.Run Uninstall80,     1, True  
      oShell.Run Uninstall81x,    1, True  
      oShell.Run Uninstall811,    1, True  
      oShell.Run Uninstall812,    1, True  
      oShell.Run Uninstall812U,   1, True  
      oShell.Run Uninstall81xx,   1, True  
      oShell.Run Uninstall82x,    1, True  
      oShell.Run Uninstall830,    1, True  
      oShell.Run Uninstall9DICT,  1, True  
      oShell.Run Uninstall91x,    1, True  
      oShell.Run Uninstall920,    1, True  
      oShell.Run Uninstall93x,    1, True  
      oShell.Run Uninstall940,    1, True  
      oShell.Run UninstallXDICT,  1, True  
      oShell.Run Uninstall1000,   1, True  
      oShell.Run Uninstall101x,   1, True  

      REM Cleanup Local Variables  
      Set oShell          = Nothing  
      Set Parameters      = Nothing  
      Set Uninstall4x     = Nothing  
      Set Uninstall60     = Nothing  
      Set Uninstall601    = Nothing  
      Set Uninstall602    = Nothing  
      Set Uninstall603    = Nothing  
      Set Uninstall604    = Nothing  
      Set Uninstall605    = Nothing  
      Set Uninstall606    = Nothing  
      Set Uninstall705    = Nothing  
      Set Uninstall707    = Nothing  
      Set Uninstall708    = Nothing  
      Set Uninstall709    = Nothing  
      Set Uninstall71x    = Nothing  
      Set Uninstall8DICT1 = Nothing  
      Set Uninstall8DICT2 = Nothing  
      Set Uninstall80     = Nothing  
      Set Uninstall81x    = Nothing  
      Set Uninstall811    = Nothing  
      Set Uninstall812    = Nothing  
      Set Uninstall812U   = Nothing  
      Set Uninstall81xx   = Nothing  
      Set Uninstall82x    = Nothing  
      Set Uninstall830    = Nothing  
      Set Uninstall9DICT  = Nothing  
      Set Uninstall91x    = Nothing  
      Set Uninstall920    = Nothing  
      Set Uninstall93x    = Nothing  
      Set Uninstall940    = Nothing  
      Set UninstallXDICT  = Nothing  
      Set Uninstall1000   = Nothing  
      Set Uninstall101x   = Nothing  

 End Sub  

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

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

      REM Define Local Variables  
      DIM MSI        : MSI        = Chr(32) & RelativePath & "AcroRead.msi"  
      DIM Logs       : Logs       = Chr(32) & "/lvx" & Chr(32) & LogFolder & LogFolderName & ".log"  
      DIM Transforms : Transforms = Chr(32) & "TRANSFORMS=" & RelativePath & "Transform.mst"  
      DIM Parameters : Parameters = Chr(32) & "/qb- /norestart"  
      DIM InstallX   : InstallX   = "msiexec.exe /i" & MSI & Transforms & Logs & Parameters  

      oShell.Run InstallX, 1, True  

      REM Cleanup Local Variables  
      Set InstallX   = Nothing  
      Set Logs       = Nothing  
      Set MSI        = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  
      Set Transforms = Nothing  

 End Sub  

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

 Sub AutoUpdate()  

      REM Define Local Constants  
      CONST HKEY_LOCAL_MACHINE = &H80000002  

      REM Define Local Objects  
      DIM oReg              : Set oReg          = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_  
                                                  strComputer & "\root\default:StdRegProv")  
      DIM oShell            : SET oShell        = CreateObject("Wscript.Shell")  
      DIM strKeyPath_x86    : strKeyPath_x86    = "SOFTWARE\Adobe\Adobe ARM\1.0\ARM"  
      DIM strKeyPath_x64    : strKeyPath_x64    = "SOFTWARE\Wow6432Node\Adobe\Adobe ARM\1.0\ARM"  
      DIM strDWORDValueName : strDWORDValueName = "iCheckReader"  
      DIM dwValue           : dwValue           = "3"  

      If Architecture = "x86" then  
           oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath_x86,strDWORDValueName  
           oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath_x86,strDWORDValueName,dwValue  
           'oShell.regwrite "HKLM\SOFTWARE\Adobe\Adobe ARM\1.0\ARM\iCheckReader", 3, "REG_DWORD"  
      Else  
           oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath_x64,strDWORDValueName  
           oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath_x64,strDWORDValueName,dwValue  
           'oShell.regwrite "HKLM\SOFTWARE\Wow6432Node\Adobe\Adobe ARM\1.0\ARM\iCheckReader", 3, "REG_DWORD"  
      End If  

      REM Cleanup Local Variables  
      Set dwValue           = Nothing  
      Set oReg              = Nothing  
      Set oShell            = Nothing  
      Set strDWORDValueName = Nothing  
      Set strKeyPath_x86    = Nothing  
      Set strKeyPath_x64    = Nothing  

 End Sub  

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

 Sub GlobalVariableCleanup()  

      Set LogFolder    = Nothing  
      Set RelativePath = Nothing  

 End Sub  

10 May 2012

Capture USMT to the Local Machine or a Network Share


This script allows for the USMT process to be executed locally on a machine from a remote location with the output to either the local machine or a network location. In order for the script to run correctly, you will need to  define the network location where USMT is installed. I also installed PSTools under the USMT location. The USMT location has two additional subdirectories. So in the USMT directory is this script and the x86 and x64 subdirectories contain the actual USMT files, along with the customized XML files for defining the USMT process. One for USMT x86 and the other for USMT x64. The PSTools is used to allow for the scanstate.exe to be run locally on the target machine so that network traffic is not bogged down.

I highly suggest that before running the USMT on the target machine to clean out unnecessary profiles. You can either delete them under System Properties-->User Profiles or through deleting the associated registry keys in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList. If you decide to delete the registry keys SystemProfile, LocalService, NetworkService, Administrator, and the user profile being migrated. You can find the key name under ProfileImagePath. Personally, I prefer deleting the registry keys for the fact that there are often profiles in the User Profile list that list as Unknown and cannot be deleted. The registry keys are what USMT references, not the actual folders. The reason for cleaning up these profiles before running the USMT process is the fact that it will scan every profile listed in the registry 20 times with a 30 second delay between each retry. That can add up to a significant amount of time if a lot of users have logged onto the machine.


NOTE: This script will not run "out-of-the-box." You will need to know a substantial amount about USMT and VBScripting in order to configure the script to match your environment. This script has been thoroughly tested and is consistently used in my current company's environment.

You can download the script from here.

 REM ***************************************************************************  
 REM ***     Program: USMT_Capture.vbs  
 REM ***      Author: Mick Pletcher  
 REM ***     Created: 23 July 2010  
 REM ***      Edited: 21 March 2011  
 REM ***  
 REM *** Description: This script will execute the USMT, creating a MIG file  
 REM ***                     located on the selected location, either on the local  
 REM ***                     machine, or on the network location. This is intended to  
 REM ***                     be used for generating the MIG file for the MDT/SCCM  
 REM ***                     imaging process to be included in the build. This was written  
 REM ***                     so that this script can be executed from any machine  
 REM ***                     which then executes the USMT process locally on the   
 REM ***                     target machine. PSTools will need to be downloaded and  
 REM ***                     extracted to the USMTLocation, specified below in the  
 REM ***                     Global constants. The global constants should be the  
 REM ***                     primary changes needed to be made to run this script  
 REM ***                     on any machine. The other change that will be needed  
 REM ***                     is in the USMTMigrate Subroutine. There are  
 REM ***                     additional XML files I have written for the USMT  
 REM ***                     process that would need to be removed.   
 REM ***  
 REM ***                     NOTE: To expedite the USMT process, I would suggest  
 REM ***                     going to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\  
 REM ***                     CurrentVersion\ProfileList and deleting all keys except for  
 REM ***                     the following (You can find the key name under  
 REM ***                     ProfileImagePath): SystemProfile, LocalService,   
 REM ***                     NetworkService, Administrator, and the user profile  
 REM ***                     being migrated. This will dramatically speed up the process  
 REM ***                     otherwise it will scan each profile 20 times, with a 5  
 REM ***                     second delay upon each failure. You need not delete  
 REM ***                     the profile directory, as the USMT only scans the   
 REM ***                     profiles listed under that registry key.  
 REM ***  
 REM ***                     Script Process:  
 REM ***                     1) Create HTML Display Status Window  
 REM ***                     2) Enter Source, Destination, 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) Verify USMT  
 REM ***                     8) Cleanup Global Variables  
 REM ***  
 REM ***************************************************************************  
 Option Explicit  

 REM Define Global Constants  
 'Used in the query for retrieving the SID  
 CONST NetDomain = "nash"  
 ' Specifies where to find the USMT executables  
 CONST USMTLocation = "\\global.gsp\data\special\Deploy\USMT40\"   
 ' Specifies where to write the MIG file locally  
 CONST USMTLocalStore = "c:\temp\MigData\"  
 ' Specifies where to write the MIG file on the network share  
 CONST USMTNetworkStore = "\\MDT02\USMT\"  

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

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

 REM Create HTML Display Status Window  
 CreateDisplayWindow()  
 REM Enter Source, Destination, and Username  
 GetComputerInfo()  
 REM Delete Old USMT folders, if exists, and Create New USMT Folders  
 CreateUSMTFolders()  
 REM Determine if the system is x86 or x64  
 DetermineArchitecture()  
 REM Retrieve SID from Old Computer  
 GetSID()  
 REM Perform USMT Migration on Old Machine  
 USMTMigrate()  
 REM Verify the ScanState ran with no errors  
 VerifyScanState()  
 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:" )  
      UserName    = InputBox( "Enter the username:" )  
      USMTOutput  = MsgBox("Output USMT to Network Location?", 4)  
      If USMTOutput = 6 then  
           USMTOutput = USMTNetworkStore & UserName & "\" & OldComputer  
      Else  
           USMTOutput = USMTLocalStore & UserName & "\" & OldComputer  
      End If  
      objIE.Document.WriteLn "<FONT SIZE=8>USMT migration of " & UserName & " from " & OldComputer & " to " & USMTOutput &_  
                                    Chr(32) & "</FONT><BR><BR><BR>"  

 End Sub  

 '****************************************************************************** 
 
 Sub CreateUSMTFolders()  

      On Error Resume Next  

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

      REM Define Local Variables  
      DIM CreateFolder : CreateFolder = "cmd.exe /c md" & Chr(32) & USMTOutput  
      objIE.Document.WriteLn "Creating USMT Folders....."  

      REM Create the USMT folders if they do not exist  
      If NOT FSO.FolderExists(USMTOutput) then  
           oShell.Run CreateFolder, 7, True  
      End If  

      REM Cleanup Local Variables  
      Set FSO          = Nothing  
      Set CreateFolder = Nothing  
      Set oShell       = 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 msgSource    : Set msgSource = 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 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Source:&nbsp; " & msgSource &_  
                                    Chr(32) & Right(USMTSourceCMD,3) & "<BR><BR>" 
 
      REM Cleanup Variables  
      Set colOperatingSystems = Nothing  
      Set FSO                 = Nothing  
      Set msgSource           = Nothing  
      Set x86RUNPATH          = Nothing  
      Set x64RUNPATH          = Nothing  
      Set objWMIService       = Nothing  
      Set objWMIServiceSet    = Nothing  
      Set OSSourceType        = Nothing  
      Set objOperatingSystem  = Nothing 
 
 End Sub  

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

 Sub GetSID()  

      REM Define Local Objects  
      DIM objWMIService : Set objWMIService = GetObject("winmgmts:\\" & OldComputer & "\root\cimv2")  
      DIM objAccount    : Set objAccount    = Nothing  

 '     Set objAccount = objWMIService.Get _  
 '          ("Win32_UserAccount.Name=" & Chr(39) & UserName & Chr(39) & ",Domain='nash'")  
      Set objAccount = objWMIService.Get _  
           ("Win32_UserAccount.Name=" & Chr(39) & UserName & Chr(39) & ",Domain=" & Chr(39) & NetDomain & Chr(39))  
      SID = objAccount.SID  

      REM Local Variable Cleanup  
      Set objAccount    = Nothing  
      Set objWMIService = 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 IgnoreProfs : IgnoreProfs = "cmd.exe /c Set MIG_IGNORE_PROFILE_MISSING=1"  
      DIM TMP         : TMP         = "c:\Temp"  
      DIM MigData     : MigData     = TMP & "\MigData"  
      DIM LOGPATH     : LOGPATH     = MigData & "\" & UserName  
      DIM RemoteExec  : RemoteExec  = USMTLocation & "PSTools\PsExec.exe \\" & OldComputer &_  
                                              Chr(32) & "-s" & Chr(32)  
      DIM USMT        : USMT        = RemoteExec & USMTSourceCMD & "\scanstate.exe " & USMTOutput & Chr(32) & "/v:" & Debug & Chr(32) & "/i:" &_  
                                              USMTSourceCMD & "\Migapp.xml" & Chr(32) & "/i:" & USMTSourceCMD & "\MigDocs.xml" & Chr(32) & "/i:" &_  
                                              USMTSourceCMD & "\miguser.xml" & Chr(32) & "/i:" & USMTSourceCMD & "\MigExclude.xml" & Chr(32) &_  
                                              "/progress:" & LOGPATH & "\ScanStateProg.log" & Chr(32) & "/l:" & LOGPATH & "\ScanState.log" &_  
                                              Chr(32) & "/ui:" & SID & Chr(32) & "/ue:*\* /c /vsc"  

      objIE.Document.WriteLn "Executing Scanstate on " & OldComputer & "....."  
      ReturnCode = oShell.Run(IgnoreProfs, 7, True)  
      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 IgnoreProfs = Nothing  
      SET oShell      = Nothing  
      SET TMP         = Nothing  
      SET MigData     = Nothing  
      SET LOGPATH     = Nothing  
      Set RemoteExec  = 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 GlobalVariableCleanUp()  

      Set OldComputer   = Nothing  
      Set objIE         = Nothing  
      Set ReturnCode    = Nothing  
      Set UserName      = Nothing  
      Set USMTOutput    = Nothing  
      Set USMTSourceCMD = Nothing  
      Set USMTDestCMD   = Nothing  

 End Sub  

Set Pagefile Size to double the Physical Memory

The firm I work for uses Autodesk Revit design software that requires the minimum and maximum pagefile sizes to be double the size of the installed physical memory. I wrote this script, which is run after Autodesk is installed, to do just that. It looks at the amount of physical memory and then doubles it. The reason there are ranges that I set in the Set Page File Size procedure is due to the fact that the script looks at the total installed memory and not the total physical memory, which differs by system due to how much is allocated to the on-board video card, therefor the installed memory is the net value after video card allocation.

Here is a link to download the script.

 '*******************************************************************************  
 '     Program: Install.vbs  
 '      Author: Mick Pletcher  
 '        Date: 23 August 2011  
 '    Modified:  
 '  
 '     Program: SetPageFileSize  
 '     Version:  
 ' Description: This will set the page file size to double the size of installed  
 '                 memory.  
 '                 1) Define the relative installation path  
 '                 2) Create the Log Folder  
 '                 3) Set Page File Size  
 '                 4) Write Log File  
 '                 7) Cleanup Global Variables  
 '*******************************************************************************  
 Option Explicit  

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

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

 REM Define the relative installation path  
 DefineRelativePath()  
 REM Create the Log Folder  
 CreateLogFolder()  
 REM Set PageFile Size  
 SetPagefileSize()  
 REM Write Log File  
 WriteLog()  
 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 SetPagefileSize()  

      REM Define Local Constants  
      CONST strComputer = "."  

      REM Define Local Objects  
      DIM oShell        : Set oShell        = CreateObject("Wscript.Shell")  
      DIM objWMIService : Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" &_  
                               strComputer & "\root\cimv2")  
      DIM colSettings   : Set colSettings   = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")  
      REM Define Local Variables  
      DIM Command01     : Command01         = "wmic computersystem where name=" & Chr(34) & "%computername%" & Chr(34) &_  
                                                   Chr(32) & "set AutomaticManagedPagefile=False"  
      DIM Command02     : Set Command02     = Nothing  
      DIM objComputer   : Set objComputer   = Nothing  

      For Each objComputer in colSettings  
           Pagefile = objComputer.TotalPhysicalMemory  
      Next  
      If Pagefile > 1000000000 AND Pagefile < 2000000000 THEN  
           Pagefile = "1024" * 2  
      ElseIf Pagefile > 2000000000 AND Pagefile < 3000000000 THEN  
           Pagefile = "2048" * 2  
      ElseIf Pagefile > 3000000000 AND Pagefile < 4000000000 THEN  
           Pagefile = "3072" * 2  
      ElseIf Pagefile > 4000000000 AND Pagefile < 5000000000 THEN  
           Pagefile = "4096" * 2  
      ElseIf Pagefile > 5000000000 AND Pagefile < 6000000000 THEN  
           Pagefile = "5120" * 2  
      ElseIf Pagefile > 6000000000 AND Pagefile < 7000000000 THEN  
           Pagefile = "6144" * 2  
      ElseIf Pagefile > 7000000000 AND Pagefile < 8000000000 THEN  
           Pagefile = "7168" * 2  
      ElseIf Pagefile > 8000000000 AND Pagefile < 9000000000 THEN  
           Pagefile = "8192" * 2  
      ElseIf Pagefile > 9000000000 AND Pagefile < 10000000000 THEN  
           Pagefile = "9216" * 2  
      ElseIf Pagefile > 10000000000 AND Pagefile < 11000000000 THEN  
           Pagefile = "10240" * 2  
      ElseIf Pagefile > 11000000000 AND Pagefile < 12000000000 THEN  
           Pagefile = "11264" * 2  
      ElseIf Pagefile > 12000000000 AND Pagefile < 13000000000 THEN  
           Pagefile = "12288" * 2  
      ElseIf Pagefile > 13000000000 AND Pagefile < 14000000000 THEN  
           Pagefile = "13312" * 2  
      ElseIf Pagefile > 14000000000 AND Pagefile < 15000000000 THEN  
           Pagefile = "14336" * 2  
      ElseIf Pagefile > 15000000000 AND Pagefile < 16000000000 THEN  
           Pagefile = "15360" * 2  
      ElseIf Pagefile > 16000000000 AND Pagefile < 17000000000 THEN  
           Pagefile = "16384" * 2  
      ElseIf Pagefile > 17000000000 AND Pagefile < 18000000000 THEN  
           Pagefile = "17408" * 2  
      ElseIf Pagefile > 18000000000 AND Pagefile < 19000000000 THEN  
           Pagefile = "18432" * 2  
      ElseIf Pagefile > 19000000000 AND Pagefile < 20000000000 THEN  
           Pagefile = "19456" * 2  
      ElseIf Pagefile > 20000000000 AND Pagefile < 21000000000 THEN  
           Pagefile = "20480" * 2  
      ElseIf Pagefile > 21000000000 AND Pagefile < 22000000000 THEN  
           Pagefile = "21504" * 2  
      ElseIf Pagefile > 22000000000 AND Pagefile < 23000000000 THEN  
           Pagefile = "22528" * 2  
      ElseIf Pagefile > 23000000000 AND Pagefile < 24000000000 THEN  
           Pagefile = "23552" * 2  
      ElseIf Pagefile > 24000000000 AND Pagefile < 25000000000 THEN  
           Pagefile = "24576" * 2  
      ElseIf Pagefile > 25000000000 AND Pagefile < 26000000000 THEN  
           Pagefile = "25600" * 2  
      ElseIf Pagefile > 26000000000 AND Pagefile < 27000000000 THEN  
           Pagefile = "26624" * 2  
      ElseIf Pagefile > 27000000000 AND Pagefile < 28000000000 THEN  
           Pagefile = "27648" * 2  
      ElseIf Pagefile > 28000000000 AND Pagefile < 29000000000 THEN  
           Pagefile = "28672" * 2  
      ElseIf Pagefile > 29000000000 AND Pagefile < 30000000000 THEN  
           Pagefile = "29696" * 2  
      ElseIf Pagefile > 30000000000 AND Pagefile < 31000000000 THEN  
           Pagefile = "30720" * 2  
      ElseIf Pagefile > 31000000000 AND Pagefile < 32000000000 THEN  
           Pagefile = "31744" * 2  
      ElseIf Pagefile > 31000000000 AND Pagefile < 32000000000 THEN  
           Pagefile = "32768" * 2  
      End If  
      Command02 = "wmic pagefileset where name=" & Chr(34) & "C:\\pagefile.sys" & Chr(34) &_  
                     Chr(32) & "set InitialSize=" & Pagefile & ",MaximumSize=" & Pagefile  
      REM Disable Automatic Pagefile Management  
      oShell.Run Command01, 1, True  
      REM Set Pagefile size to twice the size of the physical memory  
      oShell.Run Command02, 1, True  

      REM Cleanup Local Variables  
      Set colSettings   = Nothing  
      Set Command01     = Nothing  
      Set Command02     = Nothing  
      Set objComputer   = Nothing  
      Set objWMIService = Nothing  
      Set oShell        = Nothing  

 End Sub  

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

 Sub WriteLog()  

      REM Define Local Objects  
      DIM FSO  : Set FSO  = CreateObject("Scripting.FileSystemObject")  
      DIM File : Set File = FSO.CreateTextFile(LogFolder & LogFolderName & ".log",True)  

      File.WriteLine("PageFile Size has been set to" & Chr(32) & PageFile & Chr(32) & "megabytes.")  
      File.Close  

      REM Cleanup Local Variables  
      Set FSO  = Nothing  
      Set File = Nothing  

 End Sub  

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

 Sub GlobalVariableCleanup()  

      Set Installed    = Nothing  
      Set LogFolder    = Nothing  
      Set Pagefile     = Nothing  
      Set RelativePath = Nothing  

 End Sub  

08 May 2012

Robocopy Profiles when USMT Fails

Sometimes the USMT just fails and cannot be successfully run on a machine. The alternative is to have the user logon to a new machine and manually copy their profile contents to the new machine, mainly the Desktop, PST files, My Documents, and IE Favorites. I wrote this script to do just that. It asks for the old computer name, the new computer name, and the username. The user must have logged onto the new machine first before running this, otherwise Windows will create a new profile named <username>.admin. There are certain parts of the profile that must be created by the system and cannot be copied over. I have tried several different things, such as creating the registry keys and nothing works without the user logging in first.

I wrote this script so that psexec.exe is run from the subdirectory of the network share this script is run from. You can see the location in the RemoteExec variable. I also deployed the latest compatible version of robocopy to the c:\windows\system32 directory on all XP machines so that it can be run locally. The robocopy is run locally on the source system so that if this is being run in a remote office and it's also going to another machine in that same office, the traffic will only be in that office, otherwise it would have to come back to the system where the script was executed and then back to the destination system.

Here is a link to download the script.


 '*******************************************************************************  
 '     Program: ProfileRobocopy.vbs  
 '      Author: Mick Pletcher  
 '        Date: 04 January 2010  
 '    Modified:  
 ' Description: This script will robocopy a profile from one machine to another.  
 '                 It is intended to be used when the USMT fails. The user must  
 '                 logon to the new machine before running this script. If this is  
 '                 executed before a profile is created, a new profile will be  
 '                 created <profile>.xxx and the user will not see any of the   
 '                 copied data.  
 '                 There needs to be a %NetworkPath%\PSTools directory containing  
 '                 PSTools. Robocopy needs to be present in the PSTools directory.  
 '                 PSTools allows for the robocopy to run locally on the old  
 '                 machine, thereby conserving bandwidth if it is at a remote  
 '                 location.   
 '*******************************************************************************  
 Option Explicit  

 REM Define Constants  
 CONST TempFolder  = "c$\temp\"  
 CONST LogFolderName = "ProfileCopy"  
 CONST NetworkPath  = "\\global.gsp\data\special\Deploy\USMT\"  

 REM Define Global Variables  
 DIM NewComputer   : Set NewComputer   = Nothing  
 DIM OldComputer   : Set OldComputer   = Nothing  
 DIM NewComputerOS : Set NewComputerOS = Nothing  
 DIM OldComputerOS : Set OldComputerOS = Nothing  
 DIM LogFolder     : Set LogFolder     = Nothing  
 DIM OS            : Set OS            = Nothing  
 DIM RelativePath  : Set RelativePath  = Nothing  
 DIM ReturnCode    : ReturnCode        = "0"  
 DIM UserName      : Set UserName      = Nothing  

 REM Define relative installation path  
 DefineRelativePath()  
 REM Prompt for Old Computer Name, New Computer Name, and Username  
 GetComputerInfo()  
 REM Create the log folder  
 CreateLogFolder()  
 REM Determine which OS this script is being run from  
 DetermineOS()  
 MSGBOX OldComputerOS & Chr(32) & NewComputerOS  
 If (OldComputerOS = "WindowsXP") and (NewComputerOS = "WindowsXP") then  
      REM Robocopy the profile from the old XP machine to the new XP machine  
      CopyFilesXP2XP()  
 End If  
 If (OldComputerOS = "WindowsXP") and (NewComputerOS = "Windows7") then  
      REM Robocopy the profile from the old XP machine to the new Windows 7 machine  
      CopyFilesXP2Win7()  
 End If  
 If (OldComputerOS = "Windows7") and (NewComputerOS = "Windows7") then  
      REM Robocopy the profile from the old Windows 7 machine to the new Windows 7 machine  
      CopyFilesWin72Win7()  
 End If  
 REM Verify there were no errors during the robocopy  
 VerifyCopy()  
 REM Cleanup Global Variables  
 GlobalMemoryCleanup()  

 '*******************************************************************************  
 '*******************************************************************************  
 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 GetComputerInfo()  

      OldComputer = InputBox( "Enter the old computer name:" )  
      NewComputer = InputBox( "Enter the new computer name:" )  
      UserName  = InputBox( "Enter the username:" )  

 End Sub  
 '*******************************************************************************  
 Sub CreateLogFolder()  

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

      REM Define Local Variables  
      DIM Logs : Set Logs = Nothing  

      REM Initialize Local Variables  
      LogFolder = "\\" & OldComputer & "\" & TempFolder & LogFolderName & "\"  
      Logs      = LogFolder & "robocopy.log"  

      If NOT FSO.FolderExists("\\" & OldComputer & "\" & TempFolder) then  
           FSO.CreateFolder("\\" & OldComputer & "\" & TempFolder)  
      End If  
      If NOT FSO.FolderExists(LogFolder) then  
           FSO.CreateFolder(LogFolder)  
      End If  
      If FSO.FileExists(Logs) then  
           FSO.DeleteFile(Logs)  
      End If  

      REM Cleanup Local Variables  
      Set FSO  = Nothing  
      Set Logs = Nothing  

 End Sub  
 '*******************************************************************************  
 Sub DetermineOS()  

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

      IF FSO.FolderExists("\\" & OldComputer & "\c$\users\") then  
           OldComputerOS = "Windows7"  
      Else  
           OldComputerOS = "WindowsXP"  
      End If  
      IF FSO.FolderExists("\\" & NewComputer & "\c$\users\") then  
           NewComputerOS = "Windows7"  
      Else  
           NewComputerOS = "WindowsXP"  
      End If  

      REM Cleanup Local Variables  
      Set FSO = Nothing  

 End Sub  
 '*******************************************************************************  
 Sub CopyFilesXP2XP()  

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

      REM Define Local Variables  
      DIM ExcludeDir   : Set ExcludeDir   = Nothing  
      DIM ExcludeFiles : Set ExcludeFiles = Nothing  
      DIM Logs         : Set Logs         = Nothing  
      DIM Parameters   : Set Parameters   = Nothing  
      DIM RoboCopy     : Set RoboCopy     = Nothing  
      DIM Switches     : Set Switches     = Nothing  
      DIM RemoteExec   : RemoteExec       = RelativePath & "PSTools\PsExec.exe \\" & OldComputer &_  
                                                        Chr(32) & "-u nash\win2kload -p 2kosload" & Chr(32)  

      REM Initialize Robocopy Variables  
      Switches     = "/e /eta /r:1 /w:0"  
      ExcludeDir   = "/xd LocalService NetworkService *Links* *temp *TEMPOR~1 *cache"  
      ExcludeFiles = "/xf ntuser.* *.exd *.nk2 *.srs extend.dat *cache* *.oab index.* {* *.ost UsrClass.* SharePoint*.pst history* *tmp*"  
      Logs         = "/log:" & LogFolder & "robocopy.log"  
      Parameters   = Chr(32) & Switches & Chr(32) & ExcludeDir & Chr(32) & ExcludeFiles  
      RoboCopy     = RemoteExec & NetworkPath & "PSTools\robocopy.exe " & Chr(34) & "c:\Documents and Settings\" & UserName & Chr(34) &_  
                          Chr(32) & Chr(34) & "\\" & NewComputer & "\c$\Documents and Settings\" & UserName & Chr(34) & Parameters  

      ReturnCode = oShell.Run(RoboCopy, 1, True)  

      REM Local Memory Cleanup  
      Set oShell       = Nothing  
      Set Switches     = Nothing  
      Set ExcludeDir   = Nothing  
      Set ExcludeFiles = Nothing  
      Set Logs         = Nothing  
      Set Parameters   = Nothing  
      Set RemoteExec   = Nothing  
      Set RoboCopy     = Nothing  

 End Sub  
 '*******************************************************************************  
 Sub CopyFilesXP2Win7()  

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

      REM Define Local Variables  
      DIM ExcludeDir   : Set ExcludeDir   = Nothing  
      DIM ExcludeFiles : Set ExcludeFiles = Nothing  
      DIM Logs         : Set Logs         = Nothing  
      DIM Parameters   : Set Parameters   = Nothing  
      DIM RoboCopy     : Set RoboCopy     = Nothing  
      DIM Switches     : Set Switches     = Nothing  
      DIM RemoteExec   : RemoteExec       = RelativePath & "PSTools\PsExec.exe \\" & OldComputer &_  
                                                        Chr(32) & "-u nash\win2kload -p 2kosload" & Chr(32) 
 
      REM Initialize Robocopy Variables  
      Switches     = "/e /eta /r:1 /w:0"  
      ExcludeDir   = "/xd Application* Cookies IETldCache *Links* Local* NetHood NetworkService PrintHood PrivacIE Recent SendTo Start* *temp Templates *TEMPOR~1 Tracing *cache"  
      ExcludeFiles = "/xf ntuser.* ilent* *.exd *.nk2 *.srs extend.dat *cache* *.oab index.* {* *.ost UsrClass.* SharePoint*.pst history* *tmp*"  
      Logs         = "/log:" & LogFolder & "robocopy.log"  
      Parameters   = Chr(32) & Switches & Chr(32) & ExcludeDir & Chr(32) & ExcludeFiles  
      RoboCopy     = RemoteExec & NetworkPath & "PSTools\robocopy.exe " & Chr(34) & "c:\Documents and Settings\" & UserName & Chr(34) &_  
                          Chr(32) & Chr(34) & "\\" & NewComputer & "\c$\users\" & UserName & Chr(34) & Parameters  

      ReturnCode = oShell.Run(RoboCopy, 1, True)  

      REM Local Memory Cleanup  
      Set oShell       = Nothing  
      Set Switches     = Nothing  
      Set ExcludeDir   = Nothing  
      Set ExcludeFiles = Nothing  
      Set Logs         = Nothing  
      Set Parameters   = Nothing  
      Set RemoteExec   = Nothing  
      Set RoboCopy     = Nothing  

 End Sub  
 '*******************************************************************************  
 Sub CopyFilesWin72Win7()  

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

      REM Define Local Variables  
      DIM ExcludeDir   : Set ExcludeDir   = Nothing  
      DIM ExcludeFiles : Set ExcludeFiles = Nothing  
      DIM Logs         : Set Logs         = Nothing  
      DIM Parameters   : Set Parameters   = Nothing  
      DIM RoboCopy     : Set RoboCopy     = Nothing  
      DIM Switches     : Set Switches     = Nothing  
      DIM RemoteExec   : RemoteExec       = RelativePath & "PSTools\PsExec.exe \\" & OldComputer &_  
                                                        Chr(32) & "-u nash\win2kload -p 2kosload" & Chr(32)  

      REM Initialize Robocopy Variables  
      Switches     = "/e /eta /r:1 /w:0"  
      ExcludeDir   = "/xd LocalService NetworkService *Links* *temp *TEMPOR~1 *cache"  
      ExcludeFiles = "/xf ntuser.* *.exd *.nk2 *.srs extend.dat *cache* *.oab index.* {* *.ost UsrClass.* SharePoint*.pst history* *tmp*"  
      Logs         = "/log:" & LogFolder & "robocopy.log"  
      Parameters   = Chr(32) & Switches & Chr(32) & ExcludeDir & Chr(32) & ExcludeFiles  
      RoboCopy     = RemoteExec & NetworkPath & "PSTools\robocopy.exe " & Chr(34) & "c:\users\" & UserName & Chr(34) &_  
                          Chr(32) & Chr(34) & "\\" & NewComputer & "\c$\users\" & UserName & Chr(34) & Parameters  

      ReturnCode = oShell.Run(RoboCopy, 1, True)  

      REM Local Memory Cleanup  
      Set oShell       = Nothing  
      Set Switches     = Nothing  
      Set ExcludeDir   = Nothing  
      Set ExcludeFiles = Nothing  
      Set Logs         = Nothing  
      Set Parameters   = Nothing  
      Set RemoteExec   = Nothing  
      Set RoboCopy     = Nothing  

 End Sub  
 '*******************************************************************************  
 Sub VerifyCopy()  

      If ReturnCode = "0" then  
           MsgBox("The profile, " & UserName & ", on " & OldComputer & " successfully copied to " & NewComputer & ".")  
      Else  
           MsgBox("The profile, " & UserName & ", on " & OldComputer & " failed to copy to " & NewComputer & " due to error " & ReturnCode & ".")  
      End If  

 End Sub  
 '*******************************************************************************  
 Sub GlobalMemoryCleanup()  

      Set NewComputer  = Nothing  
      Set OldComputer  = Nothing  
      Set RelativePath = Nothing  
      Set UserName     = Nothing  

 End Sub  

VBScript Subroutine to Determine the OS and Architecture

This is a simplified procedure I wrote to determine both the OS and the architecture and return a single value showing both (i.e. Windows7x64, XPx86).

NOTE: The variable OS is a global variable and is not defined within this subroutine.


 Sub DetermineOS()  

      REM Define Local Constant  
      CONST strComputer = "."  

      REM Define Local Objects  
      DIM objWMIService : Set objWMIService = GetObject("winmgmts:" _  
           & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
      DIM colOperatingSystems: Set colOperatingSystems = objWMIService.ExecQuery _  
           ("Select * from Win32_OperatingSystem")  
      DIM objOperatingSystem : Set objOperatingSystem = Nothing  
      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  
           OSType = "x86"  
      elseif OSType = "AMD64" then  
           OSType = "x64"  
      end if  
      For Each objOperatingSystem in colOperatingSystems  
           OS = objOperatingSystem.Version  
      Next  
      OS = Trim(OS)  
      OS = Left(OS,3)  
      Select Case OS  
      Case 5.0  
           OS = "XP" & OSType  
      Case 6.0  
           OS = "Vista" & OSType  
      Case 6.1  
           OS = "Windows7" & OSType  
      End Select  

      REM Cleanup Local Variables  
      Set objWMIService       = Nothing  
      Set colOperatingSystems = Nothing  
      Set objOperatingSystem  = Nothing  
      Set OSType              = Nothing  
      Set WshShell            = Nothing  

 End Sub  

07 May 2012

Deploying Autodesk Revit Packages

Autodesk makes it very easy to create installation packages for deploying Revit software. The problem is that when executing these deployment packages through SMS/SCCM or integrating them into a build process, the package returns erroneous data and if it is in a build process, it causes errors because the build proceeds to install the next application when the Autodesk has not completed. This is caused because the setup.exe opens another instance of itself and then closes the original setup.exe, thereby making the deployment server or installation script think the installation is complete, when in essence, it is just beginning the installation.

To get around this, I wrote the following installation VBScript that executes the setup.exe, waits for 5 seconds, which is enough time for the new setup.exe to have appeared and the old one to have closed. That 5 seconds may need to be changed if it is an older machine. At that point, the script waits for the setup.exe process to disappear before it ends so the deployment server receives correct information as to when the deployment is complete.

You can download the script from here.

 '*******************************************************************************  
 '     Program: Install.vbs  
 '      Author: Mick Pletcher  
 '        Date: 08 November 2010  
 '    Modified:  
 '  
 '     Program: Autodesk Revit  
 '     Version: 2012  
 ' Description: This will install Autodesk Revit Structural  
 '                 1) Define the relative installation path  
 '                 2) Create the Log Folder  
 '                 3) Install Current Version of Revit  
 '                 4) Install Workstation Monitor  
 '                 5) Cleanup Global Variables  
 '*******************************************************************************  
 Option Explicit

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

 REM Define Global Variables  
 DIM LogFolder    : Set LogFolder    = Nothing  
 DIM RelativePath : Set RelativePath = Nothing  
 DIM ReturnCode   : ReturnCode       = "0"  

 REM Initialize Global Variables  
 LogFolder = TempFolder & LogFolderName & "\"  

 REM Define the relative installation path  
 DefineRelativePath()  
 REM Create the Log Folder  
 CreateLogFolder()  
 REM Install Current Version  
 InstallCurrentVersion()  
 REM Install Workshare Monitor  
 InstallWorkshareMonitor()  
 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 InstallCurrentVersion()  

      REM Define Local Constants  
      CONST Timeout  = 3000  
      CONST Timepoll = 500  
      CONST FileName = "setup.exe"  

      REM Define Local Objects  
      DIM oShell : Set oShell = CreateObject("Wscript.Shell")  
      DIM SVC    : Set SVC    = GetObject("winmgmts:root\cimv2")  

      REM Define Local Variables  
      DIM sQuery     : sQuery         = "select * from win32_process where name=" & Chr(39) & FileName & Chr(39)  
      DIM cproc      : Set cproc      = Nothing  
      DIM iniproc    : Set iniproc    = Nothing  
      DIM Install    : Set Install    = Nothing  
      DIM Parameters : Set Parameters = Nothing  

      REM Initialize Local Variables  
      Parameters = Chr(32) & "/qb /I" & Chr(32) & RelativePath &_  
                      "AdminImage\RST_64bit.ini"  
      Install    = RelativePath & "AdminImage\" & FileName & Parameters  

      REM Install Autodesk  
      oShell.Run Install, 1, True  
      REM Wait until Second Setup.exe closes  
      Wscript.Sleep 5000  
      Set cproc = svc.execquery(sQuery)  
      iniproc = cproc.count  
      Do While iniproc = 1  
           wscript.sleep 5000  
           set svc=getobject("winmgmts:root\cimv2")  
           sQuery = "select * from win32_process where name=" & Chr(39) & FileName & Chr(39)  
           set cproc=svc.execquery(sQuery)  
           iniproc=cproc.count  
      Loop  

      REM Cleanup Local Variables  
      Set cproc      = Nothing  
      Set iniproc    = Nothing  
      Set Install    = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  
      Set sQuery     = Nothing  
      set svc        = Nothing  

 End Sub  

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

 Sub InstallWorkshareMonitor()  

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

      REM Define Local Variables  
      DIM MSI        : MSI        = Chr(32) & "workshare_monitor\worksharingmonitorforautodeskrevit2012_20110316_1624.msi"  
      DIM Log        : Log        = "WorkshareMonitor.log"  
      DIM Logs       : Logs       = Chr(32) & "/lvx" & Chr(32) & LogFolder & Log  
      DIM Parameters : Parameters = Chr(32) & "/qn /norestart"  
      DIM Install    : Install    = "msiexec.exe /i" & MSI & Logs & Parameters  

      oShell.Run Install, 1, True  

      REM Cleanup Local Variables  
      Set Install    = Nothing  
      Set Log        = Nothing  
      Set Logs       = Nothing  
      Set MSI        = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  

 End Sub  

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

 Sub GlobalVariableCleanup()  

      Set LogFolder    = Nothing  
      Set RelativePath = Nothing  
      Set ReturnCode   = Nothing  

 End Sub  

02 May 2012

VBScript Software Installation

With as often as I deploy software, I created a standard VBScript template to use when needing to create an unattended application installation. One thing that I do not have in this script is and uninstall procedure, which I usually do when deploying software, as to uninstall the older version before installing the newer. I do not depend on the application installation to take care of the uninstall of older versions because I have run across too many apps in the past that did not properly uninstall before starting the new install.

So in this script, the parts you will need to modify are the global variable LogFolderName to be the name of the folder you wish for placing the log file at. The TempFolder constant may also need to be changed if you do not wish for the log file folder to be under c:\temp.

If this is a simple MSI installer, I have already completed most of the script for deploying the MSI. The only part that might need to be inserted is if there is a transform file.

You can download the script from here.

 '*******************************************************************************  
 '     Program: Install.vbs  
 '      Author: 
 '        Date: 
 '    Modified: 
 '  
 '     Program: 
 '     Version: 
 ' Description: This will install   
 '                 1) Define the relative installation path  
 '                 2) Create the Log Folder  
 '                 *) Install   
 '                 *) Cleanup Global Variables  
 '*******************************************************************************  
 Option Explicit  

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

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

 REM Define the relative installation path  
 DefineRelativePath()  
 REM Create the Log Folder  
 CreateLogFolder()  
 REM Install   
 Install  
 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 Install()  
      REM Define Local Objects  
      DIM oShell : SET oShell = CreateObject("Wscript.Shell") 
 
      REM Define Local Variables  
      DIM MSI        : MSI        = Chr(32) & RelativePath & ".msi"  
      DIM Logs       : Logs       = Chr(32) & "/lvx" & Chr(32) & LogFolder & ""  
      DIM Parameters : Parameters = Chr(32) & "/qb- /norestart"  
      DIM Transforms : Transforms = Chr(32) & "Transforms=" & RelativePath & ""
      DIM Install    : Install    = "msiexec.exe /i" & MSI & Logs & Parameters  

      oShell.Run Install, 1, True  

      REM Cleanup Local Variables  
      Set Install    = Nothing  
      Set Logs       = Nothing  
      Set MSI        = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  
      Set Transforms = Nothing
 End Sub  

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

 Sub GlobalVariableCleanup()  
      Set LogFolder    = Nothing  
      Set RelativePath = Nothing  
 End Sub  

Why I use ANSI values for certain characters in VBscripts

Some people think it is weird that I use the ANSI values in all of my VBScripts, but there is a good reason for it. There have been times when code that I have written needed to be debugged. The error was hard to find in the code, especially when it came down to a space. After several times of this, I changed to specifying spaces with their ANSI value so that it is easy to identify them.

I also extended the use of ANSI values to other characters such as the quotation mark, as such that when defining a string variable and a quotation mark is needed with the string, it is not possible to use a quotation mark because of the necessary ones at that beginning and end.

Another character I use ANSI for is the carriage return, as it is not possible to do otherwise. My suggestion is to always keep a printed ANSI table on your desk as a reference while coding. When you go back and debug code in such instances, you will be glad that you did this!

01 May 2012

List all systems that are logged off

I wrote this script in 2010 to be able to give me a list of systems that are currently logged off from a list of computers in a text file. My purpose for this was to be able to find systems to test software deployments on in which a user was not logged on. There are two text files, one it reads from for the list of computers to scan, and the second file to output who is logged onto that computer. If no one is logged on, then it is blank beside the computer name. At the end, it pops up a status message saying query is complete. During the scan, there is an IE window that pops up and gives a percentage status as to how much has completed.

You can download the script from here.

 REM ***************************************************************************  
 REM ***   Program: User Logged On.vbs  
 REM ***   Author: Mick Pletcher  
 REM ***   Created: 10 January 2010  
 REM ***   Edited:  
 REM ***  
 REM *** Description:   
 REM ***  
 REM ***************************************************************************  
 On Error Resume Next

 REM Define Global Constants  
 CONST ForReading = 1  
 CONST InputFile  = "<LOCATION>\WorkStations.txt"  
 CONST OutputFile = "<LOCATION>\output.txt"

 REM Define Global Objects  
 DIM objFSO      : Set objFSO      = CreateObject("Scripting.FileSystemObject")  
 DIM objTextFile : Set objTextFile = objFSO.OpenTextFile(InputFile, ForReading)  
 DIM objIE       : Set objIE       = CreateObject("InternetExplorer.Application")  
 DIM WshShell    : Set WshShell    = WScript.CreateObject("WScript.Shell")

 REM Define Global Variables       
 DIM arrComputers  : Set arrComputers  = Nothing  
 DIM Count         : Set Count         = Nothing  
 DIM objOutput     : Set objOutput     = Nothing  
 DIM objWMIService : Set objWMIService = Nothing  
 DIM strComputer   : Set strComputer   = Nothing  
 DIM strText       : strText           = objTextFile.ReadAll  
 DIM X             : Set X             = 1  
 DIM Total         : Set Total         = 0  
 DIM PrevTotal     : Set PrevTotal     = Nothing  

 CreateDisplayWindow()  
 objIE.Document.WriteLn "Scanning Systems..." & "<BR>"  
 objIE.Document.Write Total & "% complete" & "<BR>"  
 objTextFile.Close  
 arrComputers = Split(strText, VbCrLf)  
 Count = UBound(arrComputers)  
 Set objOutput = objFSO.CreateTextFile(OutputFile)  
 Set objOutput = objFSO.OpenTextFile  
 For Each strComputer In arrComputers  
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")  
      Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)  
      For Each objItem in colItems  
           If IsNull(objItem.UserName) then  
                objOutput.WriteLine( strComputer & ": ")            
           else  
                objOutput.WriteLine( strComputer & ": " & objItem.UserName )  
     End IF  
   Next  
      Total = (X / Count) * 100  
      Total = Int(Total)  
      If NOT Total = PrevTotal then  
           CreateDisplayWindow()  
           objIE.Document.WriteLn "Scanning Systems..." & "<BR>"  
           objIE.Document.Write Total & "% complete" & "<BR>"  
      End If  
      PrevTotal = Total  
      X = X + 1  
 Next  
 objOutput.Close  
 Wscript.Echo " Query is complete"

 REM Cleanup Global Variables  
 Set Count         = Nothing  
 Set objFSO        = Nothing  
 Set objTextFile   = Nothing  
 Set arrComputers  = Nothing  
 Set objOutput     = Nothing  
 Set objWMIService = Nothing  
 Set strComputer   = Nothing  
 Set strText       = Nothing  

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

 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 = 500  
      DIM intHeight       : intHeight = 300  
      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.Document.Title = "Users Logged On"  
      objIE.Toolbar  = 0  
      objIE.StatusBar = 0  
      objIE.AddressBar = 0  
      objIE.MenuBar  = 0  
      objIE.Resizable = 0  
      objIE.Width   = 100  
      objIE.Height   = 100  
      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  

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