Having trouble with stdregprov and uintvalue..

T

Text

I'm trying to invoke the createkey method under StdRegProv but I can't seem
to get the first
imparam correct

it says that "Value was either too large or too small for a UInt32 when it
processes current_user."

how do I pass a UInt32 value? Msdn has it listed as 0x80000001, but
vb.net won't except that. hDefKey only accepts uint32 values... or so it
seems.


Const HKEY_current_user As Long = &H80000001

Dim strkeypath As Object = "Software\Microsoft\Internet Explorer\Main\mas"

Dim wmi As ManagementClass

Dim md As MethodData

Dim RemotePC As String

RemotePC = "."

wmi = New ManagementClass("\\" & RemotePC & "\root\default:StdRegProv")

Dim inParams As ManagementBaseObject = wmi.GetMethodParameters("Createkey")

inParams("hDefKey") = HKEY_current_user

inParams("sSubKeyName") = strkeypath

Dim outParams As ManagementBaseObject = wmi.InvokeMethod("Createkey",
inParams, Nothing)



' Display results

' Note: The return code of the method is provided in the "returnValue"
property of the outParams object

Console.WriteLine("Creation of registry returned: {0}",
outParams("returnValue"))
 
O

Olivier DALET

Two answers:
- first and best one (to me): use C# which provides unsigned types (uint,
ulong, ...):
const uint HKEY_current_user = 0x80000001;

- second one: using VB, I wrote this horrible (but working) piece of code:
Const HKEY_current_user As String = "80000001"
...
inParams("hDefKey") = UInt32.Parse(HKEY_current_user,
System.Globalization.NumberStyles.HexNumber)

Maybe somebody will find a cleaner solution using VB ?...

Olivier DALET
----------------
Text said:
I'm trying to invoke the createkey method under StdRegProv but I can't seem
to get the first
imparam correct

it says that "Value was either too large or too small for a UInt32 when it
processes current_user."

how do I pass a UInt32 value? Msdn has it listed as 0x80000001, but
vb.net won't except that. hDefKey only accepts uint32 values... or so it
seems.


Const HKEY_current_user As Long = &H80000001

Dim strkeypath As Object = "Software\Microsoft\Internet Explorer\Main\mas"

Dim wmi As ManagementClass

Dim md As MethodData

Dim RemotePC As String

RemotePC = "."

wmi = New ManagementClass("\\" & RemotePC & "\root\default:StdRegProv")

Dim inParams As ManagementBaseObject = wmi.GetMethodParameters("Createkey")

inParams("hDefKey") = HKEY_current_user

inParams("sSubKeyName") = strkeypath

Dim outParams As ManagementBaseObject = wmi.InvokeMethod("Createkey",
inParams, Nothing)



' Display results

' Note: The return code of the method is provided in the "returnValue"
property of the outParams object

Console.WriteLine("Creation of registry returned: {0}",
outParams("returnValue"))






----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
G

greendot

You need to just specify what type the literal is:


dim dword as uint32

dword = convert.ToInt32(&H80000000)

' does not work, you get the "Value was too large or too small..."
exception.
' probably because that literal resolves to be a negative number

dword = convert.ToInt32(&H80000000L)

' this one does work, the "L" casts it long and keeps it positive


And it avoids the parsing trick. :)

Now, if they would only give us a literal cast that would let us bypass
the convert part.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top