473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Restarting the computer programmatically

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.
Oct 6 '08 #1
8 2391
On Oct 6, 2:17*pm, "K Viltersten" <t...@viltersten.comwrote:
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
Oct 6 '08 #2
On Oct 6, 2:17*pm, "K Viltersten" <t...@viltersten.comwrote:
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
Oct 6 '08 #3
use System.Management class.
<snip>

Thanks.
--
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.
Oct 6 '08 #4
>I'd like to believe that there's at least a
>convenience wrapper for performing such task
in C#. Is there? Where?
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".

--
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.
Oct 6 '08 #5
On Oct 6, 8:03*am, "K Viltersten" <t...@viltersten.comwrote:
I'd like to believe that there's at least a
convenience wrapper for performing such task
in C#. Is there? Where?
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".

--
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
Oct 8 '08 #6
>>>I'd like to believe that there's at least a
>>>convenience wrapper for performing such task
in C#. Is there? Where?

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

--
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.
Oct 8 '08 #7
On Oct 8, 9:59*am, "K Viltersten" <t...@viltersten.comwrote:
>>I'd like to believe that there's at least a
convenience wrapper for performing such task
in C#. Is there? Where?
>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 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.

--
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
Oct 8 '08 #8
On Oct 8, 10:08*am, Duggi <DuggiSrinivasa...@gmail.comwrote:
On Oct 8, 9:59*am, "K Viltersten" <t...@viltersten.comwrote:


>>>I'd like to believe that there's at least a
>>>convenience wrapper for performing such task
>>>in C#. Is there? Where?
>>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 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.
--
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- Hide quoted text -

- Show quoted text -
Hey be I am wrong, the above as per my best knowledge goes.

-Cnu
Oct 8 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: serge | last post by:
We have an ASP application installed on one powerful Win 2003 and the SQL Server on another Win 2003. We have two copies of the application (identical, one for production and one for test...
3
by: Nick | last post by:
Hi, I would like to make my application to automatically check on updates from a source and if any, downloads it and automatically updates itself with the new version. Now because the...
1
by: Bhavya Shah | last post by:
Hello All, I am facing a serious problem while copying a file to a remote computer programmatically. What I want to do: I want to connect to a remote computer and copy a file to the remote...
2
by: John Spiegel | last post by:
Hi all, Is there a way to programmatically restart Windows (2000, specifically), login automatically then start an application? I've been running across some Windows Shell options (which...
1
by: Dex | last post by:
Hello, We're developing our own small installation application in C#. At the end of the installation, we need to reboot the computer. Does anyone know how to write some C# code to...
9
by: woolley.dean | last post by:
The problem we are having is with the worker process restarting after one minute of being started up. We had a website running in .Net 1.1 and switched it over to .Net 2.0. The site is running on...
3
by: gourmet | last post by:
Hello! I need to restart the "Windows Audio Service" (audiosrv) via C#. I'm using the ServiceController Class to do this. It is no problem under XP and no problem under vista if UAC is...
8
by: SAL | last post by:
Hello, I have a web app (asp.net 2.0) that I'm loosing Session variables in. I implemented: Application_End in Global.asax using the following code: Sub Application_End(ByVal sender As Object,...
2
by: sheperson | last post by:
Hi, Does anyone know how to restart a computer using C# code? I can use shutdown -r command but this is not a good choice because it takes 30 seconds to restart. I have made a wizard for one of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.