C# send VNC commands
Is there any simpl开发者_StackOverflowe way in C# to send commands to a VNC server on a computer. Ideally some sort of library or something would be nice but whatever is simplest really. All I want to be able to do is just connect and send a command, I don't even want to view the desktop.
Thanks
There is VncSharp.
Here are two alternative solutions Method 1 :
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");
Method 2 :
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("=");
}
精彩评论