By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,470 Members | 924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,470 IT Pros & Developers. It's quick & easy.

Shutting Down Windows Vista in C#

P: 6
Hi all, I am making a program that requires the user to be able to shut down windows after a set period of time.The code I used is as follows:

Expand|Select|Wrap|Line Numbers
  1. namespace Program_1
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         [DllImport("user32.dll")]
  6.         public static extern void LockWorkStation(); 
  7.         [DllImport("user32.dll")]
  8.         public static extern int ExitWindowsEx(int uFlags, int dwReason);
  9.  
  10.  
  11.         private void restartBtn_Click(object sender, EventArgs e)
  12.         {
  13.             ExitWindowsEx(2, 0);
  14.         }
  15.  
  16.         private void shutDownBtn_Click(object sender, EventArgs e)
  17.         {
  18.             ExitWindowsEx(1, 0);
  19.         }
  20.     }
  21. }
The problem is that this code does not work for Windows Vista due to some kind of diffrence between it and the older versions of Windows. I have tried the code and it works on XP so I expect it should work on Millenium,98,etc..

So does any body know how to shut down Windows Vista in code??
Thnx.
Oct 16 '08 #1
Share this Question
Share on Google+
2 Replies


Plater
Expert 5K+
P: 7,872
How about running the shutdown.exe process. That's probably still available in vista?
Oct 16 '08 #2

joedeene
100+
P: 583
If what Plater said doesn't work, then a simple Google search would've worked and brought up a site like this one.

joedeene
Oct 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.