;Paul Hughes' AutoIT Office Install script created for Computer Weekly ;Script to install Office with logging and reg writing $OfficeCached = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeCached") If $OfficeCached = "NoDiskSpace" Then Exit EndIf ;Variables for the script are listed here $Officefilelocation = "\\" & $CMDLINE[1] $username = "YourAdministratorUsernameHere" $password = "YourPasswordHere" $DoNotProceed = "Proceed" $file = FileOpen(@MyDocumentsDir & "\OfficeInstall.txt", 1) ; Check if log file opened for writing OK If $file = -1 Then MsgBox(4096, "Error", "Unable to open LogFile for writing, No logging will occur in Office2007InstallForMyCompanyOfficeInstall.txt located under My Documents", 10) EndIf ; Message to inform users Office Install is about to begin ; This also checks for the existance of a key called "HadMessage" which means that the user has had a successful install in the past. $OfficeMessage = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "HadMessage") if $OfficeMessage <> "Yes" Then ; Now we tell the user the install is going to start in a few moments. MsgBox(4096, "Office 2007 Installation", "We are now beginning the process of installing Office 2007 with components on your machine. This will take some time to complete.",15) Else ;We want the exe to end rather than go through the rest when it doesn't need to if the user had a good install before Exit endif ;Check for Office Existance after install, this is in case the installation caused a reboot of the workstation and there wasn't enough time to write to the registry $OfficeAlready = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeInstalled") if FileExists(@ProgramFilesDir & "\Microsoft Office\Office12\WinWord.exe") and $OfficeAlready <> "Yes" Then RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v OfficeInstalled /t REG_SZ /d "Yes" /f') MsgBox(4096,"Office 2007 detected","Office 2007 was detected on the machine already, will not rerun the install",10) EndIf ;The big moment of installing the Office Suite comes here ;First, the check for the required registry entries, the OfficeCached should be yes, and the OfficeInstalled should be no for this to go forward $OfficeCached = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeCached") $OfficeInstalled = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeInstalled") if $OfficeCached = "Yes" And $OfficeInstalled <> "Yes" Then ;This will run the Office Installer dependent of the location MsgBox(4096, "Installing Office", "Your machine may reboot during this part of the process, this is normal behaviour.", 10) RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, "C:\MSOCache\All Users\{90120000-0012-0000-0000-0000000FF1CE}-C\setup.exe /adminfile " & $Officefilelocation & "\Office2007$\Configs\installforOffice2007InstallForMyCompany.msp /config " & $officefilelocation & "\Office2007$\configs\lisinstall.xml") if @error = 0 Then RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v OfficeInstalled /t REG_SZ /d "Yes" /f') FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - Office 2007 Installed OK" & @CRLF) Else ;We want a message Box to appear telling the user something is wrong here MsgBox(0, "errorcode", @error) MsgBox(4096,"Office Cache Issue", "There was an issue installing Office on your machine, Please contact Local IT Support") RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v OfficeInstalled /t REG_SZ /d "No" /f') FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - There was an issue with the Office Install. Check Event Logs and Computer to ensure all is well." & @CRLF) ;The Donotproceed variable will be changed to ensure no other products get installed $DoNotProceed = "Yes" EndIf EndIf ;Here we begin the addtional component installations, starting with the Web Components $Web = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "WebComponentsInstalled") $OfficeInstalled = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeInstalled") ;Notice here, that the DoNotProceed Variable comes into play to make sure Office 2007 is present before it does run the installer if ($Web <> "Yes" and $OfficeInstalled = "Yes" and $DoNotProceed <> "Yes") Then ;This will run the Office Cache exe dependent of the location given from the command line parameter MsgBox(4096, "Installing OWC11", "Installing Office 2003 Web Components...", 10) RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, $Officefilelocation & "\Office2007$\Web\owc11.exe /quiet") if @error = 0 Then RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v WebComponentsInstalled /t REG_SZ /d "Yes" /f') FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - Office 2003 Web Components Installed OK" & @CRLF) Else ;We want a message Box to appear telling the user something is wrong here MsgBox(4096,"Office Web Components Issue", "There was an issue installing Office 2003 Web Components on your machine, Please contact Local IT Support") RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v WebComponentsInstalled /t REG_SZ /d "No" /f') FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - There was an issue with the Web Components Install. Check Event Logs and Computer to ensure all is well." & @CRLF) EndIf EndIf ;Here we begin the Office XPS / PDF Add-in install $OfficeInstalled = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeInstalled") $XPSPDF = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "XPSPDFInstalled") if ($XPSPDF <> "Yes" and $OfficeInstalled = "Yes" and $DoNotProceed <> "Yes") Then ;This will run the Office Save as exe dependent on the location from the command line parameter MsgBox(4096, "Installing XPS/PDF Add-on", "Installing XPS/PDF Save as Add-on...", 10) RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, $Officefilelocation & "\Office2007$\XPSPDF\SaveAsPDFandXPS.exe /quiet") if @error = 0 Then RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v XPSPDFInstalled /t REG_SZ /d "Yes" /f') FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - XPS/PDF YourDomainNamehered-on Installed OK" & @CRLF) Else ;We want a message Box to appear telling the user something is wrong here MsgBox(4096,"Office Web Components Issue", "There was an issue installing Office 2003 Web Components on your machine, Please contact Local IT Support") RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v XPSPDFInstalled /t REG_SZ /d "No" /f') FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - There was an issue with the PDF/XPS ADD-on Install. Check Event Logs and Computer to ensure all is well." & @CRLF) EndIf EndIf ; .net frameworks installer ; We don't have the DoNotProceed variable here as we want .net to be installed regardless. This of course can be changed ;This registry entry comes from technet, therefore should be standard for this version of .Net 3.5Sp1 $netinstalled = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5","Version") if $netinstalled <> "3.5.30729.01" then ;This will run the .net frameworks installer dependent on the location from the command line parameter MsgBox(0,".net Install Notice", "Your Keyboard and mouse will be disabled during the Install of .Net Frameworks 3.5 SP1 and re-enabled after the install has completed.", 10) ;We are disabling the mouse and keyboard here as .net will provide the user with the cancel button and if possible we want to avoid them pressing it BlockInput(1) RunAsWait($userName, "YOURDOMAINNAMEHERE" , $password, 0, $Officefilelocation & "\Office2007$\.net3.5sp1\dotnetfx35.exe /qb /norestart","C:\") if @error = 0 Then ;All is well, we will not create an extra key here as the above registry key should be present and ;used for checks to ensure .net frameworks is present for other scripts. ;Input for the user is re-enabled here BlockInput(0) FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - .net frameworks 3.5 SP1 Install completed OK" & @CRLF) Else ;Input for the user is re-enabled here BlockInput(0) MsgBox(4096, ".Net Framework Failure", "There was an issue installing .net frameworks 3.5 SP1 on your machine. Contact local IT Support.") FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - There was an issue with .net frameworks 3.5 SP1 Install. Check Event Logs and Computer to ensure all is well." & @CRLF) EndIf EndIf ; Here we are checking for the existance of .Net frameworks and the Visual Studio Tools $netinstalled = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5","Version") $VSTOinstalled = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "VSTOInstalled") if $netinstalled = "3.5.30729.01" and $VSTOinstalled <> "Yes" then MsgBox(0,"Visual Studio Runtime", "Installing Visual Studio Runtime", 10) ;This will run the Visual Studio Runtime installer dependent on the location from the command line parameter RunAsWait($userName, "YOURDOMAINNAMEHERE" , $password, 0, $Officefilelocation & "\office2007$\VSTO\vstor30.exe /q","C:\") if @error = 0 Then FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - Visual Studio Runtime Install completed OK" & @CRLF) RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v VSTOInstalled /t REG_SZ /d "Yes" /f') Else MsgBox(4096, ".Net Framework Failure", "There was an issue installing Visual Studio Runtime on your computer. Contact local IT Support.") FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - There was an issue with Visual Studio Runtime Install. Check Event Logs and Computer to ensure all is well." & @CRLF) RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v VSTOInstalled /t REG_SZ /d "No" /f') EndIf EndIf ; This Part checks that the required Registry Keys exist and if all is well the user will recieve a message saying so. $netinstalled = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5","Version") $VSTOinstalled = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "VSTOInstalled") $XPSPDF = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "XPSPDFInstalled") $OfficeMessage = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "HadMessage") $OfficeInstalled = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeInstalled") if ($netinstalled = "3.5.30729.01" and $XPSPDF = "Yes" and $OfficeInstalled = "Yes" and $OfficeMessage <> "Yes") Then ;Add the "HadMessage" registry key so from here on out, no users get any prompts from the exe when it is ran again. RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v HadMessage /t REG_SZ /d "Yes" /f') MsgBox(4096, "Office Main Install Complete", "The Main Office Components are installed, continuing with normal KIX script",6) Else ;This MSGBox will stay until the user looks at it and closes the window, to ensure they know not all went to plan MsgBox(4096, "Office Main Install did not complete", "Not all the Main Office Components are installed, Please contact IT Support") EndIf ;Close the logging text file opened earlier FileClose($file)