473,756 Members | 8,443 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 3063
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
2766
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
2949
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
4191
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
8761
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
6807
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
2566
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
4288
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
9462
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
10046
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...
0
9722
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
8723
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5155
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
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
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
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
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.