UFT 12.5操作HKLM注册表项时遇Invalid root错误求助
Hey there, let's get to the bottom of that registry write error you're hitting. The issue boils down to two key things: UFT 12.5 being a 32-bit application, and Windows Server 2012's registry redirection behavior. Here's what's happening and how to fix it:
Why the error occurs
UFT 12.5 runs as a 32-bit program, so when you try to write to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon, Windows automatically redirects your request to the 32-bit registry hive (HKLM\SOFTWARE\Wow6432Node\...). But the Winlogon keys you're targeting live in the 64-bit section of the registry—hence the "Invalid root in registry key" error.
Solution: Use WMI's StdRegProv class (64-bit registry access)
Instead of relying on WshShell.RegWrite, use the WMI StdRegProv class, which lets you explicitly access the 64-bit registry hive. This avoids redirection issues and works reliably on Windows Server 2012.
Here's a ready-to-use VBScript snippet for UFT:
' Define constants for registry access Const HKEY_LOCAL_MACHINE = &H80000002 Const REG_SZ = 1 ' Connect to the WMI registry provider Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") ' Target registry path (no redirection here) strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" ' Update LegalNoticeCaption strValueName = "LegalNoticeCaption" strNewCaption = "Your Custom Caption" objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strNewCaption ' Update LegalNoticeText strValueName = "LegalNoticeText" strNewText = "Your full legal notice content goes here" objReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strNewText MsgBox "Registry values updated successfully!", vbInformation
Critical Notes
- Run UFT as Administrator: Modifying keys under
HKLMrequires elevated privileges. Right-click the UFT shortcut and select "Run as administrator" before executing the script. - Test outside UFT first: If you still hit issues, run the script via
cscript.exe(as admin) to confirm it works outside the UFT environment—this helps rule out UFT-specific configuration problems. - UAC settings: On Windows Server 2012, UAC might block the operation even for admins, so ensuring elevated rights is non-negotiable.
内容的提问来源于stack exchange,提问作者Vikram Ganapathi

