|
-
Mar 31st, 2005, 11:09 AM
#1
Thread Starter
Fanatic Member
System Shutdown
When my application is closed by the user, I want to shutdown the system also. How to go for it??
-
Mar 31st, 2005, 11:17 AM
#2
"The dark side clouds everything. Impossible to see the future is."
-
Apr 1st, 2005, 02:03 PM
#3
Frenzied Member
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.
-
Apr 1st, 2005, 02:30 PM
#4
Frenzied Member
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.
-
Apr 2nd, 2005, 10:18 AM
#5
Re: System Shutdown
shell is an old vb6 command.
the .NET equivalent is the Process.Start function.
-
Apr 2nd, 2005, 10:24 AM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 3rd, 2005, 02:42 AM
#7
Hyperactive Member
Re: System Shutdown
 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
-
Apr 3rd, 2005, 04:08 AM
#8
Addicted Member
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...

-
Apr 3rd, 2005, 09:59 PM
#9
Frenzied Member
Re: System Shutdown
 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:
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.
-
Apr 3rd, 2005, 10:39 PM
#10
Re: System Shutdown
Shell() wraps the CreateProcess
Process.Start uses both CreateProcess/ShellExecuteEx (by default uses ShellExecuteEx)
VB Code:
Dim sdwn As New ProcessStartInfo("shutdown", "-t 0 -s")
sdwn.CreateNoWindow = True
sdwn.UseShellExecute = False ' use the same api as Shell()
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
-
Apr 4th, 2005, 02:03 AM
#11
Thread Starter
Fanatic Member
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:
Imports System.Management
Public Class clsWMI
Private obj As Object
Public Enum ShutDownOptions
LogOff = 0
SHUTDOWN = 1
REBOOT = 2
FORCE = 4
POWEROFF = 8
End Enum
Public WriteOnly Property ShutDown() As Integer
'Value should be ShutDownOptions
Set(ByVal Value As Integer)
For Each obj In GetObject("winmgmts:{(shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
obj.Win32Shutdown(Value)
Next
End Set
End Property
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|