1

我将 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\?

4

2 回答 2

0

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

>> WScript.Echo CreateObject("WScript.Shell").ExpandEnvironmentStrings("%systemroot%")
>>
C:\WINDOWS

文档

于 2012-12-17T23:01:38.160 回答
0

使值成为可扩展的字符串

objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\VPService" _
  , "%SystemRoot%\\System32\\VPService.exe", "REG_EXPAND_SZ"
于 2012-12-17T23:04:35.557 回答