Registry editing

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
carelvos
Posts: 19
Joined: Tue Jul 14, 2015 5:21 pm

Registry editing

Post by carelvos » Sat Aug 01, 2015 1:26 pm

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

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Registry editing

Post by AxWald » Sun Aug 02, 2015 12:56 pm

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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply