代码如下,xp sp3下执行,报错“无效参数”
请高手们指导private void RebootComputer()
        {
            try
            {
                ManagementObject classInstance = new ManagementObject("root\\CIMV2", "Win32_OperatingSystem.", null);                ManagementBaseObject outParams = classInstance.InvokeMethod("Reboot", null, null);                Console.WriteLine("Out parameters:");
                Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
            }
            catch (ManagementException err)
            {
                MessageBox.Show("WMI执行错误: " + err.Message);
            }

解决方案 »

  1.   


    public static string ShutDownComputer(string strHost,string strUserName,string strPassWrod)
    {
    try 
    {
    ConnectionOptions Options = new ConnectionOptions();         // 定义连接远程计算机的一些选项
    Options.Username          = strUserName;
    Options.Password          = strPassWrod;                     //远程计算机名或IP地址   
    ManagementScope Scope     = new ManagementScope(string.Format("\\\\{0}\\root\\cimv2",strHost),Options); Scope.Connect();                                             // 用给定管理者用户名和口令连接远程的计算机
    System.Management.ObjectQuery oq           = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");
    ManagementObjectSearcher   Query           = new ManagementObjectSearcher(Scope,oq);
    ManagementObjectCollection QueryCollection = Query.Get();    // 得到WMI控制
    foreach(ManagementObject mo in QueryCollection) 
    {
    mo.InvokeMethod("Reboot",new string[]{""});              // 重启远程计算机
    }
    return null;
    }
    catch(Exception me)
    {
    return me.Message;
    }
    }
      

  2.   

    我要的是本地计算机重启,isjoe,你的代码我看过了
    能不能在我的代码基础上改一改,我最想知道的是我错在什么地方
    如果纯粹要重启的话,我直接调用windows api的exitwindows()就能解决了