The VBScript sample from Microsoft was a start, but here were the major limitations:
- Only meant to be used from within the “Scripts” folder, which is not useful when attempting to install applications.
- Does not include examples of actually using the ZTIUtility.vbs functions.
Template pulled from http://gallery.technet.microsoft.com/scriptcenter/84d18835-300a-42e3-b0e7-29cb7fc5aafc.
* Thanks Mr. Barnes!
GitHub Link: https://github.com/brianfgonzalez/Scripts/blob/master/Z-MyMDTTemplate.wsf
<job id="Z-Sample"> <script language="VBScript" src="..\..\Scripts\ZTIUtility.vbs"/> <script language="VBScript"> ' //*************************************************************************** ' // ***** Script Header ***** ' // ' // Solution: Solution Accelerator for Microsoft Deployment ' // File: Z-MyMDTTemplate.wsf ' // ' // Purpose: Template ' // ' // Usage: cscript Z-MyMDTTemplate.wsf [/debug:true] ' // ' // Customer Build Version: 1.0.0 ' // Customer History: ' // ' // ***** End Header ***** ' //*************************************************************************** '//---------------------------------------------------------------------------- '// '// Global constant and variable declarations '// '//---------------------------------------------------------------------------- Option Explicit Dim iRetVal '//---------------------------------------------------------------------------- '// End declarations '//---------------------------------------------------------------------------- '//---------------------------------------------------------------------------- '// Main routine '//---------------------------------------------------------------------------- On Error Resume Next iRetVal = ZTIProcess ProcessResults iRetVal On Error Goto 0 '//--------------------------------------------------------------------------- '// '// Function: ZTIProcess() '// '// Input: None '// '// Return: Success - 0 '// Failure - non-zero '// '// Purpose: Perform main ZTI processing '// '//--------------------------------------------------------------------------- Function ZTIProcess() iRetVal = Success ZTIProcess = iRetval '!!!!!!!!!!! INSERT YOUR CODE HERE !!!!!!!!!!!! 'Set a variable example 'oEnvironment.Item("OSDComputerName") = "PC-01" 'Read a variable example 'If oEnvironment.Exists("_SMSTSORGNAME") then ' Wscript.Echo "The Property Value = " & oEnvironment.Item("_SMSTSORGNAME") 'Else ' Wscript.Echo "The Property Value is not set!" 'End if 'Check if a variable is Null or Empty 'If oEnvironment.isNullOrEmpty("_SMSTSORGNAME") then ' Wscript.Echo "The Property Value = " & oEnvironment.Item("_SMSTSORGNAME") 'Else ' Wscript.Echo "The Property Value is not set!" 'End if 'Other oEnvironment methods 'oEnvironment.Substitute(sVal) 'Given a string, will expand any variables and/or functions within that string. 'oEnvironment.ListItem(sName) 'Read/Write a variable of type array to a persistent store. 'Create a Log file with the name of the script file in the MININT\SMSOSD\OSDLOGS\ directory. 'oLogging.CreateEntry "Logging: Beginning logging process", LogTypeInfo 'wscript.echo "Hello world" 'oLogging.CreateEntry "This is an Information Log Entry", LogTypeInfo 'oLogging.CreateEntry "This is a Warning Log Entry", LogTypeWarning 'oLogging.CreateEntry "This is an Error Log Entry", LogTypeError 'oLogging.CreateEntry "Logging: End logging process", LogTypeInfo 'oLogging.ReportFailure (sMessage,iError) 'Used to perform a structured exit if an unrecoverable error is detected. 'oLogging.CreateEvent(iEventID, iType, sMessage, arrParms) 'Write a message to the log file, and post the event to a defined server. 'Delete a file 'Dim sTargetFile 'sTargetFile = "C:\test.txt" 'oFileHandling.DeleteFile sTargetFile 'Move a file 'Dim sFile, sDest 'sFile = "C:\Folder1\test.txt" 'sDest = "C:\Folder2\" 'oFileHandling.MoveFile sFile, sDest 'Copy a file 'Dim sFile, sDest, bOverwrite 'sFile = "C:\Folder1\test.txt" 'sDest = "C:\Folder2\" 'bOverwrite = True 'oFileHandling.CopyFile sFile, sDest, bOverwrite 'Copy a folder 'Dim sSource, sDest, bOverwrite 'sSource = "C:\Folder1" 'sDest = "C:\Folder2" 'bOverwrite = True 'oFileHandling.CopyFolder sSource, sDest, bOverwrite 'Move a folder 'Dim sSource, sDest 'sSource = "C:\Folder1" 'sDest = "C:\Folder2\" 'oFileHandling.MoveFolder sSource, sDest 'Delete a folder incl. sub-folders 'Dim sPath 'sPath = "C:\Folder1" 'oFileHandling.RemoveFolder sPath 'Read a registry key 'Dim sRegValue, sRegKey 'sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version" 'sRegValue=oUtility.regread(sregkey) 'oLogging.CreateEntry "IE Version is " & sRegValue, LogTypeInfo 'Write a registry key 'Dim sRegValue, sRegKey, sNewRegValue 'sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\New Program" 'sNewRegValue = "C:\Windows\Notepad.exe" 'sRegValue=oUtility.regWrite(sregkey, sNewRegValue) 'Pre-defined objects 'oFSO – File System Object 'oShell – Wscript Shell object 'oEnv - Process Environment object 'oNetwork - WScript Network object 'Returns the full path of the script into the sScript variable 'Dim sScriptName, sScript 'sScriptName = "Set-Supervisor.wsf" 'iRetVal = oUtility.FindFile(sScriptName, sScript) 'If iRetVal <> Success then ' oLogging.CreateEntry "Unable to locate script " & sScriptName, LogTypeError ' Exit Function 'End if 'Script Directory and Name variables 'oUtility.ScriptName 'oUtility.ScriptDir 'oUtility.LogPath 'Sleep (Timeout) the script "safely" 'oUtility.SafeSleep(miliSeconds) 'sFile = oUtility.ScriptDir & "\WMI Provider GUI InstallShield Package 1.00L18.exe" 'If not oFSO.FileExists(sFile) then ' oLogging.CreateEntry "Install Panasonic BIOS Provider: " & sFile & " was not found, unable to install.", LogTypeError ' ZTIProcess = Failure ' Exit Function 'End if 'sCmd = sFile & " -s -f1""" & _ ' oUtility.ScriptDir & "\noui.iss"" -f2""" & _ ' oUtility.LogPath & "\PanasonicBIOSProvider.log""" 'oLogging.CreateEntry "Running: " & sCmd, LogTypeInfo 'iRetVal = oUtility.RunWithHeartbeat(sCmd) 'If (iRetVal = 0) or (iRetVal = 3010) then ' ZTIProcess = Success 'Else ' ZTIProcess = Failure 'End If 'oLogging.CreateEntry "Install Panasonic BIOS Provider: Return code from command = " & iRetVal, LogTypeInfo 'oLogging.CreateEntry "Install Panasonic BIOS Provider: Finished installation", LogTypeInfo 'Pull OS Version from Win32_OperatingSystem WMI 'Set oOperatingSystems = objWMI.ExecQuery ("Select * from Win32_OperatingSystem") 'For Each oTmp in oOperatingSystems ' sOSCurrentVersion = oTmp.Version 'Next 'Run console command and hide window 'RunWithConsoleLoggingAndHidden(sCmd) 'Trim all white space from variable 'oEnvironment.Item("_SMSTSORGNAME") = oUtility.TrimAllWS(oEnvironment.Item("_SMSTSORGNAME")) 'Get random number/guid 'oUtility.GenerateRandomGUID 'Other File/Folder methods 'oFileHandling.NormalizePath 'oFileHandling.GetTempFolder 'oFileHandling.GetTempFile 'oFileHandling.GetTempFileEx("FileExtension") 'oFileHandling.GetWindowsFolder 'Check if the file is newer than a specified version 'Dim sFileName, iMinVersion 'sFileName = oUtility.ScriptDir & "\MyInstall.msi" 'iMinVersion = 1.3 'If oUtility.CheckFileVersion(sFileName, iMinVersion) Then ' Wscript.echo "File is new enough.." 'End If 'Regular Expression match 'For Each Match in oRegEx.GetRegExMatchesFromFile( "\[([^\]]*)\]","c:\boot.ini" ) ' Wscript.echo "Match: " & Match 'Next End Function </script> </job> </script> </job>
/BG