2017-05-12 7 views
0

特定のモニタでソフトウェアを起動することができますか?どのようにこれを行うことができますか?第2モニタでnode.jsで外部exeを起動する

自分のコンピュータ(Windows 10)にnode.jsサーバーがあり、いくつかの外部ソフトウェアを起動する必要があります(exeファイルしかないので、その外部ソフトウェアでコードを変更することはできません)。最終的なアプリケーションは、実際のモニタと第2の偽のモニタを備えた設定で動作するはずです。最初のモニタにはブラウザウィンドウがフルスクリーンで表示されます。外部ソフトウェアの起動と停止には、開始ボタンと停止ボタンがあります(すでに動作しています)。 2番目のモニタ(非表示)で、外部ソフトウェアを起動する必要があります。 すべてがこのように動作するならば、私はそのコンピュータ上のリモートに接続し、2番目の画面を見ることができます。私は外部のソフトウェアを使用することができます。そのコンピュータのMonitor(1)には、常にブラウザウィンドウのみが表示されます。

テストするには私はnotepad.exeを外部ソフトウェアとして使用します。 起動をクリックすると、メインモニタ(1)でソフトウェアが開きますが、2台目のモニタでソフトウェアが起動します。

ありがとうございました。

答えて

0

これは直接行うことはできないようです。しかし、node.jsからちょっとしたヘルパープログラムを始めると、難しくありません。私は、次のような機能を持つ小さなC#コンソールアプリケーションを作っnodejs docs

[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")] 
    public static extern IntPtr SetForegroundWindow(IntPtr hWnd); 

    [DllImport("user32.dll", EntryPoint = "ShowWindow")] 
    public static extern bool ShowWindow(IntPtr hWnd, int cmdShow); 

    [DllImport("user32.dll", SetLastError = true)] 
    internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint); 

その後、私はSystem.Windows.Forms.Screen.AllScreens反復処理とProcess私の実行を開始するあなたはでexecFile()表情でそれを開始することができます。 Processから私はMainWindowHandleを取得しました。それで、あなたが望むスクリーンにウィンドウを設定することが可能です。

static void Main(string[] args) 
    { 
     if (args.Length == 1 && args[0].Equals("h")) 
     { 
      Console.Out.WriteLine("Command: [displayName] [executable] [arguments for executable]"); 
      return; 
     } 

     if (args.Length < 2) 
     { 
      Console.Out.WriteLine("arguments not correct. Should be: [displayName] [executable1] [arguments for executable]"); 
      return; 
     } 

     foreach (var screen in Screen.AllScreens) 
     { 
      Console.Out.WriteLine(screen.DeviceName); 
      if (screen.DeviceName.Equals(args[0])) 
      { 
       var process = new Process(); 

       process.StartInfo.FileName = args[1]; 
       string[] arguments = args.Skip(2) as string[]; 
       if (arguments != null) process.StartInfo.Arguments = string.Join(" ", arguments); 

       process.Start(); 

       var hwnd = process.MainWindowHandle; 
       Console.Out.WriteLine("while get process.MainWindowHandle"); 
       while (!process.HasExited) 
       { 
        process.Refresh(); 
        if (process.MainWindowHandle.ToInt32() != 0) 
        { 
         hwnd = process.MainWindowHandle; 
         break; 
        } 
       } 
       Console.Out.WriteLine("windowHandle: " + hwnd); 

       MoveWindow(hwnd, screen.WorkingArea.X, screen.WorkingArea.Y, screen.WorkingArea.Width, screen.WorkingArea.Height, true); 
       ShowWindow(hwnd, SwMaximize); 
       SetForegroundWindow(hwnd); 
       // Waits here for the process to exit. 
       process.WaitForExit(); 
       return; 
      } 
     } 
     Console.Out.WriteLine("screen not found: " + args[0]); 
    } 
} 
関連する問題