2

C# 中是否有任何简单的方法可以将命令发送到计算机上的 VNC 服务器。理想情况下,某种图书馆或其他东西会很好,但实际上最简单的东西。我想做的只是连接并发送命令,我什至不想查看桌面。

谢谢

4

2 回答 2

3

VncSharp

于 2011-03-08T23:23:47.943 回答
1

以下是两种替代解决方案方法 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");

方法二:

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("=");

        }
于 2011-11-09T10:46:54.273 回答