Results 1 to 11 of 11

Thread: System Shutdown

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    System Shutdown

    When my application is closed by the user, I want to shutdown the system also. How to go for it??

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: System Shutdown

    search the forum
    "The dark side clouds everything. Impossible to see the future is."

  3. #3
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: System Shutdown

    the easiest way is to send this command:
    Code:
    shell("shutdown -t 0 -s")
    that tells the computer to shutdown within 0 seconds so the user doesn't see the box telling them it is being shutdown.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: System Shutdown

    for more info on that command, goto a command prompt, type 'shutdown' and you'll see the entire argument list. you can even restart the pc using that command.

  5. #5
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: System Shutdown

    shell is an old vb6 command.

    the .NET equivalent is the Process.Start function.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: System Shutdown

    Why do you want to shutdown the system when they close your app?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Hyperactive Member
    Join Date
    Apr 2005
    Posts
    331

    Re: System Shutdown

    Quote Originally Posted by tr333
    shell is an old vb6 command.

    the .NET equivalent is the Process.Start function.
    Well the shell code still works in vb. net

  8. #8
    Addicted Member
    Join Date
    Apr 2005
    Location
    Croatia
    Posts
    183

    Re: System Shutdown

    Why do you want to shutdown the system when they close your app?
    Maybe it's a kind of virus
    It has been said that something as
    small as the flutter of a butterfly's
    wing can ultimately cause a typhoon
    halfway around the world...


  9. #9
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: System Shutdown

    Quote Originally Posted by tr333
    shell is an old vb6 command.

    the .NET equivalent is the Process.Start function.
    agreed, however, it looked cleaner on my particular machine using the above command rather than this:


    VB Code:
    1. Process.Start("shutdown", "-t 0 -s")
    it just seemed like it didn't take as long etc etc.

    but you're right. Process.Start() is the 'dot net' way.

  10. #10
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: System Shutdown

    Shell() wraps the CreateProcess

    Process.Start uses both CreateProcess/ShellExecuteEx (by default uses ShellExecuteEx)

    VB Code:
    1. Dim sdwn As New ProcessStartInfo("shutdown", "-t 0 -s")
    2.  
    3.         sdwn.CreateNoWindow = True
    4.         sdwn.UseShellExecute = False ' use the same api as Shell()
    5.  
    6.         Process.Start(sdwn)

    This should have no noticeable speed difference from Shell().
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  11. #11

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: System Shutdown

    Well, I am not developing any virus as such. I have a given an option to the user where after the backup is taken the system should be powered off. Found the code in this forum.

    VB Code:
    1. Imports System.Management
    2.  
    3. Public Class clsWMI
    4.     Private obj As Object
    5.  
    6.     Public Enum ShutDownOptions
    7.         LogOff = 0
    8.         SHUTDOWN = 1
    9.         REBOOT = 2
    10.         FORCE = 4
    11.         POWEROFF = 8
    12.     End Enum
    13.  
    14.     Public WriteOnly Property ShutDown() As Integer
    15.         'Value should be ShutDownOptions
    16.         Set(ByVal Value As Integer)
    17.             For Each obj In GetObject("winmgmts:{(shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
    18.                 obj.Win32Shutdown(Value)
    19.             Next
    20.         End Set
    21.     End Property
    22. End Class

    Regards

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