AutoHotkey Community

It is currently May 27th, 2012, 12:21 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: November 20th, 2008, 12:14 am 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
Thanks Skan. Still not being successful though; not sure where I'm messing up :(

Code:
hKey = HKEY_LOCAL_MACHINE
sKeyName = SYSTEM
sValueName = InstallLocation
KEY_QUERY_VALUE = 0x1

DllCall("Advapi32.dll\RegOpenKeyEx", Str,hKey, Str,sKeyName, Int,0, Int,KEY_QUERY_VALUE, "UInt *",tmpHandle)
DllCall("Advapi32.dll\RegQueryValue", "UInt *",tmpHandle, Str,sValueName, Str,vValue)

MsgBox, %vValue%

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 2:15 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
dbaldacchino wrote:
not sure where I'm messing up :(


There are only RegOpenKeyExA / RegOpenKeyExW for me in advapi32.dll ( Win XP 32b )

Code:
DllCall("Advapi32.dll\RegOpenKeyEx", Str,hKey, Str,sKeyName, Int,0, Int,KEY_QUERY_VALUE, "UInt *",tmpHandle)
MsgBox, % Errorlevel ; if -4 ,  try calling RegOpenKeyExA


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 3:01 am 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
I see. I read the following and thought it needed to be RegOpenKeyEx.



As you pointed out, it returned -4. I corrected it to RegOpenKeyExA and it now returns 0, which means ERROR_SUCCESS, correct?

Now if that is working, I'm still having trouble with RegQueryValueEx that reads the value. Errorlevel is returning A-4. Not sure what to make of that.

Code:
hKey = HKEY_LOCAL_MACHINE
sKeyName = SYSTEM
sValueName = InstallLocation
KEY_QUERY_VALUE = 0x1

DllCall("Advapi32.dll\RegOpenKeyExA", Str,hKey, Str,sKeyName, Int,0, Int,KEY_QUERY_VALUE, "UInt *",tmpHandle)
MsgBox, % Errorlevel ; This is  now returning 0

DllCall("Advapi32.dll\RegQueryValueExA", "UInt *",tmpHandle, Str,sValueName, Int,0, Int,0, Str,vValue)
MsgBox, % Errorlevel ; This is returning A-4
MsgBox, %vValue%


[ Moderator!: MSDN links fixed ]

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 3:18 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Code:
DllCall("Advapi32.dll\RegOpenKeyExA", Str,hKey, Str,sKeyName, Int,0, Int,KEY_QUERY_VALUE, "UInt *",tmpHandle)
MsgBox, % tmpHandle ; What shows up ?


Quote:
returns 0, which means ERROR_SUCCESS, correct?


http://www.autohotkey.com/forum/viewtopic.php?t=19766


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 3:45 am 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
It returned 0. Doesn't sounds like that should be the value of that variable!

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2008, 6:04 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Okay.. here is the wrapped function for you, to experiment with:

Code:
; fourth parameter not required while retrieving default value
MsgBox, % RegRead( Data, "HKLM", "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.exe"  )
MsgBox, % Data

; Retrieving Text
MsgBox, % RegRead( Data, "HKLM", "SOFTWARE\AutoHotkey", "InstallDir" )
MsgBox, % Data

;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

; Retrieving DWord
MsgBox, % RegRead( Data, "HKLM", "SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "Bias" )
MsgBox, % NumGet( Data )

; Retrieving Binary
MsgBox, % RegRead( FileTime, "HKLM", "SYSTEM\CurrentControlSet\Control\Windows", "ShutdownTime" ) ; XP Only
; FILETIME Structure needs to be processed with FileTimeToSystemTime()
; www.msdn.microsoft.com/en-us/library/ms724280(VS.85).aspx
Return

RegRead( byRef Data, RootKey="", SubKey="", ValueName="" ) {
 IfEqual,RootKey,HKCR, SetEnv, RootKey, 0x80000000 ; HKEY_CLASSES_ROOT
 IfEqual,RootKey,HKCU, SetEnv, RootKey, 0x80000001 ; HKEY_CURRENT_USER
 IfEqual,RootKey,HKLM, SetEnv, RootKey, 0x80000002 ; HKEY_LOCAL_MACHINE
 IfEqual,RootKey,HKU , SetEnv, RootKey, 0x80000003 ; HKEY_USERS
 IfEqual,RootKey,HKPD, SetEnv, RootKey, 0x80000004 ; HKEY_PERFORMANCE_DATA
 IfEqual,RootKey,HKPD, SetEnv, RootKey, 0x80000005 ; HKEY_CURRENT_CONFIG
 KEY_QUERY_VALUE = 0x1
 DllCall( "Advapi32.dll\RegOpenKeyExA", UInt,RootKey, UInt,0, UInt,0, Int,0x1, UIntP,hKey)
 Loop, Parse, SubKey, \
  {
    DllCall( "Advapi32.dll\RegOpenKeyExA"
            , UInt,hKey, Str,A_LoopField, Int,0, UInt,0x1, UIntP,tmpHandle )
    DllCall( "Advapi32.dll\RegCloseKeyA", UInt,(hKey := tmpHandle) )
 }
 DllCall( "Advapi32.dll\RegQueryValueExA"
         , UInt,hKey, Str,ValueName, UInt,0, UInt,0, UIntP,Data, UIntP,RqdSz )
 VarSetCapacity( Data,RqdSz, 0 )
 DllCall( "Advapi32.dll\RegQueryValueExA"
         , UInt,hKey, Str,ValueName, UInt,0, UIntP,ValueType, Str,Data, UIntP,RqdSz )
 DllCall( "Advapi32.dll\RegCloseKeyA", UInt,hKey )
 IfEqual,ValueType,1, Return, "REG_SZ " RqdSz
 IfEqual,ValueType,2, Return, "REG_EXPAND_SZ " RqdSz
 IfEqual,ValueType,3, Return, "REG_BINARY " RqdSz
 IfEqual,ValueType,4, Return, "REG_DWORD " RqdSz
 IfEqual,ValueType,7, Return, "REG_MULTI_SZ " RqdSz
}


:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2008, 1:19 am 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
Thanks a lot SKAN! It took a while for me to get back but it seems like I have a workable solution now. This Threadalso helped a ton (really, the solution was delivered on a platter!). Thanks for all your help. I'm a total rookie when it comes to scripting, especially with using dllcall and doing registry reading.

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 3:50 pm 
Offline

Joined: August 12th, 2007, 3:49 am
Posts: 12
Posted full RegRead64() and RegWrite64() functions on this page:

http://www.autohotkey.com/forum/viewtopic.php?p=241769

Cheers!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 4:36 pm 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
Thanks tomte! I'll give those functions a spin.

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], jrav and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group