![](/img/trans.png)
[英]Why is my clipboard-manipulating application behaving differently when run outside of Visual Studio?
[英]Executable behaving differently when run through WMI compared to run locally
我將以下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從遠程計算機運行此可執行文件時,它會產生日期,並且當前窗口的名稱為空白,我認為這意味着它返回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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.