2/01/2011

vbScript - Get running environment

The following vbScript Function delivers the value true if the script runs within a task sequence environment. If not the functions delivers the value false. This function can be useful in scripts like wrapper and so on.


...
If RunningInTaskSequence = True Then
...

Function RunningInTaskSequence()
On Error Resume Next
Err.Clear
Dim objTSEnv : Set objTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")
If Err Then
'Script does not run within the Task Sequence environment
RunningInTaskSequence = False
Else
'Script does run within the Task Sequence environment
RunningInTaskSequence = True
End If
On Error GoTo 0
End Function

No comments: