;Paul Hughes' AutoIT Office cache script created for Computer Weekly ;Script to cache Office with Disk Space check and logging $OfficeCached = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeCached") If $OfficeCached = "NoDiskSpace" Then Exit EndIf ;Variables to use for the scripts $Officefilelocation = "\\" & $CMDLINE[1] $username = "YourAministratorUsernamehere" $password = "YourPasswordhere" $file = FileOpen(@MyDocumentsDir & "\OfficeInstall.txt", 1) $diskfree = DriveSpaceFree("c:\") ; Check if file opened for writing OK If $file = -1 Then MsgBox(4096, "Error", "Unable to open LogFile for writing, No logging will occur in OfficeInstall.txt located under My Documents", 10) EndIf ;Now comes the part where we check the user's C:\ Drive space to see if we have room to work with $OfficeCached = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeCached") ;the check here will see if the avaliable MB on the C:\ Drive is less than 4000 and if the OfficeCached variable is not showing as nodiskspace already, ;then it should flag this up to the user as a problem. if $diskfree < 4000 and $OfficeCached <> "NoDiskSpace" Then MsgBox(4096, "Low Disk Space","You do not have enough diskspace, Office Install will not proceed",10) ;Now in order to know who didn;t have enough disk space here, we can either write to a text file using AutoIT or as per this example, call another kix script ;which can be written in a way that writes to a csv detailing information about the user and the computer that didn't have the required disk space. ;The choice is yours as they say! RunWait("\\Server\netlogon\KIX32.exe \\Server\OfficeRollout$\NoDiskSpace.kix") RunAsWait($username, "YourDomainNamehere", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v OfficeCached /t REG_SZ /d "NoDiskSpace" /f') Exit EndIf $OfficeCached = RegRead("HKEY_LOCAL_MACHINE\Software\Office2007InstallForMyCompany\OfficeRollout", "OfficeCached") if $OfficeCached <> "Yes" Then ;This will run the Office Cache exe dependent of the location from the command line parameter RunAsWait($username, "YOURDOMAINNAMEHERE", $password, 0, $Officefilelocation & "\Office2007$\setup.exe /config " & $officefilelocation & "\Office2007$\configs\liscache.xml") if @error = 0 Then ;The start of using RUNASWAIT to write to an area of the registry that normal users cannot RunAsWait($username, "YourDomainNamehere", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v OfficeCached /t REG_SZ /d "Yes" /f') ;We also write to our local logging text file FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " - Office 2007 Cached OK" & @CRLF) Else ;We want a message Box to appear telling the user something is wrong here MsgBox(4096,"Office Cache Issue", "There was an issue caching Office on your machine, Please contact Local IT Support") FileWriteLine($file, @MDAY & "-" & @MON & "-" & @YEAR & "-" & @HOUR & ":" & @MIN & " - Office 2007 Cache did not complete. Check machine." & @CRLF) RunAsWait($username, "YourDomainNamehere", $password, 0, 'C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Office2007InstallForMyCompany\OfficeRollout /v OfficeCached /t REG_SZ /d "No" /f') EndIf EndIf FileClose($file)