Re: Reading GUID from registry
- From: "Don Burn" <burn@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 9 Dec 2008 08:12:54 -0500
No,
You have multiple problems here, the UNICODE_STRING is a length, max
length and pointer to the string. Also RtlStringFromGUID allocates the
buffer for the string without space for the NULL. So you need something
like (I have not tested or compiled this):
UNICODE_STRING DiskId;
PWCHAR Buffer;
status = RtlStringFromGUID(&Partition.disk_id,&DiskId);
if ( NT_SUCCESS( status ) )
{
KdPrint(( "Got String %wZ\n", &DiskId );
Buffer = ExAllocatePoolWithTag( PagedPool, DiskId.Length +
sizeof( WCHAR), TAG );
if ( Buffer != NULL )
{
RtlZeroMemory( Buffer, DiskId.Length + sizeof( WCHAR) );
RtlCopyMemory( Buffer, DiskId.Buffer, DiskId.Length );
status = ZwSetValueKey( ... )
ExFreePool( Buffer );
RtlFreeUnicodeString( &DiskId );
}
}
--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"qwert" <qwert@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ADCD644F-DD86-4C0E-B305-943E609AC904@xxxxxxxxxxxxxxxx
I use ZwSetValueKey to set the ID in registry.
I takes PVOID as the input paramater.
I just pass addresss of UNICODE_STRING to it like &DiskID
and the length parameter as sizeof(WCHAR) + DiskID.Length
Is it correct???
"Don Burn" wrote:
No, UNICODE_STRINGS have a pointer, but the registry calls take a
pointer
to the wide character strings. The print is probably messed up the same
way, as is the write.
--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"qwert" <qwert@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E3ED71C1-E295-453E-B44D-4C37B6CC6288@xxxxxxxxxxxxxxxx
I tried using RtlGUIDfromString
UNICODE_STRING DiskID;
status = RtlStringFromGUID(&Partition.disk_id,&DiskID);
I checked the return value also.It is success but however when I try to
print the DiskID unicode I see some junk.
Now I am setting this value in Registry.
when I query from registry I use
status = ZwQueryValueKey(MemberKeyHandle,
&RegistryValueName,
KeyValuePartialInformation,
pKeyValuePartialInformation,
KeyInformationLength,
&ResultLength);
if(NT_SUCCESS(status))
{
RtlGUIDFromString((UNICODE_STRING
*)pKeyValuePartialInformation->Data,
&disk_id.DiskId);
}
After this I am blue screening.Is my usage of the above 2 functions
correct????
"Don Burn" wrote:
No you cannot use strtok. You can depending on how you wrote it use
RtlGUIDfromString. Why did you write the GUID as a string, a binary
registry entry is easier.
--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"qwert" <qwert@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B8176D31-2307-485B-89B3-D9E6D507768F@xxxxxxxxxxxxxxxx
I have a case were I need to read the GUID which I have written in
registry.
I actually created a wchar array and used swprintf to format the
GUID
structure and I did set the GUID in the registry,
Now I wanted read back that string and assign the values to the
structure.
Normally when I write the GUID in registry I enclose it with
brackets
and
use hyphens inbetween to print it in correct format.
I have strtok in application where I can use hyphens as delimiters.
In kernel side can I use strtok???
How do normally people do this in kernel side???
Thanks in advance
.
- References:
- Reading GUID from registry
- From: qwert
- Re: Reading GUID from registry
- From: Don Burn
- Re: Reading GUID from registry
- From: qwert
- Re: Reading GUID from registry
- From: Don Burn
- Re: Reading GUID from registry
- From: qwert
- Reading GUID from registry
- Prev by Date: Re: Reading GUID from registry
- Next by Date: math.h in driver
- Previous by thread: Re: Reading GUID from registry
- Next by thread: Re: Reading GUID from registry
- Index(es):
Relevant Pages
|