in c++ it was ExitWindowsEx()
thanks 6 12738
In C#, it is still the same ExitWindowsEx API call.
class Class1
{
[DllImport("user 32.dll")]
static extern bool ExitWindowsEx(u int uFlags, uint
dwReason);
[STAThread]
static void Main(string[] args)
{
ExitWindowsEx(1 , 0); //this will cause the system to
shut down.
}
}
uFlags
4 = Force any applications to quit instead of prompting the user to close
them.
0 = Log off the network.
8 = Shut down the system and, if possible, turn the computer off.
2 = Perform a full reboot of the system.
1 = Shut down the system.
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in
message news:OI******** ******@TK2MSFTN GP09.phx.gbl... in c++ it was ExitWindowsEx()
thanks
Lebesgue wrote: In C#, it is still the same ExitWindowsEx API call.
class Class1 { [DllImport("user 32.dll")] static extern bool ExitWindowsEx(u int uFlags, uint dwReason);
[STAThread] static void Main(string[] args) { ExitWindowsEx(1 , 0); //this will cause the system to shut down. } }
uFlags 4 = Force any applications to quit instead of prompting the user to close them. 0 = Log off the network. 8 = Shut down the system and, if possible, turn the computer off. 2 = Perform a full reboot of the system. 1 = Shut down the system.
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in message news:OI******** ******@TK2MSFTN GP09.phx.gbl...
in c++ it was ExitWindowsEx()
thanks
thanks
so there is no C# class that encapsulates this API ?
Herbert,
No, there is not. You could use the classes in the System.Manageme nt
namespace and access the method on the WMI class, but it is just as
roundabout as using the function through the P/Invoke layer.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in
message news:42******** ******@microsof t.com... Lebesgue wrote: In C#, it is still the same ExitWindowsEx API call.
class Class1 { [DllImport("user 32.dll")] static extern bool ExitWindowsEx(u int uFlags, uint dwReason);
[STAThread] static void Main(string[] args) { ExitWindowsEx(1 , 0); //this will cause the system to shut down. } }
uFlags 4 = Force any applications to quit instead of prompting the user to close them. 0 = Log off the network. 8 = Shut down the system and, if possible, turn the computer off. 2 = Perform a full reboot of the system. 1 = Shut down the system.
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in message news:OI******** ******@TK2MSFTN GP09.phx.gbl...
in c++ it was ExitWindowsEx()
thanks
thanks
so there is no C# class that encapsulates this API ?
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in
message news:42******** ******@microsof t.com... Lebesgue wrote: In C#, it is still the same ExitWindowsEx API call.
class Class1 { [DllImport("user 32.dll")] static extern bool ExitWindowsEx(u int uFlags, uint dwReason);
[STAThread] static void Main(string[] args) { ExitWindowsEx(1 , 0); //this will cause the system to shut down. } }
uFlags 4 = Force any applications to quit instead of prompting the user to close them. 0 = Log off the network. 8 = Shut down the system and, if possible, turn the computer off. 2 = Perform a full reboot of the system. 1 = Shut down the system.
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in message news:OI******** ******@TK2MSFTN GP09.phx.gbl...
in c++ it was ExitWindowsEx()
thanks
thanks
so there is no C# class that encapsulates this API ?
Yes there is, you could use System.Manageme nt classes and the WMI class
Win32_Operating System.
public static void Main() {
ManagementBaseO bject outParams = null;
ManagementClass os = new ManagementClass ("Win32_Operati ngSystem");
os.Get();
os.Scope.Option s.EnablePrivile ges = true; // enables required security
privilege.
ManagementBaseO bject inParams = os.GetMethodPar ameters("Win32S hutdown");
inParams["Flags"] = "1"; // System shutdown
inParams["Reserved"] = "0";
foreach (ManagementObje ct mo in os.GetInstances ())
outParams = mo.InvokeMethod ("Win32Shutdown ",
inParams, null);
Willy.
"Lebesgue" <no****@spam.jp > wrote in message
news:e5******** ******@TK2MSFTN GP12.phx.gbl... In C#, it is still the same ExitWindowsEx API call.
class Class1 { [DllImport("user 32.dll")] static extern bool ExitWindowsEx(u int uFlags, uint dwReason);
[STAThread] static void Main(string[] args) { ExitWindowsEx(1 , 0); //this will cause the system to shut down. } }
uFlags 4 = Force any applications to quit instead of prompting the user to close them. 0 = Log off the network. 8 = Shut down the system and, if possible, turn the computer off. 2 = Perform a full reboot of the system. 1 = Shut down the system.
"Herbert VON GRÜNENWALD" <he************ *******@microso ft.com> wrote in message news:OI******** ******@TK2MSFTN GP09.phx.gbl... in c++ it was ExitWindowsEx()
thanks
Did you test your code? If you actualy did you would have noticed that this
doesn't work.
The reason is simple, you have to enable the "SeShutdown " privilege using
PInvoke, something more complicated than calling ExitWindowsEx.
Willy.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:e3******** ******@tk2msftn gp13.phx.gbl... Herbert,
No, there is not. You could use the classes in the System.Manageme nt namespace and access the method on the WMI class, but it is just as roundabout as using the function through the P/Invoke layer.
Hope this helps.
Nicholas ,
I have to disagree, because the simple PInvoke snip is not enough to invoke
a shutdown, you need to enable the SeShutdown privilege for this to work,
and this is non-trivial using PInvoke. System.Manageme nt is definitely the
way to go.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve Duke |
last post by:
Here is the block of the sproc that I?ve created. All lines execute
fine except for the ?exec master..xp_cmdshell @reboottc?. In order to
make this work from the query analyzer I had to set the MSSQLSERVER
service to have the same credentials as the thin clients we are trying
to shut down, that means the service is running as an...
|
by: Allan Bredahl |
last post by:
Hi All
I am trying to construct an application that is able to cancel a machine
shutdown, reboot or logoff. And after performing some stuff to perform the
original shutdown order : Shutdown/reboot/logoff.
I have tried this :
AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf
|
by: Senthil |
last post by:
Hi,
I would like to know the code for reboot and shutdown windows xp
professional using VB.Net.
thanx
Senthil
|
by: Haim |
last post by:
Anybody knows how to prevent a shutdown command? (on Win
XP).
Or just a way to let my application close itself rather
then being killed by the restart command.
I have been working in my organization on an application
that sometimes gets killed by an installation that
restarts the computer. I want to prevent this from
happening and display...
|
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 programmatically reboot the computer? (Note: The
computer will be Win2k, WinXP, or Win2k3, nothing else.)
Thanks.
| |
by: sam |
last post by:
I found reboot script at TechNet and I wonder how to apply in VB.Net?
Reboot Coding
************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
|
by: cj |
last post by:
My program shuts itself down and reboots the pc it's running on at
2:00am twice a week and has been doing so without fail for over a year.
But twice in the past month it's been found running in the AM with an
unhandled exception on the screen. As best I can tell this exception
occurs while it's trying to reboot the pc. This has me thinking...
|
by: remya1000 |
last post by:
i'm using VB.NET.
i wrote a Auto Reboot program. and here is the codes i tried...
Code:
Private Enum ShutDown1
LogOff = 0
Shutdown = 1
Reboot = 2
ForcedLogOff = 4
|
by: Kate77 |
last post by:
Hello,
I have a strange problem,
I have application running in the tray bar,
for some reason I cant reboot the computer when it is running and i have to close
it if i want the computer to do a reboot or shutdown.
the application is not doing anything special,
all it does is checking a web site every hour using timer.
anyone saw this...
|
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...
|
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...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |