473,607 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rebooting

A
Anyone have any code to reboot from a C# app?
Nov 15 '05 #1
4 2149
As far as I know, there is no managed .NET support for this.
However, you can use the "ExitWindow sEx" or "InitiateShutdo wn" or
"InitiateShutdo wnEx" Windows API calls.
The first one should be used if initiated from an interactive application,
the last two should be used from
a server application,

Bennie Haelen

"A" <NO****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Anyone have any code to reboot from a C# app?

Nov 15 '05 #2

Hi,

Thank you for posting in the community!

Based on my understanding, you want to use C# to reboot your computer.
=============== =============== =============
Based on my experience, .Net class library does not support the function of
rebooting. You need to get this done through P/invoke some WIN32 APIs.

Bennie has provided you the functions you may use, please look the detailed
remarks in MSDN "PlatForm SDK"

=============== =============== =============
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
You can use the System.Manageme nt interfaces to reboot a machine. This uses
WMI (I think it stands for Windows Management Instrumentation ). This will
also allow you to reboot remote machines too if you wanted to.

Here's some code, may need some changes, I just copy/pasted from my code. If
the current user has permissions to reboot the machine, you can comment out
the connection_opti ons stuff also.

using System.Manageme nt;

/// ----------------- Need class dedfinition...

int result;

result = 0;

string host;

host = "LOCALHOST" ;

ConnectionOptio ns Connect_options = new ConnectionOptio ns();

Connect_options .Username = user; // enter username

Connect_options .Password = password; // enter password

ManagementScope scope = new
ManagementScope ("\\\\"+host+"\ \root\\cimv2",C onnect_options) ;

scope.Options.E nablePrivileges = true;

scope.Connect() ;

System.Manageme nt.ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT
* FROM Win32_Operating System");

ManagementObjec tSearcher query1 = new ManagementObjec tSearcher(scope ,oq);
ManagementObjec tCollection queryCollection 1 = query1.Get();

foreach( ManagementObjec t mo in queryCollection 1 )

{

string[] ss={"6","0"};

mo.InvokeMethod ("Win32Shutdown ",ss);

Console.WriteLi ne(mo.ToString( ));

}

"A" <NO****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Anyone have any code to reboot from a C# app?

Nov 15 '05 #4

Hi

Is your problem resolved?
If you still have anything unclear, please feel free to feedback to me. I
will help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

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

Similar topics

0
1265
by: Al-ahmadi | last post by:
Hi EveryBody: Is there any way to add the rebooting code to the user interface of the setup project in VB.net ? if the answer is yes,how can I do it ? but if the answer is no, Is there any way to add dialog that I made by myself which consist of the rebooting code to the user inteface of the setup project ? if the answer is yes, how can I do it ? But if the answer is now, Is there any way to let my setup project rebooting after the...
0
1229
by: Todd Bright | last post by:
I have a Windows service that I wrote in C#. It uses a form in another thread to keep it running because we needed some user interface activity. When the service is running the machine will NOT reboot. Anyone have any ideas about this? Is there a way to respond to a Windows reboot event? Thanks, Todd
2
1911
by: mr_amitkulkarni | last post by:
Hello Friends, Objective : I'm working on a trivial solution for an issue like if my server/pc hangs at any moment it should reboot automatically. proposed Solution : I'll be using an external watchDog circuit. This ckt will be interfaced on LPT1's pin 16/14 . There will be software 'C' program which will continually send 01010.. on the pin on LPT1 . Now ckt is made with a logic that it will observe the square wave ie 010101...on...
2
286
by: Brady Kelly | last post by:
When I use the ExitWindowsEx function in my C# console application it doesn't reboot. Any ideas why?
8
11575
by: Steve Teeples | last post by:
I am trying to use WMI to reboot my system. I have admin privileges. I've tried two different solutions but both fail for separate reasons. private void button1_Click(object sender, System.EventArgs e) { ManagementBaseObject outParams = null; ManagementClass os = new ManagementClass("Win32_OperatingSystem"); os.Scope.Options.EnablePrivileges = true; // enables required security privilege.
1
275
by: Josh | last post by:
The error I am getting is the following. ALong with the error asp doesnt start and the web site is down until I reregister asp service. Event Type: Error Event Source: ASP.NET 1.1.4322.0 Event Category: None Event ID: 1084
1
1161
by: Al-ahmadi | last post by:
Hi EveryBody: Is there any way to add the rebooting code to the user interface of the setup project in VB.net ? if the answer is yes,how can I do it ? but if the answer is no, Is there any way to add dialog that I made by myself which consist of the rebooting code to the user inteface of the setup project ? if the answer is yes, how can I do it ? But if the answer is now, Is there any way to let my setup project rebooting after the...
7
14504
by: Raju5725 | last post by:
Hi All, How can I Change Local Machine IP Address without rebooting the machine using VB.Net. As I want to shift from one IP address to another IP address with application the effect should take place without rebooting the system. Thanks in advance. Raju
3
2603
by: spoonone | last post by:
Hi my daughters PC keeps rebooting, when it first loads, tried to Boot into safe mode, which I can not access, tried Windows Repair can't get in to give her password, tried making it a slave on my PC, to try and access her files she desperately needs but no luck, a friend said HDD is corrupt ( Windows start up code) I have managed to get into her Mums account but can't manage to get her files. Any advice would be very much appreciated.
0
8049
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7985
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8469
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8322
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1316
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.