Remote install of Windows components

Author Message
protofj

  • Total Posts : 12
  • Scores: 0
  • Reward points : 0
  • Joined: 10/31/2005
  • Status: offline
Remote install of Windows components Monday, October 31, 2005 4:49 AM (permalink)
0
New to the forum so to start off an a good footing......

This one took me ages to get right - It installs MSMQ on a specified list of remote machines, It could be used to install any windows component remotely.
It also logs the process and copies the MSMQ install log locally for reference.

  ' ===============================================
  ' #### Script to install MSMQ on remote PC's ####
  ' #### D Flint-Johnson Oct 2005 ####
  ' #### ver 1.0 ####
  '
  ' #### This version reads a name from a list of machines from a pre-prepared inf file ####
  ' #### tests if MSMQ is already installed and if not installs it ####
  ' #### it then outputs results to a text file c:\msmqinst\msmqinst.log ####
  ' #### and loops to the next machine in the list ####
  ' 
  ' #### NOTE - relies on machinelist.inf and msmqinst.vbs being present in c:\msmqinst\ ####
  ' ===============================================
  
  
  
  on Error resume Next
  installYN = "No"
  Const HKEY_LOCAL_MACHINE = &H80000002
  
  
  ' ### open streams to input file and create ouput file
  
  Set objShell = WScript.CreateObject("WScript.Shell")
  Set ObjFSO = CreateObject("Scripting.FileSystemObject")
  Set OutputStream = objFSO.CreateTextFile("C:\msmqinst\msmqinst.log", True)
  Set InputStream = objFSO.OpenTextFile("c:\msmqinst\machinelist.inf", 1)
  
  ' ### connect to remote PC and test if OS is windows XP
  ' ### also test for absence of c:\windows\system32\msmq\
  ' ### if both are true then write name to log file and continue
  ' ### else get next PC from text file
  
  
  ' ### read PC name
  
  Do Until inputStream.AtEndOfStream
      Err.Clear
      StrRemoteComputer = inputStream.ReadLine
  
  ' ### write name to log
  
  outputStream.Write (strRemoteComputer & " ; ")
  
  ' ### test OS
  
      Set objSWbemServices = GetObject("winmgmts:\\" & strRemoteComputer)
      
      If Err <> 0 Then
          outputStream.WriteLine "Error connecting to computer" & " ; " & Err.Number & " ; " & Err.Description & " ; "
          installYN = "No"
          Err.clear
      Else
      
      Set colOperatingSystems = objSWbemServices.InstancesOf("Win32_OperatingSystem")
      For Each objOperatingSystem In colOperatingSystems
          if objOperatingSystem.Caption = "Microsoft Windows XP Professional" or objOperatingSystem.Caption = "Microsoft(R) Windows(R) XP Professional x64 Edition" Then
              installYN = "Yes"
              outputStream.Write "Windows XP found ; "
              
          ' ### test for folder
              
              Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\cimv2")
              Set colFolders = objWMIService.ExecQuery ("SELECT * FROM Win32_Directory WHERE Name = 'c:\\windows\\system32\\msmq\\storage'")
              
                  If colFolders.Count = 1 Then    
                      installYN = "No"
                      outputStream.WriteLine "MSMQ installation found. "
                  Else
                      outputStream.Write "MSMQ installation NOT found ; "
                  
                  End if
           ' ### carry on            
              
          Else 
              installYN = "No"
              outputStream.WriteLine "Windows XP NOT found."
          End if
      
      Next
      
      End if
      
      if installYN = "Yes" Then 
  
      
  
  ' #### Run Installl ####
  
  ' ### copy msmqinst.inf file to remote PC's C:\
  
          objFSO.CopyFile "C:\msmqinst\msmqinst.inf" , "\\" & strRemoteComputer & "\c$\" , True
          Wscript.Sleep 10000
          OutputStream.Write "Inf file copied to remote PC ; "
          
  ' ### connect to remote PC
  
          Set objWMIService1 = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\cimv2:Win32_Process")
          
  ' ### run script remotely
          
          errReturn = objWMIService1.Create("sysocmgr.exe /i:c:\windows\inf\sysoc.inf /q /u:c:\msmqinst.inf", null, null, intProcessID)
          
  ' ### report errors/success to log        
          
          If errReturn = 0 Then
              OutputStream.Write "MSMQ installation was started successfully ; " 
          Else
              OutputStream.Write "process could not be started due to error ; " & errReturn
          End If
          
  ' ### Check if remote process is still running if not then test for presence of c:\windows\msmq\storage folder        
          
          Set objWMIService2 = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\cimv2")
          For i = 1 to 30
              Set colProcesses = objWMIService2.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'sysocmgr.exe'")
                      If colProcesses.Count <> 0 Then
                      wscript.sleep 10000
                      intCount = intCount + 1    
                  End If
              Next
                      
              If intCount = 30 Then 
                  OutputStream.Write "Installation wait timed out ; "
              End If
                  
          
          Set colFolders = objWMIService.ExecQuery ("SELECT * FROM Win32_Directory WHERE Name = 'c:\\windows\\system32\\msmq\\storage'")
              If colFolders.Count = 1 Then    
                  installYN = "No"
                  outputStream.Write "MSMQ installation Succeeded ; "
              Else
                  outputStream.Write "MSMQ installation Failed ; "    
              End if
          
          Set intCount = 0
  
  ' ### Delete msmqinst.inf from c:\ on remote PC        
          
          objFSO.DeleteFile ("\\" & strRemoteComputer & "\c$\msmqinst.inf")
          OutputStream.Write "Local machine log directory created ; "
          
  ' ### Copy c:\windows\msmqinst.log (on remote PC) to c:\msmqinst\machine_name\msmqinst.log
  
          Set objFolder = objFSO.CreateFolder("C:\msmqinst\" & strRemoteComputer)
          objFSO.CopyFile "\\" & strRemoteComputer & "\c$\windows\msmqinst.log" , "C:\msmqinst\" & strRemoteComputer & "\" , True
          OutputStream.Write "Remote MQMS install log copied locally ; "
          
  ' ### complete log file entry line
      
      OutputStream.WriteLine "."
      
          
      End if
      
  Loop
  
  ' ### complete and close log files
  
  OutputStream.WriteLine " "
  OutputStream.WriteLine "Script completed at: " & Now
  inputStream.Close    
  OutputStream.Close
  
  ' ### alert that script is complete
  
  Wscript.Echo "MSMQ installations complete"
  
  
  '========================================================
  

 
#1
    protofj

    • Total Posts : 12
    • Scores: 0
    • Reward points : 0
    • Joined: 10/31/2005
    • Status: offline
    RE: Remote install of Windows components Wednesday, December 21, 2005 9:25 PM (permalink)
    0
    Apologies - I failed to post the contents of the msmqinst.inf file used in this script:

     [Version]  
      
     Signature = "$Windows NT$"  
      
     [Global]  
      
     FreshMode = Custom  
      
     MaintenanceMode = RemoveAll  
      
     UpgradeMode = UpgradeOnly  
      
     [Components]  
      
     msmq = on
     msmq_Common = on
     msmq_Core = on
     msmq_TriggersService = on
     msmq_HTTPSupport = off
     msmq_LocalStorage = on 
     msmq_ADIntegrated = off
     
     [Msmq]  
     
      
     ControllerServer=  
      
     SupportingServer=  
      
     ServerAuthenticationOnly=  
      
     Site=
     
     
     


    machinelist.inf is just a list of machine names with one machine per line
    <message edited by protofj on Wednesday, December 21, 2005 9:30 PM>
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

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

      2000-2012 ASPPlayground.NET Forum Version 3.9