473,511 Members | 16,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to restart PC in C#

I want use C# to restart my computer,

how to?

Nov 16 '05 #1
3 8204
You cna use the API
http://custom.programming-in.net/art...SystemShutdown
Or you can freestyle and just loop through each active process on your
computer and shut it down -

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
<lz**@0536.net> wrote in message
news:uy**************@TK2MSFTNGP11.phx.gbl...
I want use C# to restart my computer,

how to?

Nov 16 '05 #2

[DllImport("advapi32.dll", EntryPoint="InitiateSystemShutdown")]
public static extern int InitiateSystemShutdownA(string lpMachineName,
string lpMessage, int dwTimeout, int bForceAppsClosed, int
bRebootAfterShutdown);
public void RestartPC(object sender, System.EventArgs e)
{
int restartcode=InitiateSystemShutdownA("\\127.0.0.1", "Restart...", 10,
1, 1);
MessageBox.Show("OK"+restartcode);
}

Am i right?

but the parameter restartcode is 0,and my computer still run.
"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:un**************@tk2msftngp13.phx.gbl...
You cna use the API
http://custom.programming-in.net/art...SystemShutdown
Or you can freestyle and just loop through each active process on your
computer and shut it down -

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
<lz**@0536.net> wrote in message
news:uy**************@TK2MSFTNGP11.phx.gbl...
I want use C# to restart my computer,

how to?


Nov 16 '05 #3
You can also use WMI to do this, this will allow you to also reboot remote
machines, as well as force reboots so that it will not hault to get a user
key press to end tasks.

<lz**@0536.net> wrote in message
news:Ob**************@tk2msftngp13.phx.gbl...

[DllImport("advapi32.dll", EntryPoint="InitiateSystemShutdown")]
public static extern int InitiateSystemShutdownA(string lpMachineName,
string lpMessage, int dwTimeout, int bForceAppsClosed, int
bRebootAfterShutdown);
public void RestartPC(object sender, System.EventArgs e)
{
int restartcode=InitiateSystemShutdownA("\\127.0.0.1", "Restart...", 10,
1, 1);
MessageBox.Show("OK"+restartcode);
}

Am i right?

but the parameter restartcode is 0,and my computer still run.
"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:un**************@tk2msftngp13.phx.gbl...
You cna use the API
http://custom.programming-in.net/art...SystemShutdown
Or you can freestyle and just loop through each active process on your
computer and shut it down -

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
<lz**@0536.net> wrote in message
news:uy**************@TK2MSFTNGP11.phx.gbl...
I want use C# to restart my computer,

how to?



Nov 16 '05 #4

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

Similar topics

1
2200
by: Piotr Trawiński | last post by:
I have this notorious problem: at some point pgsql simply hangs up and requires a restart. --------------------------------------------------------------------------- -------...
1
4078
by: localhost | last post by:
In the Application_OnStart, I make some data calls and place the results in the HTTP cache. Sometimes, the database is not available when the application starts up, so I want to sleep for 20...
18
5339
by: amdishigh | last post by:
We are experiencing the following problems concerning ASP.NET: our ASP.NET application, written in .NET 1.1 platform, and hosted in IIS 5.0 environment, experience frequent session timeout problem....
3
3359
by: Pint | last post by:
I would like to know if there is a programatic way to force the Application object to restart. I have a hosted website where I will be unable to control the webserver (eg:iisreset), and I would...
3
3182
by: John A Grandy | last post by:
In ASP.NET 1.1 and/or 2.0 ..... Is it possible to configure a web-app so that replacement of an .xml file ( physically located under the virtual dir root ) with a newer version of the file...
6
3788
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop()...
8
9305
by: kenneth fleckenstein nielsen | last post by:
hi guru's I want to restart my webservice when ever it throws an exception that isn't cought. can i do that by web.config or iss or how ??
4
7256
by: shorti | last post by:
Can anyone explain in greater (and more comprehensive) detail what the RESTART option does in the ALTER TABLE table ALTER COLUMN statement. This is the description in Info Center: RESTART or...
3
3299
by: MarkusJNZ | last post by:
Hi, I have two different applications running on 2003 both in two different vitrual directories. One application runs on the .NET framework 1.1 whilst the other runs on 2.0. If I change the...
1
2626
by: Brian Simmons | last post by:
Hi All, I know that if you modify the web.config file or any file in the App_Code subfolder, that ASP.net 2.0 will "restart" the application (i.e. clear out any sessions, etc...). Are there...
0
7242
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
7355
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
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7510
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...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.