与本地运行相比,通过WMI运行时可执行文件的行为不同



我将下面的c - sharp文件编译为可执行文件。

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.Threading;
namespace Foreground {
  class GetForegroundWindowTest {
    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern IntPtr GetForegroundWindow();
    [DllImport("user32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
    public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
    public static void Main(string[] args){
        while (true){
            IntPtr fg = GetForegroundWindow(); //use fg for some purpose
            var bufferSize = 1000;
            var sb = new StringBuilder(bufferSize);
            GetWindowText(fg, sb, bufferSize);
            using (StreamWriter sw = File.AppendText("C:\Office Viewer\OV_Log.txt")) 
            {
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd_HH:mm:ss,") + sb.ToString());
            }
            Thread.Sleep(5000);
        }
    }
  }
}

当我在本地机器上运行这个可执行文件时,它会产生当前窗口的日期和名称。

当我在远程机器上使用wmi运行这个可执行文件时,它产生日期,而当前窗口的名称为空,我假设这意味着它返回null。有人能解决这个问题吗?

运行wmi可执行文件的程序是用python编写的,格式为:

import wmi
IP         = '192.168.165.x'
USERNAME   = 'username'
PASSWORD   = 'password'
REMOTE_DIR = 'c: ... '
remote_pc = wmi.WMI (IP, user = USERNAME, password = PASSWORD)
exe_remote_path = join (['\\', IP, '\', REMOTE_DIR, filename)
remote_pc.Win32_Process.Create (CommandLine = exe_remote_path)

这可能是问题.....

出于安全原因,Win32_Process. exeCreate方法不能用于远程启动交互式进程。

从msdn

相关内容

最新更新