Problem using reg.exe

This is a discussion on Problem using reg.exe within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm trying to make a program (in C) that performs certain tweaks within windows. Here's an extract that sets ...

  1. #1
    Registered User *Tom*'s Avatar
    Join Date
    Oct 2005
    Location
    England
    Posts
    7

    Problem using reg.exe

    Hi, I'm trying to make a program (in C) that performs certain tweaks within windows. Here's an extract that sets the interval time between windows update reboot nags

    Code:
    char command[256];
    int interval = 1440;
    
    system("reg add HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU /v RebootRelaunchTimeoutEnabled /t REG_DWORD /d 00000001 /f");
    sprintf(command, "reg add HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU /v RebootRelaunchTimeout /t REG_DWORD /d %08x /f", interval);
    system(command);
    the output I get is:

    The operation completed successfully
    Error: Invalid command-line parameters

    I can't work out why the second command is invalid.
    Also... I'd rather not have the output printed on the screen, would this be the right way to do it? :

    system("@echo off\n...second command...");

    Thanks for any advice

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    you didnt include an end of line marker or zero termination. add "\n\0" to the end of the sprintf string and you should be fine.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    ...and using system() instead of REG apis is horrible.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    ...and using system() instead of REG apis is horrible.
    It will behoove you to learn the Windows API's if you plan on writing code for the Windows environment. It'll make life a lot easier in the long run.

    Code:
    Code:
    #pragma comment( lib, "advapi32.lib" )
    #include <windows.h>
    #include <stdio.h>
    
    int main(void)
    {
    	HKEY hk; 
    	DWORD dwData, dwDisp; 
    	char szKey[] = {"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU"};
    
    	dwData = 1;
    	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 
    		0, NULL, REG_OPTION_NON_VOLATILE,
    		KEY_WRITE, NULL, &hk, &dwDisp)) 
    		printf("Could not create (open) the szKey registry key."); 
    	else
    	{
    		if (RegSetValueEx(hk,      // subkey handle 
    			"RebootRelaunchTimeoutEnabled",  // value name 
    			0,                 // must be zero 
    			REG_DWORD,         // value type 
    			(LPBYTE) &dwData,  // pointer to value data 
    			sizeof(DWORD)))    // length of value data 
    			printf("Could not set RebootRelaunchTimeoutEnabled."); 
    		dwData = 1440;
    		if (RegSetValueEx(hk,      // subkey handle 
    			"RebootRelaunchTimeout",  // value name 
    			0,                 // must be zero 
    			REG_DWORD,         // value type 
    			(LPBYTE) &dwData,  // pointer to value data 
    			sizeof(DWORD)))    // length of value data 
    			printf("Could not set RebootRelaunchTimeout."); 
    		RegCloseKey(hk);    
    	}
    	return 0;
    }

  5. #5
    Registered User *Tom*'s Avatar
    Join Date
    Oct 2005
    Location
    England
    Posts
    7

    Thumbs up

    Hi, thanks for your help. I sort of knew using system() was probably a bad way of doing it, but I didn't know any better way. I tried using your example code and it worked fine... so I'll stick to that method in future.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21