hai friends,
Iam developing a application using .NET remoting ,in which it shuts down,logs off , restart , locks remote PC.i tried to use windows ExwindowsEXAPI for shutdown,logoff , restart and SetSuspendState for lock PC and the later worked perfectly but the problem is ExwindowsEx only Logsoff the PC and shutdown and restart is not working .Although i achieved the result using shutdown.exe ,but iam not convinced,so could anyone say what may be the problem.
server code
client code
thanks friends
Iam developing a application using .NET remoting ,in which it shuts down,logs off , restart , locks remote PC.i tried to use windows ExwindowsEXAPI for shutdown,logoff , restart and SetSuspendState for lock PC and the later worked perfectly but the problem is ExwindowsEx only Logsoff the PC and shutdown and restart is not working .Although i achieved the result using shutdown.exe ,but iam not convinced,so could anyone say what may be the problem.
server code
Code:
[DllImport("user32.dll")]
public static extern int ExitWindowsEx(uint uflag,uint reson);
public void shutdown_server(uint f)
{
ExitWindowsEx(f,0);
}
public void shut_server_exe(string arg)
{
System.Diagnostics.Process.Start("C:/shutdown.exe", arg);
}
[DllImport("Powrprof.dll")]
public static extern bool SetSuspendState(bool h, bool g, bool i);
public void standby()
{
SetSuspendState(false, false, false);
}
client code
Code:
private void logOffToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
serverclass obj = (serverclass)Activator.GetObject(
typeof(serverclass),
"http://" + IP + ":1234/serverclass.soap");
obj.shutdown_server(0);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
disconnect();
}
}
private void turnOffToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
serverclass obj = (serverclass)Activator.GetObject(
typeof(serverclass),
"http://" + IP + ":1234/serverclass.soap");
//obj.DoExitWin(2);
// obj.shutdown_server(8);
obj.shut_server_exe("/L /C /Y");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
disconnect();
}
}
private void restartToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
serverclass obj = (serverclass)Activator.GetObject(
typeof(serverclass),
"http://" + IP + ":1234/serverclass.soap");
// obj.shutdown_server(2);
obj.shut_server_exe("/L /R /C /Y");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
disconnect();
}
}
private void lockPCToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
serverclass obj = (serverclass)Activator.GetObject(
typeof(serverclass),
"http://" + IP + ":1234/serverclass.soap");
obj.standby();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
disconnect();
}
}
thanks friends
Comment