Need Help In Source Code, C++!

Okay!  I need the source code for restarting the computer when the program loads.

I got some code in the file already, but when everything is operated I need it to restart/shutdown the computer.  How would I go about doing this?  Thx!
-Worth 50 Points

I also need help with something else, when the program loads, I need it to add a registry entry but I don't know how to go about doing that.  If someone can give me the source code for adding registry entries, greatly appreciated.  Thx!
-Worth 50 Points

Who is Participating?
//Try this out

The program below works in TurboC (or MS C).  In some compilers, you
have to fold the address to 20 bits, but here the segment and offset
are separate.*/

#define MAGIC           0               /* for cold restart */
/* #define MAGIC           0x1234          /* for warm restart */

#define BOOT_SEG      0xffffL
#define BOOT_OFF      0x0000L
#define BOOT_ADR      ((BOOT_SEG << 16) | BOOT_OFF)

#define DOS_SEG            0x0040L
#define RESET_FLAG      0x0072L
#define RESET_ADR      ((DOS_SEG << 16) | RESET_FLAG)

      void ((far *fp)()) = (void (far *)()) BOOT_ADR;

      *(int far *)RESET_ADR = MAGIC;
      return 0;      /* never gets here, but keeps compiler happy */

//Let me know if it works
Regarding shutting the machine down, you say you have got code already to do this.  It should resemble something like that shown at in C++.  If you want this code to be executed on machine startup, all you need to do is put this code in an EXE then get the EXE to run at startup via a shortcut to the startup group under the start menu or similar.

Regarding the registry side of things, you need to look at the functions given at  As an example, you can alter the wallpaper currently being displayed by using this code:

HKEY  hkey2;
char lpdata[] = "A_picture.bmp";

RegCreateKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop",

RegSetValueEx (hkey2, "Wallpaper", 0, REG_SZ, (LPBYTE) lpdata, sizeof(lpdata));  

RegCreateKeyEx will create the stated key, or if it is already in existance, open it.  In order to set a value to a key, you must open it first.  RegSetValueEx then sets the value of the key Wallpaper in HKEY_CURRENT_USER\Control Panel\Desktop to A_picture.bmp

You should be able to figure out how to add an entry to the section of the registry responsible for getting an app to start automatically; tip: it is HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run...

depends which compiler u r using
in VC++ u can use InitiateSystemShutdown
And the other one i gave runs quiet well in pure dos not in TurboC
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

// this code runs  well in puredos, if u can get some help  from it
#define reboot 0x19
void rebootpc()

union REGS inregs,outregs;
int86(reboot, &inregs, &outregs); // Call BIOS
void main()

mannujam: that is some interesting stuff !  Where did you learn how to do that ?!
XygusAuthor Commented:
Well, your asnwer was great, thou I had to make a few changes cause I was using a different compiler called Dev C++, but after all it was a good comment and it works great.  The first reply that I had to this questioned at first thought it was the answer I needed, but then I seen your reply and it was just what I was expecting from this question when I first asked it.

Thxs alot!

-Cause only one of my questions was answered, I have only awarded 50 points.

>> Cause only one of my questions was answered, I have only awarded 50 points.

What do think I was talking about in my first post RE: RegSetValueEx ???
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.