Is it possible to call my pcs shutdown or restart method in my application?

Hi I am in the process of designing an application. I would like to be able to include a button that will close my application and restart the pc. 

Or a button that will shut down my pc. 

Is this possible  Would I need to make a call to the Windows API

Thanks 


Answer this question

Is it possible to call my pcs shutdown or restart method in my application?

  • AMV5520

    Is there a list of the exit codes Do you know what the exit code is to perform a restart


  • Gueneal


    Alan D. Colón submitted this code to PlanetSourceCode which displays the Windows-Shutdown dialog.

    Dim ExplorerProcess() As Process
    ExplorerProcess = Process.GetProcessesByName("explorer")
    ExplorerProcess(0).CloseMainWindow()

  • NathanE

    Thanks I have done it. 

    I placed this code in a button click event handler. 

    Shell("Shutdown -S") 

    That worked fine. 

  • krustitoe

    How can I do that  

    Is there an object that I can work with  


    I am new to win form programming. 

    Thanks 

  • eddy400

    call commandline "shutdown"
  • xWindx

    While calling the Windows Shutdown app from a command line does work, there is a more proper way to do this in .NET.

    Create an instance of the Environment class:

    Dim Env As Environment

    This object has many useful pieces of information about the computer your app is running on.  For example, this is where you can access the system paths of all the special folders (My Documents, System Folder, Program Files, etc.) when you manipulate files in code.

    To force a system shutdown you can call:

    Env.Exit(ExitCode as Integer)

    This will terminate your application and then tell the operating system to perform the shutdown type specified by ExitCode.

    Now your program can handle things like the current user not having privileges to shutdown the computer.  The Exit method will throw a security exception if the action cannot be performed.

    .NET has the ability to do almost anything directly.  It is rare that you MUST make an API call to do something.  Now, you might have to find and/or download the right reference, if the object you want is not built into .NET by default, but there are lots of SDKs and wrappers that people have written floating around out there.

  • Is it possible to call my pcs shutdown or restart method in my application?