Win32 - registry

BlitzMax Forums/BlitzMax Programming/Win32 - registry

Hi,
I've found this Registry Module source to access the Windows registry.
It works well, but I have a little problem when accessing some keys.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

If I try to access the key PATH (its type is REG_EXPAND_SZ - dont' ask me why is not a simple string...) I got a void string. And this is not a good thing.


Can someone explain me how to change the code to read the path (or the Reg_Expand_sz variables)?

My idea is read (with this key) the system path, modify it and then save-write it again to the registry.
Unless there's another way to change permanentely the path...I mean not manually - via software.

This is the last (and of course the most important - Murphy's law...) part of my program.

Thanks.

If i recall you need to access the environment registry keys using api SHGetValue(), i would also suggest a look at SHSetValue()

kev

From what Google tells me, the reason why this is a REG_EXPAND_SZ string probably is simple: It can use environment variables.

It is also null terminated, which might be another difference to REG_SZ.

You will probably also run into permission problems; only administrators are allowed to change that registry value (you can verify this with REGEDT32.EXE instead of REGEDIT.EXE).

Thanks to all, but I think I've resolved pointing my attention on the REG.EXE program that comes with WindowXP (NT a Windows 2000 need to download).

Local qu$=Chr(34)
'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Local res$ =DoProcess("reg.exe query "+qu$+"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"+qu+" /v path") 

Local pos:Int = res.find(":") -1
Local path$ = res[pos..]
Local newpath$ = path$ + ";C:\programmi\subversion\bin"
Print "Path: " + path
Print "New Path:" + newpath
Print
Print DoProcess("reg.exe add " + qu + "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" + qu + " /v path /t REG_EXPAND_SZ /d " + newpath+" /f") 
End
Function DoProcess$(cmd$ , hide:Int = HIDECONSOLE) 
		Local	process:TProcess
		Local	bytes:Byte[] , result$,temp_read$
		process = CreateProcess(cmd$ , hide) 
		If process
			While True
				Repeat
					temp_read  = process.pipe.ReadLine()
					result = result + temp_read
					If PeekEvent() WaitEvent() 
				Until process.pipe.bufferpos<=0
				If Not process.status() Exit				
				Delay 10
				If PeekEvent() WaitEvent() 
			Wend
		EndIf
		Return result
End Function


Well, it works!

I need to check 'strange paths' with spaces but I think I found a workaround - until I figure out how to change/use the Registry library.