User405296658 posted
Hello there.
I develpoed an ASP.NET webpage that suppose to open a Notepad program on server pc.
i tried two options but both failed:
First - Using PsExec.exe tool to execute the proccess as myUser (Current logged - Administrator).
ProcessStartInfo start = new ProcessStartInfo();
start.WorkingDirectory =@"C:\Windows\System32\";
start.Arguments = "/k D:\\Downloads\\PSTools\\PsExec.exe \\\\Domain -u Username -p password \"Notepad.exe\"";
start.FileName = @"cmd.exe";
start.CreateNoWindow = false;
int exitCode;
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
// Retrieve the app's exit code
exitCode = proc.ExitCode;
}
This code doesn't run the process at all and stuck when waiting for the process to exit.
Second - Using WMI :
string strDomain = "Domain";
var connOpts = new ConnectionOptions()
{
// if i use this i get User credentials cannot be used for local connections
Username = "Username",
Password = "Password"
};
ConnectionOptions remoteConnectionOptions = new ConnectionOptions();
remoteConnectionOptions.Impersonation = ImpersonationLevel.Impersonate;
remoteConnectionOptions.EnablePrivileges = true;
remoteConnectionOptions.Authentication = AuthenticationLevel.Packet;
ManagementScope scope = new ManagementScope(@"\\" + Domain + @"\root\CIMV2", remoteConnectionOptions);
ManagementPath p = new ManagementPath("Win32_Process");
ManagementClass classInstance = new ManagementClass(scope, p, null);
object[] theProcessToRun = { @"Notepad.exe" };
classInstance.InvokeMethod("Create", theProcessToRun);
This code runs Notepad but as Application pool user.
It is important to say that im using IIS Authentication :( Windows, & Impersonated).
If someone has any idea why i notepad doesn't run.
Thank you for help.