Jump to content


  • 0
mcbroome

Sccm standalone key self expiration, following the guide exactly! What am I doing wrong? custom hook tsconfig .vbs file

Question

following the instructions here:

http://blogs.technet.com/b/deploymentguys/archive/2012/02/15/expiring-outdated-stand-alone-media.aspx

my tsconfig is as follows:

[CustomHook]

CommandLine="cscript.exe X:\ExpiredUFDCheck.vbs"

CommandLine="wscript.exe X:\Deploy\Scripts\ZTIMediaHook.wsf"

The ORIGINAL vbs file is as follows, which will not function for me and just throw errors and the logic seems wrong so I corrected it, ( changes annotated).

On Error Resume Next

 

' // ---------------------------------------------------------------------

' // Find the environment variable %configpath% for location of UFD

' // ---------------------------------------------------------------------

 

'Set objShell = CreateObject("WScript.Shell")

'Set objExecObject = objShell.Exec("%comspec% /c echo %configpath%")

'configPath1 = objExecObject.StdOut.ReadAll()

'configPath = Mid(configPath1, 1, Len(configPath1) -2)

 

 

' // -----------------------------------------------------------------------------------------

' // Find the environment variable %TEMP% for location of tool files (e.g. shutdown.exe)

' // -----------------------------------------------------------------------------------------

 

Set objShell = CreateObject("WScript.Shell")

Set objExecObject = objShell.Exec("%comspec% /c echo %temp%")

temp = objExecObject.StdOut.ReadAll()

tempdir = Mid(temp, 1, Len(temp) -2)

 

 

' // ---------------------------

' // Find driver letter for UFD

'// ----------------------------

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

Set Drives = FSO.Drives

 

For Each DiskDrive In Drives

If DiskDrive.DriveType = "1" Then

USBPath = DiskDrive.Path

End If

 

Next

 

 

' // -----------------------------------------------------------------

' // Query WMI for creation date of the Policy.xml file on the UFD

' // -----------------------------------------------------------------

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

 

' // ----------------------------

' // Media Check - Policy.xml

' // ----------------------------

 

Set colFiles = objWMIService.ExecQuery("Select * From CIM_DataFile Where Name = '" & USBPath & "\\SMS\\Data\\Policy.xml'")

 

 

' // -----------------------------------------

' // Set the date 3 months ago from today

' // -----------------------------------------

 

dt3MonthsAgo = DateAdd("m", -3, Now)

 

 

' // -----------------------------------------------------------------------------------------------------------

' // If the Policy.xml file creation date is less than the date 3 months ago from today, it is an expired UFD. <---------Shouldnt this be MORE?

' // -----------------------------------------------------------------------------------------------------------

 

For Each objFile in colFiles

dtCreationDate = WMIDateStringToDate(objFile.CreationDate)

dtEndDate = DateAdd("m", 3, dtCreationDate)

If dtCreationDate > dt3MonthsAgo then <--------------- I have changed "<" to ">"

Set WshShell = CreateObject("WScript.Shell")

Command = TEMPDIR & "\scripts\Shutdown.exe /s /t 0"

MsgBox "This USB Key expired on" & dtEndDate, vbMsgBoxSetForeground, "Expired USB Media"

Set oExec = WshShell.Exec(Command)

Else

'WScript.Quit(1) <------------------I have commented this out, ts fails every time, throwing a 4005 error

 

End If

Next

 

 

' // -----------------------------------------------------------------------------------------

' // Converting the WMI date query response to a simple date format. (e.g. 09/21/2010)

' // -----------------------------------------------------------------------------------------

 

Function WMIDateStringToDate(dtmInstallDate)

WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) & " " & Mid(dtmInstallDate, 9, 2) & ":" & Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, 13, 2))

End Function

I"m going crazy trying to get this thing to work! No matter what date I set in the bios, i see the script kick off, but my task sequence keeps right on going :( . Won't running this with the cscript command open an ugly to the end user cmd prompt box along with the notification box? Any help is appreciated!

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Try commenting out the initial "On Error Resume Next" line so you can get some error messages returned and see what's blowing up.

 

SIDE NOTE: Typically if I'm mesing with VBScript code in SCCM PE media I'll just boot into PE, hit F8, map a network drive using "NET USE", and then copy my scripts to X:\ and test from there (I make changes to the script file on my other machine, copy them down to X:\ again and try my test yet again). So no need to create new boot media for testing...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.