Re: Writing DWORD to registry key

From: Aaron (ABieberitz_at_charter.net)
Date: 10/13/04


Date: Tue, 12 Oct 2004 21:43:37 -0500

Yes I do, both test machines I have admin privileges and it's my own key
I've created. I'm writing strings to registry like they're going out of
style, but cannot write a DWORD to save my life, it just doesn't make any
sense...

"Randy Birch" <rgb_removethis@mvps.org> wrote in message
news:u7%23eZOLsEHA.376@TK2MSFTNGP09.phx.gbl...
> Are you sure you have permission to write to that key? Enter RegEdt32 in
> the Start > Run box and view the permissions for the key you're trying to
> write to (Edit > Permissions). HLKM is usually off-limits to users outside
> the admin group.
>
> --
>
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
>
>
> "Aaron" <ABieberitz@charter.net> wrote in message
> news:10mod77q40pft0d@corp.supernews.com...
> : That did not work either...nothing seems to be working and it is really
> : baffling me...here's what I did
> :
> : Dim verValue As Long
> :
> : WriteRegDWord HKEY_LOCAL_MACHINE, "\SOFTWARE\Software Limited,
Inc.\Tools
> : 5.2\5.2", "Version", verValue
> :
> : This code I have is under a form and I put all of your code you provided
> in
> : a separate module and made the WriteRegDWord a Public Function...is this
> the
> : problem, cause I surely don't get any errors???
> :
> : "Mike D Sutton" <EDais@mvps.org> wrote in message
> : news:OiSQESDsEHA.2588@TK2MSFTNGP12.phx.gbl...
> : > > I have spent the last several days trying every imaginable way to
> write
> : a
> : > > DWORD value to a key and nothing seems to work. I have used just
> about
> : > > every piece of code from this newsgroup as well as code from all
over
> : the
> : > > internet and no luck...I'm completely baffled at this point. I get
no
> : > > errors when calling functions that I've used, but the key is never
> : created
> : > > or the value is never populated. Any possible help whatsoever would
> be
> : > > EXTREMELY appreciated since I'm at the end of my rope with this...I
> : can't
> : > > believe no one's code out there works, it's just mind-boggling.
> : >
> : > Try these functions:
> : >
> : > '***
> : > Private Declare Function RegSetValueEx Lib "AdvAPI32.dll" Alias
> : "RegSetValueExA" ( _
> : > ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As
> : Long, _
> : > ByVal dwType As Long, ByRef lpData As Any, ByVal cbData As Long)
As
> : Long
> : > Private Declare Function RegQueryValueEx Lib "AdvAPI32.dll" Alias
> : "RegQueryValueExA" ( _
> : > ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved
As
> : Long, _
> : > ByRef lpType As Long, ByRef lpData As Any, ByRef lpcbData As Long)
> As
> : Long
> : > Private Declare Function RegOpenKeyEx Lib "AdvAPI32.dll" Alias
> : "RegOpenKeyExA" ( _
> : > ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As
> Long,
> : _
> : > ByVal samDesired As Long, ByRef phkResult As Long) As Long
> : > Private Declare Function RegCloseKey Lib "AdvAPI32.dll" (ByVal hKey As
> : Long) As Long
> : >
> : > Private Const HKEY_LOCAL_MACHINE As Long = &H80000002
> : > Private Const REG_DWORD As Long = 4 ' 32-bit number
> : > Private Const REG_DWORD_BIG_ENDIAN As Long = 5 ' 32-bit number
> : >
> : > Private Const READ_CONTROL As Long = &H20000
> : > Private Const KEY_QUERY_VALUE As Long = &H1
> : > Private Const KEY_SET_VALUE As Long = &H2
> : > Private Const KEY_CREATE_SUB_KEY As Long = &H4
> : > Private Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
> : > Private Const KEY_NOTIFY As Long = &H10
> : > Private Const KEY_READ As Long = (READ_CONTROL Or _
> : > KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or _
> : > KEY_NOTIFY)
> : > Private Const KEY_WRITE As Long = (READ_CONTROL Or _
> : > KEY_SET_VALUE Or KEY_CREATE_SUB_KEY)
> : >
> : > Private Const ERROR_SUCCESS As Long = 0&
> : >
> : > Private Function WriteRegDWord(ByVal inHive As Long, ByRef inKey As
> : String, _
> : > ByRef inValue As String, ByVal inDWord As Long, _
> : > Optional ByVal inBigEndian As Boolean = False) As Boolean
> : > Dim hKey As Long
> : >
> : > If (RegOpenKeyEx(inHive, inKey, 0, KEY_WRITE, hKey) =
ERROR_SUCCESS)
> : Then
> : > WriteRegDWord = RegSetValueEx(hKey, inValue, 0,
IIf(inBigEndian,
> _
> : > REG_DWORD_BIG_ENDIAN, REG_DWORD), inDWord, 4&) =
> ERROR_SUCCESS
> : > Call RegCloseKey(hKey)
> : > End If
> : > End Function
> : >
> : > Private Function ReadRegDWord(ByVal inHive As Long, _
> : > ByRef inKey As String, ByRef inValue As String) As Long
> : > Dim hKey As Long, ReadRet As Long, ReadSize As Long
> : >
> : > If (RegOpenKeyEx(inHive, inKey, 0, KEY_READ, hKey) =
ERROR_SUCCESS)
> : Then
> : > ReadSize = 4
> : > If (RegQueryValueEx(hKey, inValue, 0, REG_DWORD, ReadRet, _
> : > ReadSize) = ERROR_SUCCESS) Then ReadRegDWord = ReadRet
> : > Call RegCloseKey(hKey)
> : > End If
> : > End Function
> : > '***
> : >
> : > Hope this helps,
> : >
> : > Mike
> : >
> : >
> : > - Microsoft Visual Basic MVP -
> : > E-Mail: EDais@mvps.org
> : > WWW: http://EDais.mvps.org/
> : >
> : >
> :
> :
>



Relevant Pages

  • Re: SBS 2003 XP Client SP2 add new user with user rights cant use
    ... This will work im sure just tried similar setup seamed ok - What I dont ... loacal admin privileges even though she was assigned USER privilages from the ... Sometimes you need to contact the app vendor ... >> permission to open database file - Its something to do with not having ...
    (microsoft.public.windows.server.sbs)
  • Re: downloading itunes on computer
    ... If per chance you are speaking of the Current User hive via the registry, ... you have admin privileges? ... Taskbar Repair Tool Plus! ...
    (microsoft.public.windowsxp.general)
  • Re: Registry entry to add app to "Open with" list
    ... double-entry in the "Open with list". ... I need to configure an installation program to *add* the software ... The installation currently doesn't need admin privileges. ... this registry entryrequire admin privileges? ...
    (microsoft.public.windowsxp.basics)
  • Registry entry to add app to "Open with" list
    ... reverse of my problem! ... I need to configure an installation program to *add* the software (e.g. ... The installation currently doesn't need admin privileges. ... this registry entryrequire admin privileges? ...
    (microsoft.public.windowsxp.basics)
  • Re: How do I install IIS on XP Professional?
    ... I am not going to bypass the restriction with out permission. ... permission to by pass the restriction from desktop support. ... I have admin privileges on the machine and I can ...
    (microsoft.public.windowsxp.setup_deployment)