Thursday, September 1, 2011

Patching Civil 3D 2011 - Part 3, The Final Chapter

I sort of promised a "part 3" and here it is. I was toying around with using a .CMD script, but decided to go with a VBscript solution instead.  Dovetailing with my Package Scripting 101 blog post somewhat, this should provide a brief example of just one rationale for choosing an approach to a problem constraint.  In this case, the constraint was how "best" to detect if the (a) base product is installed, and (b) the updates are already installed.

The best criteria for my needs is/was to check for a specific Registry key/value.  My preference is to go with using the RegRead() method of the Wscript.Shell object, rather than the clunky REG Query test and fetching the %errorlevel% result, so I chose VBscript.

[code]
'**************************************************************** ' Filename..: install_updates.vbs ' Author....: skatterbrainz ' Date......: 09/01/2011 ' Purpose...: install updates 1 and 2 for AutoCAD Civil 3D 2011 '**************************************************************** appName = "AutoCAD_Civil3D_2011_Update2" Set objShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") strTemp = Env("TEMP") progFiles = Env("PROGRAMFILES") scriptPath = Replace(wscript.ScriptFullName, "\" & wscript.ScriptName, "") strLog = strTemp & "\CVB_" & appName & "_install.log" Set objLogFile = objFSO.CreateTextFile(strLog, True) '---------------------------------------------------------------- echo "installing... " & appName echo "source....... " & scriptPath echo "target....... " & Env("COMPUTERNAME") echo "windir....... " & Env("WINDIR") echo "progfiles.... " & progFiles echo "temp......... " & strTemp echo "logfile...... " & strLog echo "-----------------------------------------------" echo "info: searching for civil 3d 2011 installation..."
appPath = progFiles & "\Autodesk\AutoCAD Civil 3D 2011\acad.exe"
If objFSO.FileExists(appPath) Then echo "info: checking for installed updates... " key = "HKLM\Software\Microsoft\Windows\CurrentVersion" & _
"\Uninstall\AutoCAD Civil 3D 2011 Version 3\DisplayName" On Error Resume Next result = objShell.RegRead(key) If err.Number = 0 Then echo "info: updates are already installed (abort)" wscript.quit(0) Else update1 = scriptPath & "\c3d2011_win32_sp1.msp" update2 = scriptPath & "\c3d2011_win32_sp2.msp" command1 = "msiexec /p " & chr(34) & update1 & chr(34) & " /quiet /norestart" command2 = "msiexec /p " & chr(34) & update2 & chr(34) & " /quiet /norestart" result = 0 echo "info: updates not installed. installing now..." echo "info: command = " & command1 result = objShell.Run(command1, 7, True) echo "info: exit code is " & result echo "info: command = " & command2 result = objShell.Run(command2, 7, True) echo "info: exit code is " & result If result = 0 Then echo "info: restarting computer in 30 seconds" x = objShell.Run("shutdown /r /f /t 30", 7, True) End If End If Else echo "info: civil 3d 2011 installation not found." End If echo "-----------------------------------------------" echo "completed / exit code: " & result objLogFile.Close wscript.quit(result) Sub echo (strMsg) Dim ln ln = FormatDateTime(Now, vbShortDate) & " " & _ FormatDateTime(Now, vbLongTime) & " " & strMsg objLogFile.WriteLine(ln) End Sub Function Env(varName) Env = objShell.ExpandEnvironmentStrings("%" & varName & "%") End Function [/code]

Log output...

[code]
9/1/2011 1:42:07 PM installing... AutoCAD_Civil3D_2011_Update2 9/1/2011 1:42:07 PM source....... \\Server1\source$\Apps\Adsk\C3D2011_Updates 9/1/2011 1:42:07 PM target....... Computer1234 9/1/2011 1:42:07 PM windir....... C:\WINDOWS 9/1/2011 1:42:07 PM progfiles.... C:\Program Files 9/1/2011 1:42:07 PM temp......... C:\DOCUME~1\dstein\LOCALS~1\Temp 9/1/2011 1:42:07 PM logfile...... C:\DOCUME~1\dstein\LOCALS~1\Temp\ACAD_Civil3D_2011_Update2_install.log 9/1/2011 1:42:07 PM ----------------------------------------------- 9/1/2011 1:42:07 PM info: searching for civil 3d 2011 installation... 9/1/2011 1:42:07 PM info: checking for installed updates... 9/1/2011 1:42:07 PM info: updates not installed. installing now... 9/1/2011 1:42:07 PM info: command = msiexec /p "\\server1\source$\Apps\Adsk\C3D2011_Updates\c3d2011_win32_sp1.msp" /quiet /norestart 9/1/2011 1:46:40 PM info: exit code is 0 9/1/2011 1:46:40 PM info: command = msiexec /p "\\server1\source$\Apps\Adsk\C3D2011_Updates\c3d2011_win32_sp2.msp" /quiet /norestart 9/1/2011 1:48:40 PM info: exit code is 0 9/1/2011 1:48:40 PM info: restarting computer in 30 seconds 9/1/2011 1:48:40 PM ----------------------------------------------- 9/1/2011 1:48:40 PM completed / exit code: 0
[/code] 

Conclusion

As I always say: This is not the only solution.  This is simply ONE possible approach that works for me, and may work for you.  Maybe not.  If this helps you, great.  If not, eh.

If you're in the same situation I'm in: Existing installations needing to be patched - you should also make sure to patch your administrative deployment share (aka "Network Deployment").  I would download both .exe files, extract the .msp files from them, and import them into the Deployment utility to add them into the deployment image.  That way your future installations will have the updates included.

No comments: