I'm having trouble with GetRegKey(). When I try to compile, I'm getting the error:
GetRegKey() is not a function, an array, or a linked list.
Any help would be appreciated
Cheers,
Jim
Seems you dont have any lib installed, that support the command GetRegKey()... Take a look to the tips and tricks sections and search for something like "GetVersion FireFox" ... there are proecdures to Get the Registry values!Jimbo_H wrote:Hi,
I'm having trouble with GetRegKey(). When I try to compile, I'm getting the error:
GetRegKey() is not a function, an array, or a linked list.
Any help would be appreciated
Cheers,
Jim
Hi,PB wrote:> when I searched the forum it says this command was added to PB in 3.91
It wasn't. What did you search for that shows this? No PureBasic version
has native Registry commands in it.

Code: Select all
;info: Read and change the Registry / FileAssociate
Procedure Reg_SetValue(topKey, sKeyName.s, sValueName.s, vValue.s, lType, ComputerName.s)
lpData.s
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbData = 255
lpData = Space(255)
Select lType
Case #REG_SZ
GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1)
Case #REG_DWORD
lValue = Val(vValue)
GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4)
EndSelect
RegCloseKey_(hKey)
ergebnis = 1
ProcedureReturn ergebnis
Else
MessageRequester("Fehler", "Ein Fehler ist aufgetreten", 0)
RegCloseKey_(hKey)
ergebnis = 0
ProcedureReturn ergebnis
EndIf
EndProcedure
Procedure.s Reg_GetValue(topKey, sKeyName.s, sValueName.s, ComputerName.s)
lpData.s
GetValue.s =""
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbData = 255
lpData = Space(255)
GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)
If GetHandle = #ERROR_SUCCESS
Select lType
Case #REG_SZ
GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)
If GetHandle = 0
GetValue = Left(lpData, lpcbData - 1)
Else
GetValue = ""
EndIf
Case #REG_DWORD
GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lpType, @lpDataDWORD, @lpcbData)
If GetHandle = 0
GetValue = Str(lpDataDWORD)
Else
GetValue = "0"
EndIf
EndSelect
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn GetValue
EndProcedure
Procedure.s Reg_ListSubKey(topKey, sKeyName.s, Index, ComputerName.s)
lpName.s
lpftLastWriteTime.FILETIME
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbName = 255
lpName = Space(255)
GetHandle = RegEnumKeyEx_(hKey, Index, @lpName, @lpcbName, 0, 0, 0, @lpftLastWriteTime)
If GetHandle = #ERROR_SUCCESS
ListSubKey.s = Left(lpName, lpcbName)
Else
ListSubKey.s = ""
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn ListSubKey
EndProcedure
Procedure Reg_DeleteValue(topKey, sKeyName.s, sValueName.s, ComputerName.s)
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
GetHandle = RegDeleteValue_(hKey, @sValueName)
If GetHandle = #ERROR_SUCCESS
DeleteValue = #True
Else
DeleteValue = #False
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn DeleteValue
EndProcedure
Procedure Reg_CreateKey(topKey, sKeyName.s, ComputerName.s)
lpSecurityAttributes.SECURITY_ATTRIBUTES
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegCreateKeyEx_(topKey, sKeyName, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, @lpSecurityAttributes, @hNewKey, @GetHandle)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegCreateKeyEx_(lhRemoteRegistry, sKeyName, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, @lpSecurityAttributes, @hNewKey, @GetHandle)
EndIf
If GetHandle = #ERROR_SUCCESS
GetHandle = RegCloseKey_(hNewKey)
CreateKey = #True
Else
CreateKey = #False
EndIf
ProcedureReturn CreateKey
EndProcedure
Procedure Reg_DeleteKey(topKey, sKeyName.s, ComputerName.s)
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegDeleteKey_(topKey, @sKeyName)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegDeleteKey_(lhRemoteRegistry, @sKeyName)
EndIf
If GetHandle = #ERROR_SUCCESS
DeleteKey = #True
Else
DeleteKey = #False
EndIf
ProcedureReturn DeleteKey
EndProcedure
Procedure.s Reg_ListSubValue(topKey, sKeyName.s, Index, ComputerName.s)
lpName.s
lpftLastWriteTime.FILETIME
ListSubValue.s
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbName = 255
lpName = Space(255)
GetHandle = RegEnumValue_(hKey, Index, @lpName, @lpcbName, 0, 0, 0, 0)
If GetHandle = #ERROR_SUCCESS
ListSubValue = Left(lpName, lpcbName)
Else
ListSubValue = ""
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn ListSubValue
EndProcedure
Procedure.b Reg_KeyExists(topKey, sKeyName.s, ComputerName.s)
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
KeyExists = #True
Else
KeyExists = #False
EndIf
ProcedureReturn KeyExists
EndProcedure
Procedure Reg_DeleteKeyWithAllSub(topKey,sKeyName.s,ComputerName.s)
i=0
a$=""
Repeat
b$=a$
a$=Reg_ListSubKey(topKey,sKeyName,0,"")
If a$<>""
Reg_DeleteKeyWithAllSub(topKey,sKeyName+"\"+a$,"")
EndIf
Until a$=b$
Reg_DeleteKey(topKey, sKeyName, ComputerName)
EndProcedure
Procedure Reg_CreateKeyValue(topKey,sKeyName.s,sValueName.s,vValue.s,lType,ComputerName.s)
Reg_CreateKey(topKey,sKeyName,ComputerName)
ProcedureReturn Reg_SetValue(topKey,sKeyName,sValueName,vValue,lType,ComputerName)
EndProcedure
Procedure AssociateFileEx(ext$,ext_description$,programm$,icon$,prgkey$,cmd_description$,cmd_key$)
cmd$=Chr(34)+programm$+Chr(34)+" "+Chr(34)+"%1"+Chr(34)
If GetVersion_() & $FF0000 ; Windows NT/XP
Reg_CreateKeyValue(#HKEY_CLASSES_ROOT, "Applications\"+prgkey$+"\shell\"+cmd_description$+"\command","",cmd$,#REG_SZ,"")
If ext_description$
Key$=ext$+"_auto_file"
Reg_CreateKeyValue(#HKEY_CLASSES_ROOT ,"."+ext$ ,"",Key$ ,#REG_SZ,"")
Reg_CreateKeyValue(#HKEY_CLASSES_ROOT ,Key$ ,"",ext_description$,#REG_SZ,"")
If icon$
Reg_CreateKeyValue(#HKEY_CLASSES_ROOT,Key$+"\DefaultIcon","",icon$ ,#REG_SZ,"")
EndIf
EndIf
Reg_CreateKeyValue(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"Application",prgkey$,#REG_SZ,"")
Else ;Windows 9x
Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE ,"Software\Classes\."+ext$ ,"",prgkey$ ,#REG_SZ,"")
If ext_description$
Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$ ,"",ext_description$,#REG_SZ,"")
EndIf
If icon$
Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\DefaultIcon" ,"",icon$ ,#REG_SZ,"")
EndIf
If cmd_description$<>cmd_key$
Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$,"",cmd_description$,#REG_SZ,"")
EndIf
Reg_CreateKeyValue(#HKEY_LOCAL_MACHINE ,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$+"\command","",cmd$,#REG_SZ,"")
EndIf
EndProcedure
Procedure Remove_AssociateFile(ext$,prgkey$)
If GetVersion_() & $FF0000 ; Windows NT/XP
Reg_DeleteKeyWithAllSub(#HKEY_CLASSES_ROOT,"Applications\"+prgkey$,"")
Key$=ext$+"_auto_file"
Reg_DeleteKeyWithAllSub(#HKEY_CLASSES_ROOT,"."+ext$,"")
Reg_DeleteKeyWithAllSub(#HKEY_CLASSES_ROOT,Key$,"")
Reg_DeleteKeyWithAllSub(#HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"")
Else ;Windows 9x
Reg_DeleteKeyWithAllSub(#HKEY_LOCAL_MACHINE ,"Software\Classes\."+ext$,"")
Reg_DeleteKeyWithAllSub(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$,"")
EndIf
EndProcedure
Procedure AssociateFile(ext$,ext_description$,programm$,icon$)
AssociateFileEx(ext$,ext_description$,programm$,icon$,GetFilePart(programm$),"open","open")
EndProcedure 