Gossamer Forum
Home : General : Perl Programming :

Shut Down

Quote Reply
Shut Down
Not really to do with CGI, but I was wondering if anyone knew and answer to this Wink

I'm trying to work out some C++ code that will enable me to shut down a computer without going through the normal shut down procedure. The reason for wanting to do this is to simulate a power-cut/brown-out. We are trying to test the stability of our software with un-predicted power loss to the server.

Any ideas on some code for this?

Thanks

Andy
Quote Reply
Re: [AndyNewby] Shut Down In reply to
I'm not quite sure what you are trying to achieve but anyway.....

system("rundll32 shell32.dll,SHExitWindows 1");

Surely the software programmer would have known that?

Last edited by:

RedRum: Oct 8, 2001, 9:49 AM
Quote Reply
Re: [AndyNewby] Shut Down In reply to
There's more complexed code freely available anywhere on the net.....

Code:
bool ShutdownSystem(unsigned int uFlags)


{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
bool bOkShutdown;
OSVERSIONINFO osv;
const char szShutdown[] = "SeShutdownPrivilege";
osv.dwOSVersionInfoSize=sizeof(osv);
GetVersionEx(&osv);



if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT) {


if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken) ) {
LookupPrivilegeValue("",szShutdown, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bOkShutdown = (AdjustTokenPrivileges(hToken,0,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0)!=0);
}
}


else {
bOkShutdown=true;
}


if(bOkShutdown) {
return (ExitWindowsEx(uFlags,0)!=0);
}
return false;
}
Quote Reply
Re: [RedRum] Shut Down In reply to
I'm not sure that the code you gave did what we want. Basically, we want an uncontrolled shutdown, to simulate a power cut or such. This is to test how it works after random restarts (its an audio recorder, so we dont want it to mess up). We really need a complete shut down, without having to use a windows shutdown command. I.e. we basically want it to be as if someone just turned off the switch, or the main power unit. Does your code do this?

An no, our programmer did not know how to do this, otherwise I wouldnt have posted tihs message Crazy

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Shut Down In reply to
I'm just a little confused as to how a programmer can write the code for an audio recorder but not know how to shut down a pc.

The code I provided will just shut down the pc. Nothing special.
Quote Reply
Re: [AndyNewby] Shut Down In reply to
Pull the plug! That's the best test ;-)

Cheers

- wil
Quote Reply
Re: [Wil] Shut Down In reply to
Haha good point.
Quote Reply
Re: [Wil] Shut Down In reply to
We'd love to, if we didnt have to do it several thousand times a week Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Shut Down In reply to
If you are doing it "thousands" of times then surely you need people there to monitor what happens otherwise the exercise is pointless.

CrazyCrazy
Quote Reply
Re: [AndyNewby] Shut Down In reply to
Cant you do something with that Windows Scheduler thingy? You can program that thing to shut down, start programs, start the machine back up etc. etc.

Look for that little icon in the icon tray. Never used it myself but it's suppose to be preety powerful.

Cheers

- wil
Quote Reply
Re: [RedRum] Shut Down In reply to
No the scheduler thing doesn't do what we want.

As for the standing by and watching it shut doewn and restart thousands of times, be my guest [:()]

We have log files installed, so any events are recorded, for later review if needed.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Wil] Shut Down In reply to
.....still requires someone to turn the pc back on....
Quote Reply
Re: [AndyNewby] Shut Down In reply to
Buy some kind of special plug, or buy a CPU backup thingy, so you can simulate power failiures. We have one of those lying around in the office. Maybe that would work?

- wil