【发布时间】:2011-03-08 23:19:59
【问题描述】:
在 C# 中是否有任何简单的方法可以将命令发送到计算机上的 VNC 服务器。理想情况下,某种图书馆或其他东西会很好,但实际上是最简单的。我想做的只是连接并发送命令,我什至不想查看桌面。
谢谢
【问题讨论】:
-
你想发送什么样的命令?鼠标按键?按键?一个shell命令?
-
啊只是按键。如CTRL-ALT-DELETE、通用文本等。
在 C# 中是否有任何简单的方法可以将命令发送到计算机上的 VNC 服务器。理想情况下,某种图书馆或其他东西会很好,但实际上是最简单的。我想做的只是连接并发送命令,我什至不想查看桌面。
谢谢
【问题讨论】:
有VncSharp。
【讨论】:
这里有两种替代解决方案 方法一:
Process pl = new Process();
pl.StartInfo.CreateNoWindow = false;
pl.StartInfo.FileName = "calc.exe";
pl.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
// = ProcessWindowStyle.Hidden; if you want to hide the window
pl.Start();
System.Threading.Thread.Sleep(1000);
SendKeys.SendWait("11111");
方法二:
using System.Runtime.InteropServices;
// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
private void test()
{
IntPtr calculatorHandle = FindWindow("CalcFrame", "Calculator");
// Verify that Calculator is a running process.
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("Calculator is not running.");
return;
}
// Make Calculator the foreground application and send it
// a set of calculations.
SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("111");
SendKeys.SendWait("*");
SendKeys.SendWait("11");
SendKeys.SendWait("=");
}
【讨论】: