Windows8.1:无法使用从 HTA 调用的 VBS 编辑注册表,而单独调用 VBS 工作正常

Windows 8.1: can't edit registry with a VBS called from an HTA while calling the VBS alone works fine

我正在开发一个 Windows 8.1 HTA 来实现各种操作。在某些时候,我需要将值插入注册表(用于自动登录和运行一次)。

这是 VBS 代码:

Sub RunOnce()

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objShell = CreateObject("WScript.Shell")
Set objRegistry = GetObject("winmgmts:\" & strComputer & "\root\default:StdRegProv")
strNewKeyPath = "Software\Microsoft\Windows\CurrentVersion\RunOnce"
strNewValue = "AppsInstaller"
strCurDir    = objShell.CurrentDirectory
strScriptPath = strCurdir & "_Install_Apps.hta"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strNewKeyPath, strNewValue, strScriptPath

End Sub

Function AutoLogon(strLogin, strPassword)

Set objShell = CreateObject("WScript.Shell")
strAutoLogon = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\winlogon"
objShell.RegWrite strAutoLogon & "\AutoAdminLogon", "1", "REG_DWORD"
objShell.RegWrite strAutoLogon & "\DefaultUserName", strLogin, "REG_SZ"
objShell.RegWrite strAutoLogon & "\DefaultPassword", strPassword, "REG_SZ"

End Function

我正在 Windows 下的计算机上进行开发 7. 当我从以管理员权限启动的 HTA 调用 RunOnce 和 AutoLogon 时,一切正常。 我的目标是 Windows 8.1 下的 Surface Pro 3。当我从这台计算机上以管理权限启动的 HTA 调用 RunOnce 和 AutoLogon 时,注册表没有被编辑。但是,如果我以管理员权限启动以下 VBS 文件,它就可以正常工作。

Sub RunOnce()

    Const HKEY_LOCAL_MACHINE = &H80000002
    strComputer = "."
    Set objShell = CreateObject("WScript.Shell")
    Set objRegistry = GetObject("winmgmts:\" & strComputer & "\root\default:StdRegProv")
    strNewKeyPath = "Software\Microsoft\Windows\CurrentVersion\RunOnce"
    strNewValue = "AppsInstaller"
    strCurDir    = objShell.CurrentDirectory
    strScriptPath = strCurdir & "_Install_Apps.hta"
    objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strNewKeyPath, strNewValue, strScriptPath

End Sub


Function AutoLogon(strLogin, strPassword)

    Set objShell = CreateObject("WScript.Shell")
    strAutoLogon = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\winlogon"
    objShell.RegWrite strAutoLogon & "\AutoAdminLogon", "1", "REG_DWORD"
    objShell.RegWrite strAutoLogon & "\DefaultUserName", strLogin, "REG_SZ"
    objShell.RegWrite strAutoLogon & "\DefaultPassword", strPassword, "REG_SZ"

End Function

RunOnce()
Test = AutoLogon("login", "password")

我真的不明白这是怎么回事。确实跟管理员权限有关系,但是我一头雾水,不知道怎么办了。

确保 运行 您的 HTA 是 mshta.exe 的 64 位版本。 (或检查正确的位数)。

来自帮助。

Registry Redirector

The registry redirector isolates 32-bit and 64-bit applications by providing separate logical views of key portions of the registry on WOW64.

The registry redirector intercepts 32-bit registry calls to each logical registry view and maps them to the corresponding physical registry location.

The redirection process is transparent to the application. Therefore, a 32-bit application can access registry data as if it were running on 32-bit Windows even if the data is stored in a different location on 64-bit Windows.

Redirection is enabled for the following registry keys:

HKEY_LOCAL_MACHINE\Software

HKEY_USERS*\Software\Classes

HKEY_USERS*_Classes

Note * indicates a match for all user security IDs (SID).

The following scenario illustrates the use of these logical views:

A 32-bit application checks for the existance of the following registry key: HKEY_LOCAL_MACHINE\Software\Hello. If the key does not exist, it creates it with a default value of "Hello 32-bit world"; otherwise, it reads and displays the value.

The same application is modified to write "Hello 64-bit world" instead of "Hello 32-bit world" and recompiled as a 64-bit application. When the 32-bit application is run on 64-bit Windows, it displays "Hello 32-bit world". When the 64-bit application is run, it displays "Hello 64-bit world". Both applications call the same registry functions with the same predefined handle and the same key name; the difference is that each application operates on its logical view of registry, and each view is mapped to a separate physical location of the registry, which keeps both versions of the string intact.

To help applications that write REG_EXPAND_SZ keys containing %ProgramFiles% to the registry, WOW64 intercepts these writes and replaces them with "%ProgramFiles(x86)%". This environment variable is defined for all processes. For example, if the Program Files directory is on the C drive, then "%ProgramFiles(x86)%" expands to "C:\Program Files (x86)".

To enable application interoperability through COM and other mechanisms, WOW64 uses registry reflection, which copies specific registry keys and values between the two registry views to keep them in synch. The reflector is intelligent and copies COM activation data for Local servers between the views, but not in-process data, because 32/64 in-process data mixing is not permitted on 64-bit Windows.

For more information, see the following topics:

Registry Reflection

Shared Registry Keys

Accessing an Alternate Registry View

Example of Registry Reflection and Redirection on WOW64

Remote Registry Access in 64-bit Windows

Send comments about this topic to Microsoft

Build date: 10/2/2006