Restarting the computer programmatically

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

I've found a number of pages describing how
to restart the computer that my service runs
on. The nicest one was the Black Wasp's but
even there, i need to play with C++-like
looking code. Is it really neccessary?

http://www.blackwasp.co.uk/ExitLogoffWindows.aspx

I'd like to believe that there's at least a
convenience wrapper for performing such task
in C#. Is there? Where?
 
I've found a number of pages describing how
to restart the computer that my service runs
on. The nicest one was the Black Wasp's but
even there, i need to play with C++-like
looking code. Is it really neccessary?

http://www.blackwasp.co.uk/ExitLogoffWindows.aspx

I'd like to believe that there's at least a
convenience wrapper for performing such task
in C#. Is there? Where?

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.

use System.Management class.


ManagementBaseObject mbObject = null;
ManagementClass mcWin32 = new
ManagementClass("Win32_OperatingSystem");
mcWin32.Get();

mcWin32.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mbObjParams =
mcWin32.GetMethodParameters("Win32Shutdown");

mbObjParams["Flags"] = "1";
mbObjParams["Reserved"] = "0";

foreach (ManagementObject manObj in
mcWin32.GetInstances())
{
mbObject = manObj.InvokeMethod("Win32Shutdown",
mbObjParams, null);
}

the above code should work.

-cnu
 
I've found a number of pages describing how
to restart the computer that my service runs
on. The nicest one was the Black Wasp's but
even there, i need to play with C++-like
looking code. Is it really neccessary?

http://www.blackwasp.co.uk/ExitLogoffWindows.aspx

I'd like to believe that there's at least a
convenience wrapper for performing such task
in C#. Is there? Where?

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.

Or else another tweak around is invoke shutdown.exe in a process,
which shuts system down.

-Cnu
 
I'd like to believe that there's at least a
Or else another tweak around is invoke
shutdown.exe in a process, which shuts
system down.

What are drawbacks with this method? Can it
lead to the computer being stuck TRYING to
restart and not being able to kill some of
the processes?

I need something that basically ensures that
"the cord is unplugged".
 
What are drawbacks with this method? Can it
lead to the computer being stuck TRYING to
restart and not being able to kill some of
the processes?

I need something that basically ensures that
"the cord is unplugged".

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.

what is "the cord is unplugged" means?? :-( (I am not good at
English may be)

-Cnu
 
I'd like to believe that there's at least a
what is "the cord is unplugged" means?? :-(
(I am not good at English may be)

Try to picture what happens if you UNPLUG your
computer (desktop, not laptop). That's what i
ment to cause. Guaranteed reboot.

As for the phrase - it's probably my english,
not yours, that is to blame, hehe.
 
Try to picture what happens if you UNPLUG your
computer (desktop, not laptop). That's what i
ment to cause. Guaranteed reboot.

As for the phrase - it's probably my english,
not yours, that is to blame, hehe.

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.- Hide quoted text -

- Show quoted text -

As far as I know, if You wanted a guaranteed reboot, the only approach
is load all the current running processes that are running and start
killing them one after another.

I strongly do not recommend this as the side effects are generally
more than the advantage you gain.

The earlier approach is good enough, as even if some proceses are not
killed, and system system does not shut down, my support guys can
always request the customer to restart the machine carefully. (To the
best fo my knowledge, a process can not be stopped because it has
something important to do. or current user do not have permision to do
so)

If you want code for get all the processes and kill them one after
anthor, I can write send it to you.

-Cnu
 
As far as I know, if You wanted a guaranteed reboot, the only approach
is load all the current running processes that are running and start
killing them one after another.

I strongly do not recommend this as the side effects are generally
more than the advantage you gain.

The earlier approach is good enough, as even if some proceses are not
killed, and system system does not shut down, my support guys can
always request the customer to restart the machine carefully. (To the
best fo my knowledge, a process can not be stopped because it has
something important to do. or current user do not have permision to do
so)

If you want code for get all the processes and kill them one after
anthor, I can write send it to you.

-Cnu- Hide quoted text -

- Show quoted text -

Hey be I am wrong, the above as per my best knowledge goes.

-Cnu
 
Back
Top