代码如下,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);
}
请高手们指导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);
}
解决方案 »
- 后台触发前台脚本事件的问题
- 有点难度的问题,谢谢大家!
- WinForm,DataGrid中如何设定某一列的颜色与其他列显示的不同?
- 如何将数据库中的Binary类型的数据转换成string?
- 急问怎么用ADSI控制目录权限,或用其他方法,~~~顶着有分~~~~
- vb.net的字符串函数在C#中对应的字符串函数?
- C# List<T> 作为参数的问题
- C# GDI+怎么将图片填充到多边形
- xsl文件中 的日期用ms:format-time 格式化日期的问题
- 怎么xml文件头无 <?xml 也不报错 ? 怎么加了 xsd 也没有验证 ,在ie照样执行
- usercontrol
- Visual Studio2005与unity
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;
}
}
能不能在我的代码基础上改一改,我最想知道的是我错在什么地方
如果纯粹要重启的话,我直接调用windows api的exitwindows()就能解决了