Set Shell=WScript.CreateObject("WScript.Shell")
Set Environment=Shell.Environment("User")
Environment("Path")=Environment("Path")&"C:\"
我想更改运行脚本的wscript.exe进程的环境变量,仅影响它及其子进程。上面的代码不是我想要的,因为它更改了HKEY_CURRENT_USER \ Environment注册表设置,它会影响每个新进程。换句话说,我需要cmd.exe中set
命令的对应部分
答案 0 :(得分:5)
您必须更改process
环境:
With CreateObject("WScript.Shell")
With .Environment("process")
.Item("path") = .Item("path") & ";C:\"
End With
.Run "wscript.exe ""C:\test\another.vbs"""
End With