'========================================================================================================================== ' NAME: SetPathAsVariable.vbs ' ' AUTHOR: Mathias Haas, Fidelity Consulting AB. ' mathias.haas@fidelityconsulting.se ' DATE : 2014-06-11 ' Version : 1.0 '========================================================================================================================== Option Explicit Dim wShell, sTemp, sLogFile, sPath Set wShell = WScript.CreateObject( "WScript.Shell" ) sTemp = wShell.ExpandEnvironmentStrings( "%TEMP%" ) sLogFile = sTemp & "\" & Replace (WScript.ScriptName,".vbs","") & ".log" sPath = replace(Wscript.ScriptFullName,"\" & WScript.ScriptName,"") Call CreateTSVariable(sPath,"WindowsSource") Call LogToFile(Now() & " - Finished!") Wscript.Quit() ''''''''''''''''''''''''''''' ' FUNCTIONS ' ''''''''''''''''''''''''''''' ' ---------------------------------------------- Function CreateTSVariable(Path,SMSTSVar) dim TSenv Set TSenv = CreateObject("Microsoft.SMS.TSEnvironment") Call LogToFile(Now() & " - Creating SMS TS Variable for " & SMSTSVar & " = " & Path ) TSenv(SMSTSVar) = Path end Function Function LogToFile(txt2log) Dim fso, sPath, fsotxt Const ForAppending = 8 Set fso = CreateObject("Scripting.FileSystemObject") if (fso.FileExists(sLogfile)) Then Set fsotxt = fso.OpenTextFile(sLogfile, ForAppending, True) Else Set fsotxt = fso.CreateTextFile(sLogfile, False) fsotxt.WriteLine("Log from " & WScript.ScriptName & ".") End If On Error Resume Next fsotxt.WriteLine txt2log On Error GoTo 0 WScript.Echo txt2log fsotxt.close End Function