Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 在VBS上使用变量_Variables_Vbscript_Registry - Fatal编程技术网

Variables 在VBS上使用变量

Variables 在VBS上使用变量,variables,vbscript,registry,Variables,Vbscript,Registry,我将reg文件转换为VBS命令 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run] @="" "VPService"="C:\\Windows\\System32\\VPService.exe" 但是我不能在这个问题上使用%systemroot%变量来代替C:\Windows\ Option Explicit Dim objShell Set objShell = CreateObject("WScript.She

我将reg文件转换为VBS命令

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
@=""
"VPService"="C:\\Windows\\System32\\VPService.exe"
但是我不能在这个问题上使用%systemroot%变量来代替C:\Windows\

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")

Dim strComputer, ArrOfValue, oReg
const HKEY_USERS = &H80000003
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_CURRENT_USER = &H80000001
const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\", ""
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\", "", "REG_SZ" 'Default value
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\VPService", "C:\\Windows\\System32\\VPService.exe", "REG_SZ"
Set objShell = Nothing
WScript.Quit

如何在此代码上使用%systemroot%变量而不是C:\Windows\呢?

WScript.Shell可以展开环境变量:

>> WScript.Echo CreateObject("WScript.Shell").ExpandEnvironmentStrings("%systemroot%")
>>
C:\WINDOWS
将该值设为:

objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\VPService" _
  , "%SystemRoot%\\System32\\VPService.exe", "REG_EXPAND_SZ"