Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need Help In Source Code, C++!

Posted on 2004-10-30
7
Medium Priority
?
491 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:Xygus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 12453361
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
 
LVL 2

Accepted Solution

by:
mannujam earned 200 total points
ID: 12480762
//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
 
LVL 2

Expert Comment

by:mannujam
ID: 12481119
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:mannujam
ID: 12481198
// 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
 
LVL 19

Expert Comment

by:mrwad99
ID: 12481824
mannujam: that is some interesting stuff !  Where did you learn how to do that ?!
0
 

Author Comment

by:Xygus
ID: 12692540
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
 
LVL 19

Expert Comment

by:mrwad99
ID: 12693809
>> 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Make the most of your online learning experience.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question