views:

375

answers:

1

Hello everyone,

I'm having some problems of getting the following simple code to run correctly:

#include <process.h>

int main( void )
{
  system("foo.reg");               //why does this NOT WORK?!
  //system("reg import foo.reg");  //why does this NOT WORK?!
  //system("regedit \"foo.reg\""); //why does this NOT WORK?!
  return 0;
}

The registry file is located in the directory where the compiled executable is. foo.reg runs successfully when I run it from command line, but running the above program only shows the regedit confirmation window, and does no corresponding change in the registry itself.

I used Dev-C++ to write the program and I am running Windows XP x64 version SP2. Any help will be greatly appreciated.

+3  A: 

system("regedit /s foo.reg"); should import it silently without any confirmation dialogs. Refer here for command-line options of regedit.exe. However, I will be sceptical about the registry file (foo.reg) in question; check if it's correct. Also after running it, be sure if you're checking the right path in the registry which foo.reg is made to amend.

On a side note, system() function of the C Standard Library is declared in stdlib.h so it should be:

#include <stdlib.h>
int main()
{
    system("regedit /s foo.reg");
    return 0;
}

Edit:

I think the import is already successful; since you've mentioned that it's a 64-bit XP machine, I think the change will be lying under the Wow6432Node. E.g. HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node or HKEY_CURRENT_USER\SOFTWARE\Wow6432Node. So check under the Wow6432Node too. See this post and MSDN for more information on this.

legends2k
system("regedit /s foo.reg") was silent, but it didn't change anything in the registry, with the included "<stdlib.h>" added, too.And the registry file is correct; if I double click the file itself, it will prompt me to confirm, but after so it does update the registry.
Max H.
I looked up the Wow6432Node folder, but it didn't contain the registry files I'm updating...Could it be that in order to change registry files, I need to use other functions than system()?
Max H.
FYI, I am trying to edit information under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Max H.
@Max H: You can directly use the registry manipulation functions (http://msdn.microsoft.com/en-us/library/ms724875%28VS.85%29.aspx) if you know the changes the `.reg` file does to the registry.
legends2k