What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 6541 |  Welcome, Guest!   Register  Login
 Home > Coding Horrors > C# > Lock, restart,logOff and shutdown a computer ...
Rajkatie

Lock, restart,logOff and shutdown a computer

 Coding Horror posted by: Rajkatie | Posted on: 3/3/2012 | Category: C# | Views: 3017 | Level: Silver | Status: [Member] | Points: 75 | Alert Moderator   



 public void PerformOperation(string filename, string arguments)

        {

            using (Process myProcess = new Process())
            {
                myProcess.StartInfo.FileName = Path.Combine(Environment.SystemDirectory, filename);
                myProcess.StartInfo.Arguments = arguments;
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
               
            }


// lock computer
1) PerformOperation("rundll32.exe", "user32.dll,LockWorkStation");

//Log Off computer
2)PerformOperation("shutdown.exe", "-l");

//Restart computer
3)PerformOperation("shutdown.exe", "-r -t 0");

//Shutdown computer
4)ProcessRequest("shutdown.exe", "-s -t  0");





Rajesh Patel
MCPD,MS
Brainbench (Asp.Net 4.0 and CSS 3.0)
Found interesting? Add this to:


About Rajesh Patel

Experience:6 year(s)
Home page:http://www.dotnetfunda.com/profile/rajkatie.aspx
Member since:Tuesday, February 14, 2012
Level:Silver
Status: [Member]
Biography:More than 6 years of professional experience in web based application development using Microsoft technology stack like ASP.NET with C#, .Net Ajax,Sql Server 2008/2005, .Net Web Services (Asmx,Page Methods and WCF).

Ability choose the best technology, platform and technique, based on a given problem definition and drive the best implementation through all development phase.
 Responses
Malkit
Posted by: Malkit | Posted on: 3/11/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

thanks for posting this code.....
would like to point out one thing...

//Shutdown computer
4)ProcessReques t("shutdown.exe", "-s -t 0");

here it should be
4) PerformOperation ("shutdown.exe", "-s -t 0");
bcz ProcessRequest is defined no where....

And also we need to use following namespaces to make this code working.
using System.Diagnostics;
using System.IO;


Malkit

Hariinakoti
Posted by: Hariinakoti | Posted on: 4/9/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Thanks for posting this code....

Thanks & Regards
Hari

Thanks & Regards
Hari

Paletiramaprasad
Posted by: Paletiramaprasad | Posted on: 12/11/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Nice post ....

Regard's
Ramaprasad


>> Write Response - Respond to this post and get points

More Coding Horrors

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 4:09:08 PM