我用c#想实现本机电脑重启报错,代码如下,在xp下执行报“无效参数” 请高手指点

[复制链接]
查看11 | 回复1 | 2011-6-19 16:38:09 | 显示全部楼层 |阅读模式
private void RebootComputer()

{

try

{

ManagementObject classInstance = new ManagementObject("root\\CIMV2", "Win32_OperatingSystem.", null);

// Execute the method and obtain the return values.

ManagementBaseObject outParams = classInstance.InvokeMethod("Reboot", null, null);

// List outParams

Console.WriteLine("Out parameters:");

Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);

}

catch (ManagementException err)

{

MessageBox.Show("WMI执行错误: " + err.Message);

}
我是想用wmi实现,如果只要重启,我都可以用exitwindows()实现
我想搞清楚ManagementObject classInstance = new ManagementObject("root\\CIMV2", "Win32_OperatingSystem.", null);这个格式错在什么地方

回复

使用道具 举报

千问 | 2011-6-19 16:38:09 | 显示全部楼层
先导入包:using System.Diagnostics;然后再在窗体中设置一个按钮,在按钮事件里面写入以下代码运行程序当你点那个按钮的时候就能实现重启计算机了:
DialogResult rs = MessageBox.Show("此操作将会重启您的计算机,您确定要执行此操作吗?","关闭计算机",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
if (rs==DialogResult.OK)
{
ProcessStartInfo ps = new ProcessStartInfo();...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行