Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: WMI StdRegProv Class can return junk characters using the GetStringValue


View products that this article applies to.

Symptoms

You can get junk characters returned when you read the registry value by using WMI’s StdregProv::GetStringValue() on Windows Server 2003/Windows XP/Windows Vista and Windows Server 2008

↑ Back to the top


Cause

The junk characters can be returned by StdregProv::GetStringValue() when the registry key of type REG_SZ has an “empty” value, this causes GetStringValue() to return a pointer to an allocated but uninitialized memory buffer resulting in what appears to be junk characters.

↑ Back to the top


Resolution

This issue has been fixed in WMI registry provider implementation on Windows 7 and Windows Server 2008 R2.

↑ Back to the top


More Information

Reproduction

To reproduce this behavior you can follow these simple steps:

On any Windows Server 2003/Windows XP or Windows Vista/Windows Server 2008 system do the following:

1. Start RegEdit on your machine.

2. Create a test key: HKEY_LOCAL_MACHINE\SYSTEM\CustomKey

3. Add a string value to the key: SimpleString set it to the value “Test”.

4. Run the simple VBS provided below, the value of SimpleString should be “Test”.

5. In regedit, highlight the key value SimpleString, right click and select the “Modify Binary Data” option.

6. Remove all of the data from the window, you should see only the byte offset of “0000” displayed to the left in the dialog. Click OK to save.

7. Run the simple VBS from step 6 once again. You will notice a bunch of what appears to be junk characters displayed on the screen.

The simple VBS test script would be:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
objReg.GetStringValue HKEY_LOCAL_MACHINE,"SYSTEM\CustomKey","SimpleString",strVal
wscript.echo "StringValue: " & strVal


Detecting the junk character values is not always possible. To completely avoid the issue with the WMI Registry provider, use the low level Win32 Registry APIs.


↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2751335
Revision : 1
Created on : 1/7/2017
Published on : 8/29/2012
Exists online : False
Views : 620