进程中如何通过Process.Start()打开程序

wangcm888 2010-07-12 03:06:29
做一个开启远程机器客户程序的程序,用Socket做,打开程序用Process.Start()做,调试模式下可以打开客户程序,正常打开exe文件时,就打不开客户程序。
private void Form1_Load(object sender, EventArgs e)
{

Thread th = new Thread(new ThreadStart(NewMethod));
th.IsBackground = true;
th.Start();

}

private void NewMethod()
{
while (true)
{
try
{
int port = 2000;
string host = "192.168.0.60";
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Bind(ipe);
s.Listen(20);
Socket temp = s.Accept();
Console.WriteLine("get a connect");
string revStr = "";
byte[] recvBytes = new byte[1024];
int bytes;
bytes = temp.Receive(recvBytes);
revStr += Encoding.ASCII.GetString(recvBytes).Replace("\0","");
if (revStr == "shutdown")
{
System.Diagnostics.Process.Start("cmd.exe", "shutdown -s -t 0");

}

if (revStr == "osk")
{
System.Diagnostics.Process.Start("osk.exe");

}
if (revStr == "notepad")
{
System.Diagnostics.Process.Start("osk.exe");

}

listBox1.Items.Add(DateTime.Now.ToString()+ " "+ revStr);
string sendStr = "OK,Client Send Message Successful!";
byte[] bs = Encoding.ASCII.GetBytes(sendStr);
temp.Send(bs, bs.Length, 0);
temp.Close();
s.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
...全文
177 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mdmzl 2010-07-12
  • 打赏
  • 举报
回复
想知道LZ是怎么做的.
铛铛 2010-07-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wangcm888 的回复:]
可以了
[/Quote]
wangcm888 2010-07-12
  • 打赏
  • 举报
回复
可以了
wangcm888 2010-07-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 thoughter 的回复:]
PATH里面有没有%windir%\system32,另外,是否存在osk.exe文件?
[/Quote]
path里面也有%windir%\system32,也存在osk.exe
thoughter 2010-07-12
  • 打赏
  • 举报
回复
PATH里面有没有%windir%\system32,另外,是否存在osk.exe文件?
wangcm888 2010-07-12
  • 打赏
  • 举报
回复
如果服务器端发送过来的命令为"osk",则客户端要打开屏幕键盘才对,现在是没反应,但在调试模式下就能打开
rabbit5 2010-07-12
  • 打赏
  • 举报
回复
权限问题?
铛铛 2010-07-12
  • 打赏
  • 举报
回复
打不开是什么概念

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧