rmatthew Posted January 24, 2003 Posted January 24, 2003 I need to forcefully reboot the system. Any ideas? Quote
rmatthew Posted January 24, 2003 Author Posted January 24, 2003 The computer is not local - several miles from ANYWHERE - in some instances we have to travel out to the location (not easily accessible in some weather) just to reboot the system. Most of the time you can ping the pc etc. I think to save time we need to be able to forece a reboot from within the program. In any case there are (I beleive) reasonable circumstances. The people that travel to the location usually end up just 'hitting the switch' anyway. Quote
*Gurus* divil Posted January 24, 2003 *Gurus* Posted January 24, 2003 There's no way built in to the .NET framework. Look up the ExitWindowsEx API instead. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
rmatthew Posted January 24, 2003 Author Posted January 24, 2003 That's what I thought... Beenworking with that - seems to work somethime - sometimes not. Never at all from a service?? Quote
*Experts* Nerseus Posted January 25, 2003 *Experts* Posted January 25, 2003 From the help for ExitWindowsEx: The ExitWindowsEx function returns as soon as it has initiated the shutdown. The shutdown or logoff then proceeds asynchronously. The function is designed to stop all processes in the caller's logon session. Therefore, if you are not the interactive user, the function can succeed without actually shutting down the computer. If you are not the interactive user, use the InitiateSystemShutdown or InitiateSystemShutdownEx function. If you're running this from a service you're probably not the interactive user (same as if you were to run this from a COM+ component with an Identity set) so the Shutdown may not work. Did you specify the following flags: EWX_FORCE, EWX_FORCEIFHUNG, etc.? There are some notes in the help when you may want to use these flags and you may need more than the two above. Other than the above, I have no idea. I've never tried rebooting programatically. It seems like you'd only want to force a reboot when the machine was hung, but then your program or service isn't likely to succeed in rebooting. If something else is wrong, like the website's not responding, you'd want to FIX instead of just rebooting. You could shell out to "iisreset" or something similar. If COM+ stops responding you could restart the services and optionally issue a "shutdown" command to each package. 99% of the time there will be something else wrong and you won't necessarily have to reboot. We have some development servers that have been up for over 180 days. One runs SQL Server another runs our development website. Granted, we have to issue "iisreset" a couple of times a week after someone locks it up, but rebooting is usually something you do when you don't know enough to fix what's really wrong, IMO. It's a good oportunity to learn more about what your programs are doing possibly :) -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Madz Posted January 26, 2003 Posted January 26, 2003 Well, Dear if the system if miles away from you, how do you want to shut down it. Remotely or by sending some EXE to user and ask it to open file. if you mention the second one then ExitWindowsEx works but if the first one mean remotely then. first of all you need a make a client program with winsock which listen for commands and then the server program which sends commands to client. if you need code i have it. Quote The one and only Dr. Madz eee-m@il
rmatthew Posted January 26, 2003 Author Posted January 26, 2003 I have a snippet that listens to a port for the command to reboot. It works now using the API call (of course still not in service - permissions should fix that.) Note that this is a VERY RARE occurrence. I am going to do some more digging into directing it more toward starting and stopping services as needed though. I appreciate all of the help and comments everybody has had on this subject :) Quote
sj_hicks Posted January 13, 2004 Posted January 13, 2004 You can use WMI to reboot a remote PC. The below code calls the WMI reboot() method from VB.NET. It reboots the current PC ("."). If you substitute this for another machine name my changing strComputer and you have access to that machine, it should reboot the remote PC (although I haven't tested this funcitonality). Sub WMIReboot() Dim strComputer As String = "." Dim options As New ConnectionOptions options.Impersonation = ImpersonationLevel.Impersonate options.EnablePrivileges = True Dim ms As New ManagementScope("\\" & strComputer & "\root\CIMV2", options) Dim q As New SelectQuery("SELECT * FROM Win32_OperatingSystem") Dim search As New ManagementObjectSearcher(ms, q) ' enum each entry for Win32_OperatingSystem and call WMI reboot method Dim info As ManagementObject For Each info In search.Get() info.InvokeMethod("Reboot", Nothing) Next End Sub If you want to do this from a VBS script instead of a compiled EXE, checkout the examples in the MS script center: http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.