c# - How to check if process is remotely started -


i run process on remote machine wmi.

can check in process code (on remote machine) if remotely created?

i tried process.getcurrentprocess() , process.getcurrentprocess().startinfo properties didn't find information. environment class doesn't contain info.

my code use create remote process (i found on forum):

                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;                         }                     }                 }             } 

i don't know if can detect or not, 1 workaround can pass command line argument saying "remotelystarted" when launch via wmi, in code do

const string remotely_started_flag = "remotelystarted";  if(environment.getcomandlineargs().contains(remotely_started_flag, stringcomparison.ordinalignorecase)) {     //do code here if running remotely. } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -