C# 手机控制电脑关机
本帖最后由 济南枫 于 2013-8-23 17:35 编辑客户端:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Web;
using System.Net;
using System.Diagnostics;
namespace 手机自动远程关机
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Hide();
this.ShowInTaskbar = false;
timer1.Enabled = true;
timer1.Interval = 10000;
}
private void timer1_Tick(object sender, EventArgs e)
{
WebClient tongip = new WebClient();
tongip.Encoding = Encoding.UTF8;
try
{
string cip = "";
cip = tongip.DownloadString("http://www.XXXXX.com/b.html");
if (cip == "a")
{
MessageBox.Show(cip);
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.CreateNoWindow = true; myProcess.Start();
myProcess.StandardInput.WriteLine("shutdown -s -t 0");
}
else
{
MessageBox.Show("不用关机");
}
}
catch
{
MessageBox.Show("错了");
}
}
}
}
手机端(需要一个支持PHP的空间):
<?php
$filename = "b.html";
$handle = fopen ($filename,"w");
$content=$_GET['get'];
if (!is_writable ($filename)){
die ("文件:".$filename."不可写,请检查其属性后重试!");
}
if (!fwrite ($handle,$content)){//将信息写入文件
die ("生成文件".$filename."失败!");
}
fclose ($handle); //关闭指针
die ("创建文件".$filename."成功!");
?>
当用手机访问网址,然后加上参数,远程电脑获取到要关机的命令 就关机了
C#也可以做到?逆天了 唉。。。不明觉厉额。膜拜。 不懂帮顶 虽不明,但觉厉! 需要服务器? 神人呀大牛呀膜拜呀···· 不明觉厉{:1_919:} 很不错。值得学习。 你弄个关机的,那我传个开机的吧
需要主板支持远程唤醒,加个网卡也行
private static void WakeUp(byte[] mac)
{
try
{
UdpClient client = new UdpClient();
client.Connect(IPAddress.Broadcast, 30000);
byte[] packet = new byte;
for (int i = 0; i < 6; i++)
{
packet = 0xFF;
}
for (int i = 1; i <= 16; i++)
{
for (int j = 0; j < 6; j++)
{
packet = mac;
}
}
int result = client.Send(packet, packet.Length);
MessageBox.Show("启动命令已发送:" + result.ToString());
}
catch (SystemException ERR)
{
MessageBox.Show("失败:" + ERR.ToString());
}
}
//1号机
private void button1_Click(object sender, EventArgs e)
{
byte[] bt1 = new byte[] { 0xEC, 0x88, 0x8F, 0xE7, 0x7C, 0x65 };//0xD0, 0x27, 0x88, 0xD7, 0x64, 0xB3
WakeUp(bt1);
}
//2号机
private void button3_Click(object sender, EventArgs e)
{
byte[] bt1 = new byte[] { 0xD0, 0x27, 0x88, 0xD7, 0xB6, 0x8A };// 0xD0, 0x27, 0x88, 0xDC, 0xB6, 0x8A
WakeUp(bt1);
}
//启动笔记本2
private void button2_Click(object sender, EventArgs e)
{
byte[] bt1 = new byte[] { 0x00, 0x1B, 0x77, 0xC1, 0x8C, 0x9A };
WakeUp(bt1);
byte[] bt2 = new byte[] { 0x00, 0x1F, 0x16, 0x50, 0x31, 0x05 };
WakeUp(bt2);
}
//服务器
private void button4_Click(object sender, EventArgs e)
{
byte[] bt2 = new byte[] { 0x00, 0x12, 0x3F, 0x32, 0xCB, 0x35 };
WakeUp(bt2);
}
页:
[1]
2