How to set environment variables in vbs that can be read in calling batch script

后端 未结 5 454
太阳男子
太阳男子 2021-01-11 17:23

I have a batch file that calls a vbscript file. I am trying to have the vbscript file change an environment variable that is later used in the batch file that calls the vbsc

5条回答
  •  情深已故
    2021-01-11 17:32

    Ho about this:

    @echo off
    set vbsFile=%temp%\createguid.vbs
    call :CreateVbs
    call :GetGuid NewGuid
    echo.%NewGuid%
    del %vbsFile%>nul
    GOTO:EOF
    
    :CreateVbs
    echo.set obj = CreateObject("Scriptlet.TypeLib")>%vbsFile%  
    echo.WScript.StdOut.WriteLine obj.GUID>>%vbsFile% 
    GOTO:EOF
    
    :GetGuid
    for /f "tokens=*" %%i in ('cscript //nologo %vbsFile%') do set %1=%%i
    GOTO:EOF
    

    It is not pure batch script but works ok.

提交回复
热议问题