473,770 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shutdown windows programmaticall y in .NET

5 New Member
hai friends,

Iam developing a application using .NET remoting ,in which it shuts down,logs off , restart , locks remote PC.i tried to use windows ExwindowsEXAPI for shutdown,logoff , restart and SetSuspendState for lock PC and the later worked perfectly but the problem is ExwindowsEx only Logsoff the PC and shutdown and restart is not working .Although i achieved the result using shutdown.exe ,but iam not convinced,so could anyone say what may be the problem.


server code
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.          [DllImport("user32.dll")]
  5.         public static extern int ExitWindowsEx(uint uflag,uint reson);
  6.  
  7.              public void shutdown_server(uint f)
  8.         {
  9.             ExitWindowsEx(f,0);
  10.                   }
  11.  
  12.         public void shut_server_exe(string arg)
  13.         {
  14.  
  15.           System.Diagnostics.Process.Start("C:/shutdown.exe", arg);
  16.                 }
  17.  
  18.         [DllImport("Powrprof.dll")]
  19.         public static extern bool SetSuspendState(bool h, bool g, bool i);
  20.                public void standby()
  21.         {
  22.             SetSuspendState(false, false, false);
  23.         }
  24.  
  25.  
  26.  

client code



Expand|Select|Wrap|Line Numbers
  1.  
  2. private void logOffToolStripMenuItem_Click(object sender, EventArgs e)
  3.         {
  4.             try
  5.             {
  6.                 serverclass obj = (serverclass)Activator.GetObject(
  7.                               typeof(serverclass),
  8.                               "http://" + IP + ":1234/serverclass.soap");
  9.                 obj.shutdown_server(0);
  10.             }
  11.             catch (Exception err)
  12.             {
  13.                 MessageBox.Show(err.Message);
  14.                 disconnect();
  15.             }
  16.         }
  17.  
  18.         private void turnOffToolStripMenuItem_Click(object sender, EventArgs e)
  19.         {
  20.             try
  21.             {
  22.                 serverclass obj = (serverclass)Activator.GetObject(
  23.                               typeof(serverclass),
  24.                               "http://" + IP + ":1234/serverclass.soap");
  25.                 //obj.DoExitWin(2);
  26.                // obj.shutdown_server(8);
  27.                 obj.shut_server_exe("/L /C /Y");
  28.             }
  29.             catch (Exception err)
  30.             {
  31.                 MessageBox.Show(err.Message);
  32.                 disconnect();
  33.             }
  34.         }
  35.  
  36.         private void restartToolStripMenuItem_Click(object sender, EventArgs e)
  37.         {
  38.             try
  39.             {
  40.                 serverclass obj = (serverclass)Activator.GetObject(
  41.                               typeof(serverclass),
  42.                               "http://" + IP + ":1234/serverclass.soap");
  43.                // obj.shutdown_server(2);
  44.                 obj.shut_server_exe("/L /R /C /Y");
  45.             }
  46.             catch (Exception err)
  47.             {
  48.                 MessageBox.Show(err.Message);
  49.                 disconnect();
  50.             }
  51.         }
  52.  
  53.         private void lockPCToolStripMenuItem_Click(object sender, EventArgs e)
  54.         {
  55.             try
  56.             {
  57.  
  58.                 serverclass obj = (serverclass)Activator.GetObject(
  59.                                          typeof(serverclass),
  60.                                          "http://" + IP + ":1234/serverclass.soap");
  61.                 obj.standby();
  62.             }
  63.             catch (Exception err)
  64.             {
  65.                 MessageBox.Show(err.Message);
  66.                 disconnect();
  67.             }
  68.         }
  69.  

thanks friends
Mar 12 '08 #1
1 3066
Plater
7,872 Recognized Expert Expert
Pretty sure using the shutdown.exe is a good way to do it, but for remote PCs the shutdown.exe must be using some kind of commands to do it, and those should exist in the win32 APIs somewhere (RPC call maybe?)
Mar 12 '08 #2

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

Similar topics

8
2767
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think this would be simple enough if the ASP didn't have any user input, but it does.
3
2951
by: Tim Werth | last post by:
Is there an attribute or property that I can set in my AssemblyInfo.cs that is used to setup my COM+ application so that I can set the "Minutes until idle shutdown" of the app to something other than the 3 minute default? I am using others like: ApplicationName ApplicationActivation ApplicationAccessControl but I can't find one to set the idle shutdown.
3
1189
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
8
4192
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my send mail code is executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services registry DependOnService value including SMPTSVC and...
6
8764
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only talk to the UPS over a special device driver. Through this device driver I can detect that the UPS is going to notify Windows 2000 server to shut down. So I start doing a graceful termination. But Windows shuts down pretty quickly and there...
2
11415
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use managed code instead. I couldn't find any easy way of doing this but searching the Internet with...
4
6810
by: Andrew | last post by:
I have ASP.NET 2.0 application. I'm running some initialization code in Application_Start() in Global.asax. If this code fails I would like to shutdown the application completely. Meaning no page, or an error page is returned to the user. I've tried HostingEnvironment.InitiateShutdown() but it's async and still returns a page to the user. According to msdn this method is equivalent to ApplicationManager.ShutdownApplication()...
2
2567
by: Sin Jeong-hun | last post by:
I created a windows form application. It has a Threading.Timer and when the timer ticks it does some work and show a popup window. The problem is that while this program is running if the user tries to shutdown Windows, my application doesn't quit and neither does Windows. Of course, if the user first click of my application and then tries to shutdown, there is no problem. To solve this problem, I overrode WndProc of the main form,...
3
4290
by: IdleBrain | last post by:
Gurus, I am trying to delay Windows Shutdown/Restart to perfrom cleanup and I am using the following code: protected override void WndProc(ref Message ex)
0
9619
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
9454
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
10102
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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,...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
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
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
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.