public void Create(string Name)
{
ManagementPath path = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(_mc.Scope, path, null);
//Gets Path and Executables name.
string[] splitPath = Name.Split('\\');
string exeName = splitPath[splitPath.Length - 1];
string exePath = null;
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
if (splitPath.Length > 1)
exePath = Name.Substring(0, Name.LastIndexOf('\\'))+"\\";
//Parameters for creation of process.
inParams["CommandLine"] = exeName;
inParams["CurrentDirectory"] = exePath;
//Invoke Method.
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Object returnValue = outParams["ReturnValue"];
switch(int.Parse(returnValue.ToString()))
{
case 0: break;
case 2: throw new System.Security.SecurityException("Access denied");
case 3: throw new System.Security.SecurityException("Insufficient privilege");
case 9: throw new Exception(string.Format("Path not found \"{0}\"",exePath));
case 21: throw new Exception("Invalid parameter");
default : throw new Exception("Unknown failure");
}
//Reload processes.
getProcesses();
}
This code is fine for creating processes such as notepad, cmd or calc but as soon as i try and access a path such as "c:\program files\internet explorer\iexplorer.exe" it has a path not found error. Any ideas?
Question
Ph8l
This code is fine for creating processes such as notepad, cmd or calc but as soon as i try and access a path such as "c:\program files\internet explorer\iexplorer.exe" it has a path not found error. Any ideas?
Link to comment
Share on other sites
15 answers to this question
Recommended Posts