In my project I want to execute some commands on the remote machine. I am
using .Net Remoting to achieve this. My server which is an exe is copied on
the remote machine and it receives command from client which is executed by
the exe. I am facing problem while executing the exe on the remote machine.
If I start the exe manually everything works fine but if I execute it
remotely through code using WMI an exception is thrown saying "No connection
could be made because the target machine actively refused it". This
exception is generally thrown when the remote server is not running but the
task manager of the remote machine shows that the exe is running. I am
using Win32_process class to do this. The MSDN help of Win32_process class
Create() method says "For security reasons the Win32_Process.C reate method
cannot be used to start an interactive process". Is this the reason for the
exception? If so, then what is the alternative for executing an exe on
remote machine?
I am pasting the code snippet of my client and server below
Code of Server:
RemotingConfigu ration.Configur e( "rpcserver.exe. config" );
TcpServerChanne l channel = new TcpServerChanne l(rs.mPort);
ChannelServices .RegisterChanne l(channel);
RemotingConfigu ration.Register WellKnownServic eType(
typeof(RemoteSe rverObject),
"ToolComman d",
WellKnownObject Mode.SingleCall );
Code for Client:
ManagementScope obScope = new ManagementScope ("\\\\" + remoteServer +
"\\root\\CIMV2" );
ManagementClass shareClass = new ManagementClass ( "\\\\" + remoteServer +
"\\root\\CIMV2: Win32_Process" );
object[] param = {"c:\\temp\\rpc server.exe",nul l,null,null};
object response = shareClass.Invo keMethod( "Create", param );
}
using .Net Remoting to achieve this. My server which is an exe is copied on
the remote machine and it receives command from client which is executed by
the exe. I am facing problem while executing the exe on the remote machine.
If I start the exe manually everything works fine but if I execute it
remotely through code using WMI an exception is thrown saying "No connection
could be made because the target machine actively refused it". This
exception is generally thrown when the remote server is not running but the
task manager of the remote machine shows that the exe is running. I am
using Win32_process class to do this. The MSDN help of Win32_process class
Create() method says "For security reasons the Win32_Process.C reate method
cannot be used to start an interactive process". Is this the reason for the
exception? If so, then what is the alternative for executing an exe on
remote machine?
I am pasting the code snippet of my client and server below
Code of Server:
RemotingConfigu ration.Configur e( "rpcserver.exe. config" );
TcpServerChanne l channel = new TcpServerChanne l(rs.mPort);
ChannelServices .RegisterChanne l(channel);
RemotingConfigu ration.Register WellKnownServic eType(
typeof(RemoteSe rverObject),
"ToolComman d",
WellKnownObject Mode.SingleCall );
Code for Client:
ManagementScope obScope = new ManagementScope ("\\\\" + remoteServer +
"\\root\\CIMV2" );
ManagementClass shareClass = new ManagementClass ( "\\\\" + remoteServer +
"\\root\\CIMV2: Win32_Process" );
object[] param = {"c:\\temp\\rpc server.exe",nul l,null,null};
object response = shareClass.Invo keMethod( "Create", param );
}
Comment