When my application is closed by the user, I want to shutdown the system also. How to go for it??
Printable View
When my application is closed by the user, I want to shutdown the system also. How to go for it??
search the forum
the easiest way is to send this command:
that tells the computer to shutdown within 0 seconds so the user doesn't see the box telling them it is being shutdown.Code:shell("shutdown -t 0 -s")
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.
shell is an old vb6 command.
the .NET equivalent is the Process.Start function.
Why do you want to shutdown the system when they close your app?
Well the shell code still works in vb. netQuote:
Originally Posted by tr333
Maybe it's a kind of virus :pQuote:
Why do you want to shutdown the system when they close your app?
agreed, however, it looked cleaner on my particular machine using the above command rather than this:Quote:
Originally Posted by tr333
it just seemed like it didn't take as long etc etc.VB Code:
Process.Start("shutdown", "-t 0 -s")
but you're right. Process.Start() is the 'dot net' way.
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().
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