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.

  1. ...  
  2. If RunningInTaskSequence = True Then  
  3. ...  
  4.   
  5. Function RunningInTaskSequence()  
  6.  On Error Resume Next  
  7.  Err.Clear  
  8.    Dim objTSEnv : Set objTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")  
  9.  If Err Then  
  10.   'Script does not run within the Task Sequence environment  
  11.      RunningInTaskSequence = False  
  12.  Else  
  13.   'Script does run within the Task Sequence environment  
  14.   RunningInTaskSequence = True  
  15.  End If  
  16.  On Error GoTo 0  
  17. End Function  

No comments: