Can I pick up environment variables in vbscript WSH script?

后端 未结 5 510
终归单人心
终归单人心 2020-11-28 13:37

Is is possible to read system environment variables in a Windows Scripting Host (WSH) VBS script?

(I am writing a VBScript using Windows Scripting Host for task for

5条回答
  •  被撕碎了的回忆
    2020-11-28 13:55

    Here's an example (taken from here):

    Set oShell = CreateObject( "WScript.Shell" )
    user=oShell.ExpandEnvironmentStrings("%UserName%")
    comp=oShell.ExpandEnvironmentStrings("%ComputerName%")
    WScript.Echo user & " " & comp
    

提交回复
热议问题