Exemple #1
0
        public static int ForceReboot(string MachineName, ShutdownStyles ShutdownStyle)
        {
            int result = -1;

            try
            {
                ObjectGetOptions     options = new ObjectGetOptions();
                ManagementClass      WMI_W32_OS = new ManagementClass(string.Format(@"\\{0}\root\cimv2", MachineName), "Win32_OperatingSystem", options);
                ManagementBaseObject inputParams, outputParams;
                foreach (ManagementObject oneInstance in WMI_W32_OS.GetInstances())
                {
                    inputParams             = oneInstance.GetMethodParameters("Win32Shutdown");
                    inputParams["Flags"]    = (int)ShutdownStyle;
                    inputParams["Reserved"] = 0;

                    outputParams = oneInstance.InvokeMethod("Win32Shutdown", inputParams, null);

                    result = Convert.ToInt32(outputParams["returnValue"]);
                    break;
                }
            }
            catch (Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Terminals was not able to reboot the remote machine.  Reason:\r\n" + exc.Message);
            }
            return(result);
        }
        public static int ForceReboot(string MachineName, ShutdownStyles ShutdownStyle)
        {
            int result = -1;
            try
            {

                ObjectGetOptions options = new ObjectGetOptions();
                ManagementClass WMI_W32_OS = new ManagementClass(string.Format(@"\\{0}\root\cimv2", MachineName), "Win32_OperatingSystem", options);
                ManagementBaseObject inputParams, outputParams;
                foreach(ManagementObject oneInstance in WMI_W32_OS.GetInstances())
                {
                    inputParams = oneInstance.GetMethodParameters("Win32Shutdown");
                    inputParams["Flags"] = (int)ShutdownStyle;
                    inputParams["Reserved"] = 0;

                    outputParams = oneInstance.InvokeMethod("Win32Shutdown", inputParams, null);

                    result = Convert.ToInt32(outputParams["returnValue"]);
                    break;
                }
            }
            catch(Exception exc)
            {
                System.Windows.Forms.MessageBox.Show("Terminals was not able to reboot the remote machine.  Reason:\r\n" + exc.Message);
            }
            return result;
        }