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

XygusAsked:
Who is Participating?
 
mannujamCommented:
//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)

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

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


//Let me know if it works
0
 
mrwad99Commented:
Regarding shutting the machine down, you say you have got code already to do this.  It should resemble something like that shown at http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20413564.html 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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regcreatekeyex.asp.  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",
            0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);

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...

HTH
0
 
mannujamCommented:
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
0
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.

 
mannujamCommented:
// this code runs  well in puredos, if u can get some help  from it
#include<dos.h>
#define reboot 0x19
void rebootpc()

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


{
rebootpc();
}
0
 
mrwad99Commented:
mannujam: that is some interesting stuff !  Where did you learn how to do that ?!
0
 
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.

0
 
mrwad99Commented:
>> 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 ???
0
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.