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

2024-04-25 19:23:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下c夏普文件编译为可执行文件。你知道吗

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从远程机器运行这个可执行文件时,它会产生date,并且当前窗口的名称为空,我认为这意味着它返回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)

Tags: iptrue可执行文件remotestaticpublicwmisystem
1条回答
网友
1楼 · 发布于 2024-04-25 19:23:38

这可能就是问题所在。。。。。你知道吗

For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely.

msdn

相关问题 更多 >