Click here to Skip to main content
15,889,116 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dynamic assembly information Pin
PIEBALDconsult16-Jan-11 14:49
mvePIEBALDconsult16-Jan-11 14:49 
QuestionRunning an exe file ( I mean a program) from inside my own program Pin
Fred 3414-Jan-11 1:41
Fred 3414-Jan-11 1:41 
AnswerRe: Running an exe file ( I mean a program) from inside my own program Pin
PIEBALDconsult14-Jan-11 1:46
mvePIEBALDconsult14-Jan-11 1:46 
AnswerRe: Running an exe file ( I mean a program) from inside my own program PinPopular
Luc Pattyn14-Jan-11 1:48
sitebuilderLuc Pattyn14-Jan-11 1:48 
GeneralRe: Running an exe file ( I mean a program) from inside my own program Pin
Fred 3414-Jan-11 2:00
Fred 3414-Jan-11 2:00 
GeneralRe: Running an exe file ( I mean a program) from inside my own program Pin
Dave Kreskowiak14-Jan-11 4:07
mveDave Kreskowiak14-Jan-11 4:07 
AnswerRe: Running an exe file ( I mean a program) from inside my own program PinPopular
JF201514-Jan-11 2:00
JF201514-Jan-11 2:00 
QuestionWhich is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Erik14-Jan-11 0:16
Erik14-Jan-11 0:16 
Hi,

I have to write an application that has the ability to perform a system-restart, shutdown or user-logoff. So far, I have found two solutions to do it, which both work very well. I'd like to know which is the best way to do it, i.e. if there are any disadvantages to the one or the other way to do it. Which is the most professional way to deal with it?

Currently, I use the System.Management Namespace, whic looks like the most elegant way to do this to me:



ManagementBaseObject mboShutdown = null;
            using (ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem"))
            {
                mcWin32.Get();
                mcWin32.Scope.Options.EnablePrivileges = true;
                ManagementBaseObject ShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");                
                ShutdownParams["Flags"] = "1";
                ShutdownParams["Reserved"] = "0";
                foreach (ManagementObject manObj in mcWin32.GetInstances())
                {
                    mboShutdown = manObj.InvokeMethod("Win32Shutdown", ShutdownParams, null);
                }
                ret = true;
            }



On the other hand, I have found many users who load the appropriate system-DLLs, and perform the whole tsak "unmanaged", an call ExitWindowsEx from these DLLs. This works too, but I am wondering why people decide to do it this way, if there is a namespace available in .NET that actually does it, like in my example above.

Which way would you chose, and why?
AnswerRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Luc Pattyn14-Jan-11 0:33
sitebuilderLuc Pattyn14-Jan-11 0:33 
AnswerRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Ravi Sant14-Jan-11 1:50
Ravi Sant14-Jan-11 1:50 
GeneralRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Dave Kreskowiak14-Jan-11 4:01
mveDave Kreskowiak14-Jan-11 4:01 
GeneralRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
jschell14-Jan-11 9:58
jschell14-Jan-11 9:58 
AnswerRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Dave Kreskowiak14-Jan-11 4:05
mveDave Kreskowiak14-Jan-11 4:05 
QuestionGetting network drives names issue Pin
Priya Prk13-Jan-11 21:34
Priya Prk13-Jan-11 21:34 
AnswerRe: Getting network drives names issue Pin
RaviRanjanKr13-Jan-11 22:24
professionalRaviRanjanKr13-Jan-11 22:24 
GeneralRe: Getting network drives names issue Pin
OriginalGriff13-Jan-11 22:41
mveOriginalGriff13-Jan-11 22:41 
GeneralRe: Getting network drives names issue Pin
Priya Prk13-Jan-11 23:07
Priya Prk13-Jan-11 23:07 
AnswerRe: Getting network drives names issue Pin
Goutam Patra13-Jan-11 23:04
professionalGoutam Patra13-Jan-11 23:04 
GeneralRe: Getting network drives names issue Pin
Priya Prk13-Jan-11 23:09
Priya Prk13-Jan-11 23:09 
GeneralRe: Getting network drives names issue Pin
RaviRanjanKr13-Jan-11 23:14
professionalRaviRanjanKr13-Jan-11 23:14 
GeneralRe: Getting network drives names issue Pin
Goutam Patra13-Jan-11 23:25
professionalGoutam Patra13-Jan-11 23:25 
AnswerRe: Getting network drives names issue Pin
Pete O'Hanlon13-Jan-11 23:21
mvePete O'Hanlon13-Jan-11 23:21 
GeneralRe: Getting network drives names issue Pin
Priya Prk13-Jan-11 23:32
Priya Prk13-Jan-11 23:32 
AnswerRe: Getting network drives names issue Pin
Luc Pattyn14-Jan-11 1:41
sitebuilderLuc Pattyn14-Jan-11 1:41 
GeneralRe: Getting network drives names issue Pin
Priya Prk14-Jan-11 2:01
Priya Prk14-Jan-11 2:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.