Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Reboot..???? 2

Status
Not open for further replies.

shanlon

Technical User
Dec 4, 2000
24
0
0
IE
Does anyone out there know how to reboot a machine from within a program.
I just want to perform some basic task and then automatically reboot.. i don't need control to return to the calling function after reboot either.. just end the program and restart.
There is info in MSDN but this would take forever to wade through (well more time than i have at my disposal anyway),
so code would be good.. or even if someone knew what functions to call.
Any kind of input would be appreciated.

Using VisualC++ on Win2000.
thanks for your time
 
thanks.. i'll give it a try and see what happens.
 
Gorecki, i have tried using the above but with no result. The only parameter i have any success with is EWX_FORCE which results in logging out and loggin back on again automatically as the same user.
I printed out the error values and it seems that i don't have the privilege of using the other parameters.. do you know how i can change this.. i'm aware of the presence of the function AdjustTokenPrivileges but i don't even know how to get a handle to the token that contains the privileges...i need to get a handle to the Process first i think.. any suggestions?

I'm new to this stuff and there isn't a great deal i know about threads and tokens etc.
I presumed that because i was an administrator on the machine that i had all privileges available to me.

Once again, anything is helpful and thanks.

 
First off, I don't want to assume. It's 2000/NT 5, do you have 'Administrator' privilages on the system running your program? That would surely cause what you're experiencing. I haven't actually tried the API on 2000 so I'm not certain what's causing your problems. The only other elements I can think of is 'NT Security' you spoke of, if any, 'encryption' if any.

Calling GetLastError may help.

Brian

 
Shanlon,

Do you use the Microsoft Documentation? It's actually a very valuable resource. Here is the SDK's comment about EWX_REBOOT flag in the ExitWindowsEx() API:

EWX_REBOOT Shuts down the system and then restarts the system.
Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.


Good luck
-pete
 
Gorecki..(Brian),
i am logged on as the administrator while i run the program.
I have used the getlasterror function and it tells me that i do not have the proper privileges to reboot the machine.
I need to be an administrator for other parts of my app to work.
The OS used is Windows2000 Pro and there is no encryption involved at all.
I think i have to basically adjust the privileges but i haven't got an iota where to start.. any help!
 
Palbano.. thanks for your reply.
I have read the documentation on ExitWindowsEx API and it is pretty clear. I still get an error because i don't have neccessary privileges.

Like i replied to Gorecki, i think i have to adjust the users rights but this involves getting a handle to the token which i think involves getting a handle to the process and thread... all out of my league given the timeframe involved.

If you can give me a simple idea of what to do .. great!
If not.. thanks again for your reply.
Shane
 
Palbano.. that code looks just fine.
I'll give it a try and let you know what happens.

Thanks,
Shane.
 
Palbano's link is nice, but I do not read Visual Basic code and I can't "convert" it to Visual C++. Could someone please post some converted code for me? I hear that the function AdjustTokenPriviledges() is just what I need. But what in the world is all this stuff? And where in my code should I even call this function?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top