Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

my project can't use System.Diagnostics.Process

on click my windows will shutdown i'm developing an metro app for windows 8.1 using c# language

using libraries

using System.Diagnostics;
using System.Runtime.InteropServices;

the action is

    private void Button_Click(object sender, RoutedEventArgs e)
    {  
        Process.Start("shutdown", "/s /t 0");
    }

red bar in "Process"

so why it couldn't read Progress and is there any other method , Thanks

like image 941
Alaeddine Avatar asked Mar 26 '26 23:03

Alaeddine


1 Answers

Metro apps only have a limited subset of classes that are useable, the Process class is one of the removed classes. If a class does not have the windows store icon (enter image description here) on the MSDN when you are looking in the namespace view then the class is not available for use in metro apps.

Metro apps are sandboxed and can not interact with other processes nor spawn new processes themselves so there are no alternatives for running shutdown.exe unless you are willing to make your app a desktop app instead of a metro app.

Taking a look at "Alternatives to Windows APIs in Windows Store apps" you can see that there is no metro equivalent to the User: shutdown API either.

If you absolutely don't want to create a desktop app but still want to be able to shut down the only other work around I can think of is to have a second program that runs as a system service that your metro app can talk to via some form of IPC. That way you can have your metro app send a request to the service then the service is what will actually initiate the shutdown command.

like image 143
Scott Chamberlain Avatar answered Mar 28 '26 22:03

Scott Chamberlain