不对,lizheng是管理员。你看看错误啊。根本就不是错在用户、密码上,这个是没有问题的,是错在内40行,我有作标记的,你看看

解决方案 »

  1.   

    取得的queryCollection1 可能为空
      

  2.   

    对方是window 2000 professional ,the same to me!
      

  3.   

    说真的,你们问的问题都不对,根本与那些无关,我现在反复活测试,只是
     For Each mo In queryCollection1     异常详细信息: System.Management.ManagementException: 无效类别 
    不知为何?
      

  4.   

    OK.对于Reboot方法
    我猜professional应该不行
    找一台window 2000 Server 去试一下.
    如果还不行,我可以复制你的代码测试
      

  5.   

    If queryCollection1 Is Nothing Then
                    Response.Write("<script>alert('queryCollection1 is null');</script>")
                End If
    我测试了一下,queryCollection1的值不为空。
      

  6.   

    foreach ( mangementobject mo in querycollection)
    {
       if (mo!=null)
       {
        ...
        }
    }
      

  7.   

    我去查MSDN了贴下来:
    Win32_OperatingSystem.Reboot
    The Reboot WMI class method shuts down the computer system, then restarts it. On computers running Windows NT/Windows 2000, the calling process must have the SE_SHUTDOWN_NAME privilege.This topic uses Visual Basic&reg; syntax. For information about using this method with C/C++, see Calling a Method.Function Reboot() As Integer
    Parameters
    This method has no parameters. 
    Return Values
    Returns zero (0) to indicate success. Any other number indicates an error.Requirements
    Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later.
    Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server 4.0 SP4 and later.
    Header: Declared in Cimwin32.mof.
    Namespace: Included in \root\cimv2.看Requirements里面
    Client 可以是 professional
    Server 连 Windows XP 都不包括在内。可见只有Server 平台的操作系统支持此方法但是代码我也没试过。只是猜一下在MSDN 2003中的位置是这里:
    ms-help://MS.MSDNQTR.2003FEB.2052/wmisdk/wmi/reboot_method_in_class_win32_operatingsystem.htm
      

  8.   

    在服务器下有这种错误提示。看来确实是要在服务器上远程控制。
    异常详细信息: System.UnauthorizedAccessException: 拒绝访问。 未授权此 ASP.NET 进程访问所请求的资源。出于安全原因,默认的 ASP.NET 进程标识为“{machinename}\ASPNET”,它只具有有限的特权。请考虑授予该 ASP.NET 进程标识访问此资源的权限。 若要授予 ASP.NET 对文件的写访问权,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”以添加“{machinename}\ASPNET”用户。突出显示此 ASP.NET 帐户,在“允许”列中选中“写”框。
    怎么做啊。在服务器哪有文件右击啊?
    怎么做啊。在服务器哪有文件右击啊?
    怎么做啊。在服务器哪有文件右击啊?
      

  9.   

    若要授予 ASP.NET 对文件的写访问权,这个对文件的文件名是哪个啊?应该是在服务器上的。
      

  10.   

    前面猜的可能错了.
    我对目标机 XP professional 测试成功。
    下面是代码:
    拿C#写了一下.后来改成VB.NET也没问题:C# :
    ConnectionOptions ConOptions = new ConnectionOptions();
    ConOptions.Username = "{AdminUser}";
    ConOptions.Password = "{myPassword}";
    ConOptions.EnablePrivileges = true;
    ManagementScope scope = new ManagementScope("\\\\{Target}\\root\\cimv2", ConOptions);
    scope.Connect();
    ObjectQuery OQuery = new ObjectQuery("Select * From Win32_OperatingSystem Where Primary = true");
    ManagementObjectSearcher OSearcher = new ManagementObjectSearcher(scope, OQuery);
    foreach(ManagementObject MO in OSearcher.Get())
    {
      MO.InvokeMethod("Reboot", null);
    }
    MessageBox.Show("Restart?");VB.NET:Dim ConOptions As ConnectionOptions = New ConnectionOptions
    ConOptions.Username = "{AdminUser}"
    ConOptions.Password = "{myPassword}"
    ConOptions.EnablePrivileges = True
    Dim scope As ManagementScope = New ManagementScope("\\{Target}\root\cimv2", ConOptions)
    scope.Connect()
    Dim OQuery As ObjectQuery = New ObjectQuery("Select * From Win32_OperatingSystem Where Primary = true")
    Dim OSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, OQuery)
    Dim MO As ManagementObject
    For Each MO In OSearcher.Get()
      MO.InvokeMethod("Reboot", Nothing)
    Next
    MessageBox.Show("Restart?")ConnectionOptions 的 EnablePrivileges 属性要设为True 启用特权操作
    将管理员用户密码和目标机替换代码中相应位置即可