Results 1 to 8 of 8

Thread: [02/03] Shutdown

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    137

    Question [02/03] Shutdown

    What would be the correct way to shutdown a users computer from my application? Can you provide a way that will work for all versions of windows?

    Thanks
    Jesse Bunch
    www.getbunch.com/
    If I have helped you, please rate my posts!

    Unless otherwise indicated, I am using the following Products:

    Visual Studio .NET 2010
    .NET Framework 4.0

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [02/03] Shutdown

    There is an API function called SH_SHUTDOWN (google "api-guide" for details).

    Also see the DOS "shutdown" command (whih you can call using Process.Start("Shutdown...") )
    I don't live here any more.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Shutdown

    If your app is only going to be used on NT-based OSes then starting a shutdown process is quite flexible. If you need support for older Windows versions then go the API route. SHShutDownDialog will display the Windows shutdown dialog. ExitWindowsEx will shutdown the system. There is also the option of the Shutdown class from Mentalis (see my signature) that encapsulates all that stuff and presents you with a simple-to-use interface.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    137

    Re: [02/03] Shutdown

    Thanks for that....but I am a newbie to API Calls....Can anyone provide me with a sample code that I can use in VB.net 2002 to call the ExitWindowsEx Api?

    Thanks
    Jesse Bunch
    www.getbunch.com/
    If I have helped you, please rate my posts!

    Unless otherwise indicated, I am using the following Products:

    Visual Studio .NET 2010
    .NET Framework 4.0

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Shutdown

    There are many examples posted on the forum already. A quick search should turn up what you need. Like I said, you can avoid using API calls youself if you use the class provided by Mentalis. They wrap the APIs in a .NET class so they are hidden from you, although you have the source so you can see how they do it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: [02/03] Shutdown

    this works for me

    'this will shut down the system.
    Process.Start("shutdown", "-s -t 00")

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Shutdown

    Quote Originally Posted by FireKnox101
    this works for me

    'this will shut down the system.
    Process.Start("shutdown", "-s -t 00")
    Shutdown.exe exists only in NT-based OSes. Windows Me and earlier do not support it, so if you need to support those operating systems then you need to use APIs.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: [02/03] Shutdown

    O i didnt know that =), that is good to know ty

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width