April 29, 2024, 10:34:57 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Registry operations

Started by carpman2007, January 11, 2007, 06:50:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

carpman2007

Hi everyone,

Could somebody please post some sample Emergence Basic code that performs all of the normal Windows Registry operations (the whole gamut -- creating and deleting keys, setting and retrieving values, determining how many keys and folders there are, etc.)?

Thanks.  :-)

mrainey

Here's a Registry Pak written for IBPro (not by me, I've forgotten the author's name)  Hopefully you'll be able to work with it.


http://mrainey.freeservers.com/Downloads/RegistryPak.zip
Software For Metalworking
http://closetolerancesoftware.com

mrainey

Just for the record, the author's name is Troy Marker.  He wrote a number of paks for IBPro.  Thanks, Troy.
Software For Metalworking
http://closetolerancesoftware.com

carpman2007

Thank you very much.  I'll be sure to play around with it to see if I can get it to work.

Ionic Wind Support Team

You won't be able to use it directly, but if it contains the source code you should be able to compile it in Emergence.
Ionic Wind Support Team

Copex

hi

the registry comand pack was bulit from this, from the old fourms.


'Registry.inc

/*
Save this as 'Registry.inc' in your include folder, then to use it, type
$include "Registry.inc"
at the beginning of your code.

Functions are as follows:

RegGetValue(Key,<ValueName>) - returns the value in the registry at the 'Key' position, in the ValueName category
Example: strA=RegGetValue("HKEY_CURRENT_USER\\Software\\Andrew\\Stuff")
Leave ValueName blank to return the (default) value
Returns: the string, or a blank string if errored

RegSetValue(Key,Value,<ValueName>) - sets the value at the 'key' position, in the ValueName category
Creates the key if it's not there
Example: RegSetValue("HKEY_CURRENT_USER\\Software\\Andrew\\Stuff","Value")
Leave ValueName blank to set the (default) value
Returns: 0 if successful, or non-zero if failed

RegCreateKey(Key) - Creates a registry key
Example: RegCreateKey("HKEY_CLASSES_ROOT\\.bin\\ShellEx\\Something")
Returns: 0 if successful, or non-zero if failed

RegDeleteKey(Key) - Deletes a registry key
Example: RegDeleteKey("HKEY_CLASSES_ROOT\\.bin\\ShellEx\\Something")
Returns: 0 if successful, or non-zero if failed
*/
   DECLARE IMPORT,RegOpenKeyExA(hkey  as Uint,subkey as string,options  as int,security  as int,result as pointer),INT
   DECLARE IMPORT,RegQueryValueExA(hkey as Uint,valuename as string,reserved  as pointer,typ as pointer,keyvalue as pointer,size as pointer),INT
   DECLARE IMPORT,RegCloseKey(hkey  as Uint),INT
   DECLARE IMPORT,RegCreateKeyExA(hKey AS INT,lpSubKey AS STRING,Reserved AS INT,lpClass AS STRING,dwOptions AS INT,samDesired AS INT,lpSecurityAttributes AS int,phkResult AS INT BYREF,lpdwDisposition AS INT BYREF),INT
   DECLARE IMPORT,RegDeleteKeyA(hKey AS Uint,SubKey AS STRING),INT
   DECLARE IMPORT,RegSetValueExA(hKey AS INT,lpValueName AS STRING,Reserved AS INT,dwType AS INT,lpData AS POINTER,cbData AS INT),INT
   SETID "HKEY_CLASSES_ROOT", 0x80000000
   SETID "HKEY_CURRENT_USER", 0x80000001
   SETID "HKEY_LOCAL_MACHINE", 0x80000002
   SETID "HKEY_USERS", 0x80000003
   SETID "HKEY_PERFORMANCE_DATA",0x80000004
   SETID "HKEY_CURRENT_CONFIG", 0x80000005
   SETID "HKEY_DYN_DATA", 0x80000006
   SETID "KEY_ALL_ACCESS", 63
   SETID "REG_SZ",1
   SETID "REG_BINARY", 3
   SETID "REG_DWORD", 4   

Sub GetRoot(Key as string),UInt
   'Internal - returns the root folder from the passed string
   string rf
   UInt retval
   retval=0
   'Split the root folder from the key
   rf=left$(Key,instr(Key,"\\")-1)
   select rf
      case "HKEY_CLASSES_ROOT"
         retval= @HKEY_CLASSES_ROOT
      case "HKEY_CURRENT_USER"
         retval=@HKEY_CURRENT_USER
      case "HKEY_LOCAL_MACHINE"
         retval=@HKEY_LOCAL_MACHINE
      case "HKEY_USERS"
         retval=@HKEY_USERS
      case "HKEY_PERFORMANCE_DATA"
         retval=@HKEY_PERFORMANCE_DATA
      case "HKEY_CURRENT_CONFIG"
         retval=@HKEY_CURRENT_CONFIG
      case "HKEY_DYN_DATA"
         retval=@HKEY_DYN_DATA
   endselect
   return retval
EndSub

Sub RegGetValue(Key as string,opt ValueName as string),string
   'Returns a registry value or blank string if errored
   'strA=RegGetValue("HKEY_CURRENT_USER\\Software\\Andrew\\File","First")
   'Leave out the ValueName to retrieve the default value
   string retval,rf,ky
   UInt root,ret,ln,typ
   int getdw
   retval=""
   ln=255
   'Split the root folder from the key
   rf=left$(Key,instr(Key,"\\")-1)
   ky=right$(Key,len(Key)-1-len(rf))
   'Get the value
   if RegOpenKeyExA(GetRoot(Key),ky,0,@KEY_ALL_ACCESS,ret) = 0
      RegQueryValueExA(Ret,ValueName,NULL,typ,retval,ln)
      if typ=4:'Dword
         ln=4
         RegQueryValueExA(Ret,ValueName,NULL,typ,getdw,ln)
         retval=str$(getdw)
      endif
   endif
   RegCloseKey(ret)
   return retval
EndSub

Sub RegSetValue(Key as string,Value as string,opt ValueName as string),int
   'Sets a value in the key
   'Result=RegSetValue("HKEY_CURRENT_USER\\Software\\Andrew\\File","First","12")
   'Leave out the ValueName to set the (default) value
   'if the key doesn't exist, creates it first
   'returns 0 for no error, 1 for error
   string rf,ky
   UInt root,ret,ln,typ
   int retval,tmp
   retval=0
   tmp=0
   ln=255
   'Split the root folder from the key
   rf=left$(Key,instr(Key,"\\")-1)
   ky=right$(Key,len(Key)-1-len(rf))
   'Create the key and get a handle
   RegCreateKeyExA(GetRoot(Key),ky,0,"",0,@KEY_ALL_ACCESS,0,ret,tmp)
   'Set the value
   tmp=0
   ln=len(value)+1
   retval=RegSetValueExA(ret,ValueName,tmp,@REG_SZ,Value,ln)
   RegCloseKey(ret)
   return retval
EndSub

Sub RegSetDWValue(Key as string,Value as int,opt ValueName as string),int
   'Sets a Dword value in the key
   'Result=RegSetDWValue("HKEY_CURRENT_USER\\Software\\Andrew\\File",123457,"12")
   'Leave out the ValueName to set the (default) value
   'if the key doesn't exist, creates it first
   'returns 0 for no error, 1 for error
   string rf,ky
   UInt root,ret,ln,typ
   int retval,tmp
   retval=0
   tmp=0
   ln=255
   'Split the root folder from the key
   rf=left$(Key,instr(Key,"\\")-1)
   ky=right$(Key,len(Key)-1-len(rf))
   'Create the key and get a handle
   RegCreateKeyExA(GetRoot(Key),ky,0,"",0,@KEY_ALL_ACCESS,0,ret,tmp)
   'Set the value
   tmp=0
   ln=4
   retval=RegSetValueExA(ret,ValueName,tmp,@REG_DWORD,Value,ln)
   RegCloseKey(ret)
   return retval
EndSub

Sub RegCreateKey(Key as string),int
   'Creates a registry key
   'Result=RegCreateKey("HKEY_CURRENT_USER\\Software\\Andrew\\File")
   'Returns 0 for no error, non-zero for error
   string rf,ky
   UInt root,ret
   int retval,tmp
   tmp=0
   ln=255
   'Split the root folder from the key
   rf=left$(Key,instr(Key,"\\")-1)
   ky=right$(Key,len(Key)-1-len(rf))
   'Create the key and get a handle
   retval=RegCreateKeyExA(GetRoot(Key),ky,0,"",0,@KEY_ALL_ACCESS,0,ret,tmp)
   RegCloseKey(ret)
   return retval
EndSub

Sub RegDeleteKey(Key as string),int
   'Deletes a registry key
   'Result=RegDeleteKey("HKEY_CURRENT_USER\\Software\\Andrew\\File")
   'Returns 0 for no error, non-zero for error
   string rf,ky
   int retval
   'Split the root folder from the key
   rf=left$(Key,instr(Key,"\\")-1)
   ky=right$(Key,len(Key)-1-len(rf))
   retval=RegDeleteKeyA(GetRoot(Key),ky)
   return retval
EndSub
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

carpman2007

So far I haven't been able to get the command pak to work, however I was able to achieve some success with the Registry.inc include file.

Thanks again.

Raid

Thank you very much for posting the registry source! I've been looking for days on accessing the registry so I could write myself a quick and dirty policy key editor. LoL.
Proudly licensed EBASIC owner since Feb 2009. Network library present!