社区
C#
帖子详情
请问如何用c#来实现远程开、重起、关机?
zteclx
2006-03-20 09:11:50
请问如何用c#来实现远程开、重起、关机?远程主机装的是2003server操作系统!
...全文
351
14
打赏
收藏
请问如何用c#来实现远程开、重起、关机?
请问如何用c#来实现远程开、重起、关机?远程主机装的是2003server操作系统!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zteclx
2006-03-28
打赏
举报
回复
谁有在2003server下调试通过的代码?
zteclx
2006-03-22
打赏
举报
回复
代码都是在2000下的,在2003server下如何用?
jrl5365
2006-03-22
打赏
举报
回复
学习一下,收藏了
zteclx
2006-03-22
打赏
举报
回复
远程重起,只是远端有防火墙,能用henry3695的方法吗?
dayasky
2006-03-22
打赏
举报
回复
远程开机真的可以做到吗?
电脑没有开的时候,谁来响应你的.net命令呀?
zteclx
2006-03-22
打赏
举报
回复
henry3695() ( ) 老兄,您的代码如果在远端有防火墙的情况下能用吗?
BookSirSwordsMan
2006-03-20
打赏
举报
回复
楼上说的都对,用WMI需要有远程系统的管理员权限用户,不过可以在远程的机子上放一个程序,直接调用远程机子的WMI就可以了,当然前提是那个程序也要在管理员权限下
还可以参考这个http://www.programfan.com/article/showarticle.asp?id=2244
Knight94
2006-03-20
打赏
举报
回复
sample as follows:
http://topic.csdn.net/t/20030424/22/1704985.html
Sangel
2006-03-20
打赏
举报
回复
用WMI
cic_wxf
2006-03-20
打赏
举报
回复
厉害,整合我用
lovvver
2006-03-20
打赏
举报
回复
http://community.csdn.net/Expert/topic/4598/4598649.xml?temp=.1263239
我看你有戏
2006-03-20
打赏
举报
回复
C#创建超管号,把这块和上面那块结合一下,写成服务端
//using System.DirectoryServices;
//需要应用dll的
//建帐号2000测试通过
//
try
{
DirectoryEntry AD = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add("hjg", "user"); //帐号
NewUser.Invoke("SetPassword", new object[] {"123456ob"}); // 密码
NewUser.Invoke("Put", new object[] {"Description", "管理计算机(域)的内置帐户"});
NewUser.CommitChanges();
DirectoryEntry grp;
grp = AD.Children.Find("Administrators", "group");
if (grp != null) {grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
Console.WriteLine("Account Created Successfully");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
我看你有戏
2006-03-20
打赏
举报
回复
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Management;
public class Form1 : System.Windows.Forms.Form
{
private TextBox textBox1 ;
private TextBox textBox2 ;
private TextBox textBox3 ;
private Label label1 ;
private Label label2 ;
private Label label3 ;
private Button button1 ;
private System.ComponentModel.Container components = null ;
public Form1 ( )
{
//初始化窗体中的各个组件
InitializeComponent ( ) ;
}
//清除程序中使用过的资源
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose ( ) ;
}
}
base.Dispose ( disposing ) ;
}
private void InitializeComponent ( )
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(140, 46);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(172, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(138, 85);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(174, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(139, 120);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(173, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 50);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 16);
this.label1.TabIndex = 1;
this.label1.Text = "机器名称或IP地址:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(37, 88);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "管理者名称:";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(37, 125);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 16);
this.label3.TabIndex = 1;
this.label3.Text = "管理者密码:";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// button1
//
this.button1.Location = new System.Drawing.Point(95, 168);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 32);
this.button1.TabIndex = 3;
this.button1.Text = "重新启动远程计算机";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(336, 245);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Name = "Form1";
this.Text = "利用C#重新启动远程计算机";
this.ResumeLayout(false);
}
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
}
private void button1_Click ( object sender , System.EventArgs e )
{
//定义连接远程计算机的一些选项
ConnectionOptions options = new ConnectionOptions ( ) ;
options.Username = textBox2.Text ;
options.Password = textBox3.Text ;
ManagementScope scope = new ManagementScope( "\\\\" + textBox1.Text + "\\root\\cimv2", options ) ;
try
{
//用给定管理者用户名和口令连接远程的计算机
scope.Connect ( ) ;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;
ManagementObjectSearcher query1 = new ManagementObjectSearcher ( scope , oq ) ;
//得到WMI控制
ManagementObjectCollection queryCollection1 = query1.Get ( ) ;
foreach ( ManagementObject mo in queryCollection1 )
{
string [ ] ss= { "" } ;
//重启远程计算机
mo.InvokeMethod ( "Reboot" , ss ) ;
}
}
//报错
catch ( Exception ee )
{
MessageBox.Show ( "连接" + textBox1.Text + "出错,出错信息为:" + ee.Message ) ;
}
}
}
zteclx
2006-03-20
打赏
举报
回复
我用wmi在远程主机是2003server的情况,程序报rpc服务不可用,我想是不是2003server操作系统的问题还是有防火墙的原因?
c#
写的一个
远程
关机
标题 "
c#
写的一个
远程
关机
" 描述的是一个使用
C#
编程语言
实现
的
远程
关机
功能。这个功能允许
开
发者通过修改代码中的目标IP地址,就能
实现
对
远程
计算机的
关机
操作。它已经在学校的环境中进行了测试,并且作者希望这个...
c#
实现
远程
关机
本主题聚焦于如何利用
C#
实现
远程
关机
功能,这是一个涉及到操作系统交互和网络通信的重要技术点。 首先,要
实现
远程
关机
,
C#
开
发者需要理解Windows API,这是微软提供的操作系统接口,允许程序员访问操作系统底层的...
C#
实现
远程
关机
和和
远程
重启
在
C#
编程环境中,
实现
远程
关机
和重启功能主要涉及到Windows API调用和网络通信的知识。下面将详细讲解这些知识点: 1. **Windows API调用**:
C#
本身并不直接支持
远程
系统操作,如
关机
或重启,但可以通过调用Windows...
C#
实现
远程
关机
(重启、注销)源码
本示例中,我们将深入探讨如何利用
C#
来
实现
远程
计算机的
关机
、重启和注销功能,这些功能是通过Windows Management Instrumentation(WMI)技术
实现
的。 WMI是微软提供的一种管理系统资源的方法,它允许程序通过脚本...
C#
111,124
社区成员
642,539
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章