Page 1 of 1

GetRegKey() problem

Posted: Mon Jun 06, 2005 11:10 am
by Jimbo_H
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

Re: GetRegKey() problem

Posted: Mon Jun 06, 2005 11:16 am
by va!n
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
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!

Btw, you need a lib with its command or you have to include the so called procedure!

Posted: Mon Jun 06, 2005 11:22 am
by Jimbo_H
Hi,

I've reinstalled PB on my laptop and have had some problems with trying to work out which libraries I had before.

But, when I searched the forum it says this command was added to PB in 3.91, so it's not a library afaik as I can't find a library with this command.

Cheers,
Jim

Posted: Mon Jun 06, 2005 11:39 am
by PB
> 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.

Posted: Mon Jun 06, 2005 11:41 am
by Jimbo_H
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.
Hi,

Here's the forum post I found:
viewtopic.php?t=10605&highlight=getregkey

Damn, I'm sorry, I just noticed it's a wishlist, not a feature list!!! :oops:

Cheers,
Jim

Posted: Mon Jun 06, 2005 11:56 am
by Jimbo_H
Found it!!!

It's a library from Reelmedia called REGini_lib.
http://www.reelmedia.org/cgi-bin/PurePr ... es&sub=ASM

Sorry for all the confusion, I feel like a right plonker now. 8)

Cheers,
Jim

Posted: Mon Jun 06, 2005 1:27 pm
by va!n
no prob :)

Posted: Mon Jun 06, 2005 1:34 pm
by NoahPhense
Or rather than a lib, you can use:

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 
- np

Posted: Wed Jun 08, 2005 12:41 pm
by Jimbo_H
NoahPhense, thank you for the code. I'm going to have a proper look at it, but at first glance it's still a bit advanced for me :D

I've had PB for quite a long time, but am still very much a noob. I can't stop playing with PB though, it's so addictive once you start to grasp it!

Regards,
Jim

Posted: Wed Jun 08, 2005 10:50 pm
by NoahPhense
Yeah it's addictive.. ;)