Advertisement
Guest User

Untitled

a guest
May 27th, 2014
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. winver=64
  2. If !RegRead(steamPath, "HKLM", "Software\Valve\Steam", "InstallPath", (If winVer = "64" ? 64:32))
  3. RegRead(steamPath, "HKLM", "Software\Valve\Steam", "InstallPath", 32)
  4. msgbox % steamPath
  5. exitapp
  6.  
  7. RegRead(ByRef OutputVar, RootKey, SubKey, ValueName = "", RegistryVersion="32")
  8. {
  9. ; Log("RegRead - Reading from Registry : RootKey=" . RootKey . ", SubKey=" . SubKey . ", ValueName=" . ValueName . ",RegistryVersion=" . RegistryVersion, 4)
  10. If (RegistryVersion = "32")
  11. RegRead, OutputVar, %RootKey%, %SubKey%, %ValueName%
  12. Else
  13. OutputVar := RegRead64(RootKey, SubKey, ValueName)
  14. ; Log("RegRead - Registry Read finished, returning " . OutputVar, 4)
  15. Return OutputVar
  16. }
  17.  
  18. RegRead64(sRootKey, sKeyName, sValueName = "", DataMaxSize=1024) {
  19. HKEY_CLASSES_ROOT := 0x80000000 ; http://msdn.microsoft.com/en-us/library/aa393286.aspx
  20. HKEY_CURRENT_USER := 0x80000001
  21. HKEY_LOCAL_MACHINE := 0x80000002
  22. HKEY_USERS := 0x80000003
  23. HKEY_CURRENT_CONFIG := 0x80000005
  24. HKEY_DYN_DATA := 0x80000006
  25. HKCR := HKEY_CLASSES_ROOT
  26. HKCU := HKEY_CURRENT_USER
  27. HKLM := HKEY_LOCAL_MACHINE
  28. HKU := HKEY_USERS
  29. HKCC := HKEY_CURRENT_CONFIG
  30.  
  31. REG_NONE := 0 ; http://msdn.microsoft.com/en-us/library/ms724884.aspx
  32. REG_SZ := 1
  33. REG_EXPAND_SZ := 2
  34. REG_BINARY := 3
  35. REG_DWORD := 4
  36. REG_DWORD_BIG_ENDIAN := 5
  37. REG_LINK := 6
  38. REG_MULTI_SZ := 7
  39. REG_RESOURCE_LIST := 8
  40.  
  41. KEY_QUERY_VALUE := 0x0001 ; http://msdn.microsoft.com/en-us/library/ms724878.aspx
  42. KEY_WOW64_64KEY := 0x0100 ; http://msdn.microsoft.com/en-gb/library/aa384129.aspx (do not redirect to Wow6432Node on 64-bit machines)
  43. KEY_SET_VALUE := 0x0002
  44. KEY_WRITE := 0x20006
  45.  
  46. myhKey := %sRootKey% ; pick out value (0x8000000x) from list of HKEY_xx vars
  47. IfEqual,myhKey,, { ; Error - Invalid root key
  48. ErrorLevel := 3
  49. return ""
  50. }
  51.  
  52. RegAccessRight := KEY_QUERY_VALUE + KEY_WOW64_64KEY
  53.  
  54. DllCall("Advapi32.dll\RegOpenKeyExA", "uint", myhKey, "str", sKeyName, "uint", 0, "uint", RegAccessRight, "uint*", hKey) ; open key
  55. DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint*", sValueType, "uint", 0, "uint", 0) ; get value type
  56. If (sValueType == REG_SZ or sValueType == REG_EXPAND_SZ) {
  57. VarSetCapacity(sValue, vValueSize:=DataMaxSize)
  58. DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint", 0, "str", sValue, "uint*", vValueSize) ; get string or string-exp
  59. } Else If (sValueType == REG_DWORD) {
  60. VarSetCapacity(sValue, vValueSize:=4)
  61. DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint", 0, "uint*", sValue, "uint*", vValueSize) ; get dword
  62. } Else If (sValueType == REG_MULTI_SZ) {
  63. VarSetCapacity(sTmp, vValueSize:=DataMaxSize)
  64. DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint", 0, "str", sTmp, "uint*", vValueSize) ; get string-mult
  65. sValue := ExtractData(&sTmp) "`n"
  66. Loop {
  67. If (errorLevel+2 >= &sTmp + vValueSize)
  68. Break
  69. sValue := sValue ExtractData( errorLevel+1 ) "`n"
  70. }
  71. } Else If (sValueType == REG_BINARY) {
  72. VarSetCapacity(sTmp, vValueSize:=DataMaxSize)
  73. DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint", 0, "str", sTmp, "uint*", vValueSize) ; get binary
  74. sValue := ""
  75. SetFormat, integer, h
  76. Loop %vValueSize% {
  77. hex := SubStr(Asc(SubStr(sTmp,A_Index,1)),3)
  78. StringUpper, hex, hex
  79. sValue := sValue hex
  80. }
  81. SetFormat, integer, d
  82. } Else { ; value does not exist or unsupported value type
  83. DllCall("Advapi32.dll\RegCloseKey", "uint", hKey)
  84. ErrorLevel := 1
  85. return ""
  86. }
  87. DllCall("Advapi32.dll\RegCloseKey", "uint", hKey)
  88. return sValue
  89. }
  90.  
  91. ExtractData(pointer) { ; http://www.autohotkey.com/forum/viewtopic.php?p=91578#91578 SKAN
  92. Loop {
  93. errorLevel := ( pointer+(A_Index-1) )
  94. Asc := *( errorLevel )
  95. IfEqual, Asc, 0, Break ; Break if NULL Character
  96. String := String . Chr(Asc)
  97. }
  98. Return String
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement