Hi Everyone,
I hope someone can help me with this, as I have searched for this, puzzled over it and i'm sure that i am missing something silly as i am just not getting this at all.
I want to simply delete a registry value - for example a dword called "a"
The registry location is HKCU\software\microsoft\Windows\CurrentVersion\Explorer\Advanced
Now i'm trying bits of code but i need help from someone out with a greater mind than mine !
I Tried this but to be honest I really don't understand it as i'm new to using the declare function - 
DEF Key:string 
DEF ret:INT
DEF subkey,bk$:string 
INT hKey
INT phkResult
bk$ = CHR$(92)
DECLARE "advapi32.dll",RegOpenKeyEx alias RegOpenKeyExA(hKey:INT, lpSubKey:STRING, ulOptions:INT, samDesired:INT, phkResult:POINTER),INT
DECLARE "advapi32.dll",RegDeleteValue alias RegDeleteValueA(hKey:INT, lpValueName:STRING),INT
CONST HKEY_CURRENT_USER = 0x80000001
CONST KEY_ALL_ACCESS = 63
subkey = "SOFTWARE"+bk$+"MICROSOFT"+bk$+"WINDOWS"+bk$+"CurrentVersion"+bk$+"Explorer"+bk$+"Advanced"
key = "HKEY_CURRENT_USER"+bk$+subkey
ret=RegOpenKeyEx(HKEY_CURRENT_USER, SubKey, 0, KEY_ALL_ACCESS, &phkResult)
result = RegDeleteValue(hKey, "a")
OPENCONSOLE
PRINT subkey
PRINT "ret    = ",ret 
PRINT "result = ",result
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
ret returns a zero
result returns '6'
HELP please
Andy.
			
			
			
				This should be all you need
openconsole
const REG_KEY = "HKEY_CURRENT_USER\\Software\\microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"
print "before ",RegGetDword(REG_KEY,"a",999)
DeleteRegKey(REG_KEY+"\\a")
print "after ",RegGetDword(REG_KEY,"a",999)
print
PRINT "Press any key to close"
waitcon
CLOSECONSOLE
END
 
LarryMc
			
			
			
				Hi Larry,
Thanks very much for trying to help me so quickly as i can see you have a puzzle of your own.
The example you gave me won't work because i have been using the old registry.inc file, thats great but you cannot delete a value.
This is why i was trying to write something using a DECLARE function but i can't get my head round it as i'm new to these commands, I really wish i had an answer for your problem and i'll have a look at it later today.
Thanks,
Andy.
			
			
			
				What I gave you was the built in commands in EBasic.
Larry
			
			
			
				I see what you mean.
The built in will delete a whole key but not the sub components.
LarryMc
			
			
			
				Larry,
Thanks again but it doesn't even like the 'waitcon' command, but thanks for trying anyway.
Andy.
			
			
			
				Quotekey = "HKEY_CURRENT_USER"+bk$+subkey
you are filling the variable 'key' here
Quoteresult = RegDeleteValue(hKey, "a")
but are passing the variable 'hKey' to the function. 
			
 
			
			
				Quote from: andy1966 on March 08, 2010, 07:29:47 AM
Larry,
Thanks again but it doesn't even like the 'waitcon' command, but thanks for trying anyway.
Andy.
What version of EBasic do you have?
LarryMc
			
 
			
			
				The phkresult from the RegOpenKeyEx function can be used for the hKey in the RegDeleteValue function. 
			
			
			
				SOLVED !
Thanks for everyone's help, here it is tested and working.
DEF dwValue AS INT
DEF result:INT
DEF SubKey:string 
DEF key:INT
DEF hKey:INT
DEF phkResult:INT
DEF res:INT
DEF res2:INT
DEF value:string 
'Need To Use The advapi32.dll to Delete a Registry Value
DECLARE "advapi32.dll",RegDeleteValue alias RegDeleteValueA(hKey:INT, lpValueName:STRING),INT
DECLARE "advapi32.dll",RegOpenKeyEx alias RegOpenKeyExA(hKey:INT, lpSubKey:STRING, ulOptions:INT, samDesired:INT, phkResult:POINTER),INT
DECLARE "advapi32.dll",RegCloseKey(hKey:INT),INT 'Delete This Line if you want to use Registry.inc File as well.
'Define The Constants
CONST HKEY_CLASSES_ROOT = 0x80000000 
CONST HKEY_CURRENT_USER = 0x80000001 
CONST HKEY_LOCAL_MACHINE = 0x80000002 
CONST HKEY_USERS = 0x80000003 
CONST KEY_ALL_ACCESS = 63 
'Set the Registry Key Location
key = HKEY_CURRENT_USER 'Integer Value 0x80000001 
SubKey="SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" 'SubKey is a string 
'Need To Open The Registry Key Location First otherwise we cannot delete a value in that key. 
res = RegOpenKeyEx(key,SubKey,0,KEY_ALL_ACCESS,&phkResult)
'Console For Confirmation & Testing if the key location opened ok.
OPENCONSOLE
IF res = 0 
PRINT "The Key Opened OK"  'res = 0
ELSE
PRINT "Could Not Open Key" 'res <> 0
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
ENDIF
DO:UNTIL INKEY$ <> ""
'Name The Registry Value we want to delete then Delete it
'========================================================
value = "a" 'Name of Value To Delete - Any Type e.g. Dword, String Etc
result = RegDeleteValue(phkResult,value)
PRINT
PRINT
IF result = 0
PRINT "The Registry Value Was Deleted OK"
ELSE
PRINT "Could Not Delete The Value"
ENDIF
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
'You can now delete more values in the same registry key location.
value = "b"
result = RegDeleteValue(phkResult,value)
value = "c"
result = RegDeleteValue(phkResult,value)
'Once Finished with Registry Location Close The Key. 
res2 = RegCloseKey(key)
'result = 0 if the value is deleted ok
'res2   = 0 if the key was closed ok 
'====================================================================
'NOTE
'====================================================================
'If you want to delete a value from another location 
'don't forget to change the location values first
'and open the new Key. 
'Set the Registry Key Location
'key = HKEY_CURRENT_USER  
'SubKey="SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"  
'Open The Registry Key Location  
'res = RegOpenKeyEx(KEY,SubKey,0,KEY_ALL_ACCESS,&phkResult)
'Set the Value, Delete and Close The Key.
'value = "x"
'result = RegDeleteValue(phkResult,value)
'res2   = RegCloseKey(key)
'====================================================================
'Hope This Helps Everyone - Andy.
'====================================================================
END
Regards Andy.
END