![](/img/trans.png)
[英]How can I check if a process was started by Visual Studio > 2015
[英]How to check if process is remotely started
我通過WMI在遠程計算機上運行進程。
是否可以在遠程計算機上簽入過程代碼(在遠程計算機上)?
我嘗試使用Process.GetCurrentProcess()
和Process.GetCurrentProcess().StartInfo
屬性,但沒有找到任何信息。 環境類也不包含任何信息。
我的代碼用於創建遠程進程(我在某個論壇上找到了它):
var connOptions = new ConnectionOptions()
{
Username = "user",
Password = "password"
};
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
var manScope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", "MachineName"), connOptions);
manScope.Connect();
var objectGetOptions = new ObjectGetOptions();
var managementPath = new ManagementPath("Win32_Process");
using (var processClass = new ManagementClass(manScope, managementPath, objectGetOptions))
{
using (ManagementBaseObject inParams = processClass.GetMethodParameters("Create"))
{
inParams["CommandLine"] = remoteFilePath;
using (ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null))
{
if ((uint)outParams["returnValue"] == 0)
{
var pid = (uint)outParams["processId"];
return pid;
}
}
}
}
我不知道是否可以檢測到它,但是您可以采取的一種解決方法是通過WMI啟動時傳遞一個命令行參數,說“ remotelyStarted”,然后在代碼中執行
const string REMOTELY_STARTED_FLAG = "remotelyStarted";
if(Environment.GetComandLineArgs().Contains(REMOTELY_STARTED_FLAG, StringComparison.OrdinalIgnoreCase))
{
//Do code here if it was running remotely.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.