Win32Shutdown
-
Tuesday, February 01, 2011 10:28 AM
I am using Win32Shutdown to shut down three PC's while nobody is logged on (screen is at "Press CTRL+ALT+DELETE to log on").
Two are Dells from 2007 and the other is a Dell from 2003. Only one of the three shuts down while logged off (one of the Dells from 2007).
I have tried everything to shut them down while logged off but nothing works. I think it is a hard disk/Windows issue.
Just wondering if anyone else had this issue?
All Replies
-
Tuesday, February 01, 2011 2:16 PM
Are you doing any apps for this.
please provide some more information.
With Regards, DP -
Tuesday, February 01, 2011 3:34 PM
To shutdown the PC you could use the following method: Please be advised that you got to add "System.Management" reference.
public void Shutdown() { ManagementBaseObject mboShutdown = null; ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem"); mcWin32.Get(); // You can't shutdown without security privileges mcWin32.Scope.Options.EnablePrivileges = true; ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown"); // Flag 1 means we want to shut down the system mboShutdownParams["Flags"] = "1"; mboShutdownParams["Reserved"] = "0"; foreach (ManagementObject manObj in mcWin32.GetInstances()) { mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null); } }also you can use the following flags to suit your needs accordingly:
Flags:
- 0 (0x0) Log Off
- 4 (0x4) Forced Log Off (0 4)
- 1 (0x1) Shutdown
- 5 (0x5) Forced Shutdown (1 4)
- 2 (0x2) Reboot
- 6 (0x6) Forced Reboot (2 4)
- 8 (0x8) Power Off
- 12 (0xC) Forced Power Off (8 4)
Balaji Baskar
[Please mark the post as answer if it answers your question]
[http://codesupport.wordpress.com]- Proposed As Answer by CoolDadTxMVP, Moderator Tuesday, February 01, 2011 4:17 PM
- Marked As Answer by Bin-ze ZhaoModerator Wednesday, February 02, 2011 5:40 AM
-
Tuesday, February 01, 2011 4:31 PM
Are you doing any apps for this.
please provide some more information.
With Regards, DP
It's a web service that starts when the PC is logged off. When someone logs off it starts the web service which powers off the PC at a certain time (it reads this from a file). It works OK on one test machine I have but not the two others. -
Tuesday, February 01, 2011 5:04 PM
To shutdown the PC you could use the following method: Please be advised that you got to add "System.Management" reference.
public void Shutdown() { ManagementBaseObject mboShutdown = null ; ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem" ); mcWin32.Get(); // You can't shutdown without security privileges mcWin32.Scope.Options.EnablePrivileges = true ; ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown" ); // Flag 1 means we want to shut down the system mboShutdownParams["Flags" ] = "1" ; mboShutdownParams["Reserved" ] = "0" ; foreach (ManagementObject manObj in mcWin32.GetInstances()) { mboShutdown = manObj.InvokeMethod("Win32Shutdown" , mboShutdownParams, null ); } }
also you can use the following flags to suit your needs accordingly:
Flags:
- 0 (0x0) Log Off
- 4 (0x4) Forced Log Off (0 4)
- 1 (0x1) Shutdown
- 5 (0x5) Forced Shutdown (1 4)
- 2 (0x2) Reboot
- 6 (0x6) Forced Reboot (2 4)
- 8 (0x8) Power Off
- 12 (0xC) Forced Power Off (8 4)
Balaji Baskar
[Please mark the post as answer if it answers your question]
[http://codesupport.wordpress.com]I tried
- 1(0x1) Shutdown
- 5 (0x5) Forced Shutdown (1 4)
- 12 (0xC) Forced Power Off (8 4)
-
Tuesday, February 01, 2011 5:11 PM
It's a web service that starts when the PC is logged off. When someone logs off it starts the web service which powers off the PC at a certain time (it reads this from a file). It works OK on one test machine I have but not the two others.
Is it a windows service or web service?
Balaji Baskar
[Please mark the post as answer if it answers your question]
[http://codesupport.wordpress.com] -
Tuesday, February 01, 2011 5:50 PM
Sorry my mistake; it's a Windows service.It's a web service that starts when the PC is logged off. When someone logs off it starts the web service which powers off the PC at a certain time (it reads this from a file). It works OK on one test machine I have but not the two others.
Is it a windows service or web service?
Balaji Baskar
[Please mark the post as answer if it answers your question]
[http://codesupport.wordpress.com] -
Tuesday, February 01, 2011 5:57 PMalso one more thing since you are using "Win32Shutdown" in windows 7 system, can check if it is 32-bit OS or 64-bit OS ?
Balaji Baskar
[Please mark the post as answer if it answers your question]
[http://codesupport.wordpress.com] -
Tuesday, February 01, 2011 8:39 PM
Are you doing any apps for this.
please provide some more information.
With Regards, DP
It's a Windows service. It starts when the user logs off and then turns off the PC after a certain amount of time has elapsed after log off (this amount of time is read from a timer).However it only works for me on one test PC? I am using WIn32Shutdown to shut it down
-
Wednesday, February 02, 2011 5:23 AM
Use the below code
System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
This will helps to shutdown your pc. Once your condition gets true.
This will resolve your problem.
With Regards, DP- Marked As Answer by Bin-ze ZhaoModerator Wednesday, February 02, 2011 5:40 AM
-
Wednesday, February 02, 2011 9:16 AM
also one more thing since you are using "Win32Shutdown " in windows 7 system, can check if it is 32-bit OS or 64-bit OS ?
Balaji Baskar
[Please mark the post as answer if it answers your question]
[http://codesupport.wordpress.com]
It's 32-bit. But the PC it does shut down in is also 32-bit so it isn't that. -
Wednesday, February 02, 2011 9:49 AM
Use the below code
System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
This will helps to shutdown your pc. Once your condition gets true.
This will resolve your problem.
With Regards, DP
Thanks for the reply but it doesn't work; it only works when logged on. Maybe it is a hardware issue?

