Is there a way to shut down a PC using the framenetwork
I tried the "shutdown /s" command but the shell doesn't work on my PC.
Thanks.
Is there a way to shut down a PC using the framenetwork
I tried the "shutdown /s" command but the shell doesn't work on my PC.
Thanks.
Shut Down PC
wenxincao
Mnd1
YoungEngineer
there isnt a class that does this in the .NET Framework but using the shutdown command will work, if your OS supports the shutdown command (Windows 2000, Windows Server 2003, XP and Vista). The correct way of doing so if you have the above:
Dim thePSI as new System.Diagnostics.ProcessStartInfo("shutdown.exe")
thePSI.Arguments = "/m \\computerName /s /t 10"
System.Diagnostics.Process.Start(thePSI)
does this not work for you If it works, it should shutdown the computer after 10 seconds
alternatively you could try this method but wouldnt recommend it (permission issues perhaps but also you are P/Invoking which can be expensive sometimes)
imports System.Runtime.InteropServices
..
..
Enum ExitWindows
LogOff = &H0
ShutDown = &H1
Reboot = &H2
PowerOff = &H8
RestartApps = &H40
Force = &H4
ForceIfHung = &H10
End Enum
Enum ShutdownReasonMajorApplication = &H40000
MajorHardware = &H10000
MajorLegacyApi = &H70000
MajorOperatingSystem = &H20000
MajorOther = &H0
MajorPower = &H60000
MajorSoftware = &H30000
MajorSystem = &H50000
MinorBlueScreen = &HF
MinorCordUnplugged = &HB
MinorDisk = &H7
MinorEnvironment = &HC
MinorHardwareDriver = &HD
MinorHotfix = &H11
MinorHung = &H5
MinorInstallation = &H2
MinorMaintenance = &H1
MinorMMC = &H19
MinorNetworkConnectivity = &H14
MinorNetworkCard = &H9
MinorOther = &H0
MinorOtherDriver = &HE
MinorPowerSupply = &HA
MinorProcessor = &H8
MinorReconfig = &H4
MinorSecurity = &H13
MinorSecurityFix = &H12
MinorSecurityFixUninstall = &H18
MinorServicePack = &H10
MinorServicePackUninstall = &H16
MinorTermSrv = &H20
MinorUnstable = &H6
MinorUpgrade = &H3
MinorWMI = &H15
FlagUserDefined = &H40000000
FlagPlanned = &H80000000
End Enum...
...
<DllImport("user32.dll", SetLastError:=true)>Private Shared Function ExitWindowsEx(byval uFlags as ExitWindows, byval dwFlags as ShutdownReason) as Boolean
End Function
'calling it:
ExitWindowsEx(ExitWindows.ShutDown, ShutdownReason.MajorOther And ShutdowReason.MinorOther) 'not sure if this works well, experiment!
CodeDigger
It works at last but I'm curious how
Process.Start("shutdown /s")
doesn't work. It says it can't find the file and this doesn't work either...
Shell "shutdown /s"
process.start(SystemDirectory & "\shutdown /s") - can't find file
However, Start| Run| Cmd |shutdown /s does work... so the OS is able to
find shutdown from any directory, but with shell or process can't.