2011-03-08 112 views
2

C#中有任何簡單的方法可以將命令發送到計算機上的VNC服務器。理想情況下,某種圖書館或某種東西會很好,但真的很簡單。我希望能夠做的只是連接併發送一個命令,我甚至不想查看桌面。C#發送VNC命令

感謝

+0

什麼樣的命令,你想送的?一個鼠標按鈕按?按鍵?一個shell命令? – 2011-03-08 23:24:01

+0

啊只是按鍵。如CTRL-ALT-DELETE,一般文本等。 – Jack 2011-03-08 23:24:39

回答

3

VncSharp

+0

看起來它會工作,但我沒有看到任何選項只發送文本或像enter命令。我只能看到SendSpecialKeys這個命令,它只允許我發送諸如control-alt-delete之類的東西,任何想法? – Jack 2011-03-09 14:41:55

+0

@jack:我不知道,這是duckduckgo.com的第一個結果。我會嘗試在調用按鍵事件之前發送3個向下鍵 – 2011-03-10 17:27:11

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

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

     }