PDA

View Full Version : Qt 4 Registry regedit



bunjee
7th May 2008, 16:35
Hey there trolls,

I'd like to execute a windows registry command at my Qt program startup ?

Anybody ever did that ?

Thanks.

wysota
7th May 2008, 17:23
Could you elaborate? A trivial solutions seems to be to read the command from the registry using QSettings and execute it using QDesktopServices. Or maybe I understood your problem incorrectly?

bunjee
7th May 2008, 17:54
I want to run the equivalent for that .reg file:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\xmpp]
@="URL:XMPP Protocol"
"EditFlags"=dword:00000002
"URL Protocol"=""
[HKEY_CLASSES_ROOT\xmpp\shell]
[HKEY_CLASSES_ROOT\xmpp\shell\open]
[HKEY_CLASSES_ROOT\xmpp\shell\open\command]
@="<application to execute> %l"

I'm not sure if I do create the reg file and execute it, or if I can adopt a more straightforward approach.

As you suggested, I'll take a look at QDesktopServices.

stevey
8th May 2008, 23:33
Your intention is still a little vague.
If what you mean is to apply the value in the .reg file as if you had double-clicked the file in Windows Explorer, you could could probably get away with QDesktopServices::openUrl, but another option is to use QSettings adding each value in c++ code.

QSettings is an ini file and registry reader / writer.
You could create a registry version of QSettings and call setValue specifying the hive key and value to insert.

I'd say the QDesktopServices approach is preferable as you cold modify the .reg file easier.
If you wanted to keep things in a text file and use QSettings, then for simplicity you'd need to re-arrange your reg into an ini file format, access the ini file with one QSettings object for reading the values, then use another QSettings object for writing to the registry.

bunjee
10th May 2008, 02:41
QDesktopServices::openUrl(QUrl::fromLocalFile("ZeMessenger.reg"))

Doesn't work.

I need to execute a regedit file with every instance of my app.

wysota
10th May 2008, 08:38
Use system() with regedit.exe or QProcess with regedit.exe or insert the information into the registry using QSettings. And try expressing your goals more clearly next time - I though you wanted to do something completely different.

bunjee
10th May 2008, 10:38
Sorry if I didin't sound clear.


QString program = "C:\\Windows\\regedit.exe";
QStringList arguments;
arguments << "/S" << "ZeMessenger.reg";

QProcess myProcess;
myProcess.start(program, arguments);

if (!myProcess.waitForStarted())
{
return false;
}

That code returns false. I'm affraid I need administrator rights to do such a command. I guess the only alternative to add regs field silently is during the installation.

stevey
10th May 2008, 11:53
For starters, you don't actually need to launch regedit as the association for .reg is to open regedit, although that won't fix your problem.

If you can't run .reg files, then chances are you won't be able to modify the registry keys even with QSettings. If this is a work machine that's locked down, then request permission to get your job done, otherwise if it's a personal machine, add yourself to the Administrators group.