Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function CreateJob(strCommand)
- Const SHELL_WAIT = True
- Const SHELL_HIDE = 0
- CreateJob = False
- ' Get date & time 1 minute in advance
- ' And it must be at least 1 minute
- ' Source: w3schools, & mikeblas on hardforum.com
- Dim strDateTime : strDateTime = DateAdd("n", 1, Now())
- Dim strDate : strDate = LEFT(strDateTime, InStr(strDateTime, " ")-1)
- Dim strTime : strTime = MID(strDateTime, InStr(strDateTime, " ")+1)
- ' define the command we will run to create the once-only scheduled task
- ' uses a new guid for the name each time so it will be a unique task
- Dim strJobCmd : strJobCmd = "schtasks.exe /Create /TN " & _
- getGuid & " /RU SYSTEM /ST " & _
- strTime & " /SD " & _
- strDate & " /SC ONCE /TR """ & _
- strCommand & """"
- ' on Vista/Win7 must create task as XP-readable type using /V1
- ' this is so it will delete itself propely (bug in schtasks) using /Z
- If onVistaWin7 Then strJobCmd = strJobCmd & " /Z /V1"
- WScript.echo strJobCmd
- Dim oJobShell : Set oJobShell = CreateObject("WScript.Shell")
- Dim jobRet : jobRet = oJobShell.Run(strJobCmd, SHELL_HIDE, SHELL_WAIT)
- If jobRet = 0 Then CreateJob = True
- ' here we tried to make the task and get the result to a variable
- ' if the return is non-zero then the creation of the task errored
- Set oJobShell = Nothing
- End Function
- Function getGuid
- ' this functions gets a unique guid and returns it as a string
- Dim TypeLib : Set TypeLib = CreateObject("Scriptlet.TypeLib")
- getGuid = Left(CStr(TypeLib.Guid),38)
- ' above line also removes some strageness at the end
- Set TypeLib = Nothing
- End Function
- Function onVistaWin7
- ' this function returns true on Vista or above (incl. Srv2008)
- Dim colOSver, objOSver
- onVistaWin7 = False
- Set colOSver = GetObject("WinMgmts:root\cimv2").ExecQuery("Select Version from Win32_OperatingSystem")
- For Each objOSver In colOSver
- If Left(objOSver.Version,1) >= 6 Then onVistaWin7 = True
- Next
- Set colOSver = Nothing
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement