PeterSchenk
asked on
Using PSEXEC in C#
Hi,
Im using PSEXEC v1.98 and the following code to launch an application on a remote machine and Im having an issue.
When launching from a command prompt this code works fine...
psexec -i 1 -d -u Administrator -p Administrator \\28.228.176.111 notepad.exe
Now when I code this in C# it launches a command prompt localy loads PSEXEC then closes.... not sure where to go from here?
string stfamtv0001 = "/C" + " " + ("psexec -i 1 -d -u Administrator -p Administrator \\28.228.176.111 notepad.exe"
);
private void button1_Click(object sender, EventArgs
e)
{
PCdata(stfamtv0001);
}
private void PCdata(string
PCstreamPath)
{
System.Diagnostics.
Process
ps;
ps =
new System.Diagnostics.Process
();
ps.EnableRaisingEvents =
false
;
ps.StartInfo.UseShellExecu te =
false
;
System.Diagnostics.
Process.Start("CMD.exe"
, PCstreamPath);
ps.Close();
}
Im using PSEXEC v1.98 and the following code to launch an application on a remote machine and Im having an issue.
When launching from a command prompt this code works fine...
psexec -i 1 -d -u Administrator -p Administrator \\28.228.176.111 notepad.exe
Now when I code this in C# it launches a command prompt localy loads PSEXEC then closes.... not sure where to go from here?
string stfamtv0001 = "/C" + " " + ("psexec -i 1 -d -u Administrator -p Administrator \\28.228.176.111 notepad.exe"
);
private void button1_Click(object sender, EventArgs
e)
{
PCdata(stfamtv0001);
}
private void PCdata(string
PCstreamPath)
{
System.Diagnostics.
Process
ps;
ps =
new System.Diagnostics.Process
();
ps.EnableRaisingEvents =
false
;
ps.StartInfo.UseShellExecu
false
;
System.Diagnostics.
Process.Start("CMD.exe"
, PCstreamPath);
ps.Close();
}
ASKER
Did not work.... it flashes to quick to see whats happening. Is there a way we can wrtie the output of the CMD to a txt file?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Looks like it trying to start it on the remote machine.... see below
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
PsExec could not start \28.228.176.111 on MACHINE98919:
Logon failure: unknown user name or bad password.
c:\documents and settings\homeuser\my documents\visual studio 2010\Projects\Conso
leApplication2\ConsoleAppl ication2\b in\Debug>
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
PsExec could not start \28.228.176.111 on MACHINE98919:
Logon failure: unknown user name or bad password.
c:\documents and settings\homeuser\my documents\visual studio 2010\Projects\Conso
leApplication2\ConsoleAppl
Are the username and password you are sending valid?
ASKER
Yes the are valid on the machine im trying to connect too.
ASKER
The ip address is the target machine and the MACHINE98919 is my machine.
ASKER
I actually fixed it with this command
string stfamtv0001 = "/C psexec -i 1 -d -u Administrator -p Administrator \\\\28.228.176.111 notepad.exe";
The \\28.228.176.111 was the issue... once it was changed to \\\\28.228.176.111 it worked : )
string stfamtv0001 = "/C psexec -i 1 -d -u Administrator -p Administrator \\\\28.228.176.111 notepad.exe";
The \\28.228.176.111 was the issue... once it was changed to \\\\28.228.176.111 it worked : )
ASKER
This solution gave me the idea about the incorrect syntax...
Thanks you
Thanks you
Ah yes. In C# if you have backslashes in a string, you either have to double them up, or prefix your string with the @ symbol. In other words:
or
string stfamtv0001 = "/C psexec -i 1 -d -u Administrator -p Administrator \\\\28.228.176.111 notepad.exe";
or
string stfamtv0001 = @"/C psexec -i 1 -d -u Administrator -p Administrator \\28.228.176.111 notepad.exe";
Open in new window