【问题标题】:C# send VNC commandsC# 发送 VNC 命令
【发布时间】:2011-03-08 23:19:59
【问题描述】:

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

谢谢

【问题讨论】:

  • 你想发送什么样的命令?鼠标按键?按键?一个shell命令?
  • 啊只是按键。如CTRL-ALT-DELETE、通用文本等。

标签: c# command vnc


【解决方案1】:

VncSharp

【讨论】:

  • 看起来它会起作用,但我没有看到任何选项可以只发送文本或像 enter 这样的命令。我只能看到命令 SendSpecialKeys,它只允许我发送 control-alt-delete 之类的东西,有什么想法吗?
  • @jack:我不知道,这是duckduckgo.com的第一个结果。我会尝试在调用键向上事件之前发送 3 个向下键
【解决方案2】:

这里有两种替代解决方案 方法一:

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-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2012-12-12
    • 2023-04-05
    • 1970-01-01
    相关资源
    最近更新 更多