Page 1 of 1

Registry editing

Posted: Sat Aug 01, 2015 1:26 pm
by carelvos
I'm trying to add a key and value to the registry but it is not working.

I tried the following:

put shell("reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v aaa")
get setRegistry("HKLM\Software\Microsoft\Windows\CurrentVersion\Run", "aaa","dword")
put it

The shell part works when I execute it from a command prompt, but not from livecode.

Thanks,

Carel

Re: Registry editing

Posted: Sun Aug 02, 2015 12:56 pm
by AxWald
Hi,

finally had a look into this. At first, I exported a matching key on my Win7-64 machine. Interesting is, at first, that the data type isn't DWORD (like in your example) but a string (REG_SZ) - your "aaa" is the start argument for whatever to run.

The .reg file then reads:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Launch MyCode"="C:\\Program Files\\Future Software\\MyCode.exe /minimized"
So I tried to translate this into LiveCode:

Code: Select all

put setRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Launch MyCode","C:\\Program Files\\Future Software\\MyCode.exe /minimized")
Returns "false". Tried then some variations - using "\" instead of "\\" in the data, renaming the key name to "Launch_MyCode", no success.

Tried the .reg file manually. And whow, it needs to run as Admin! Head -> desk ...

Started LC now as Admin, and this code worked:

Code: Select all

put setRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Launch_MyCode","C:\Program Files\Future Software\MyCode.exe /minimized")
Only that it ended in:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run\, but that shouldn't matter.
Case closed. ;-)

A word of advice: Don't do such if you don't provide a proper uninstaller!
If your user deletes your stack, the reg entry will survive and will bother him at each startup ... At least give him a .reg file that deletes this reg entry!
I'd do it in another way:
  • At first start, offer the user to put your program into "Autostart", and
  • explain to him what you do, and
  • how to remove it later.
This is quite simple an operation and any user should be able to understand it.

Have fun!