How to log out remotely?

How can I programmatically log out remotely (from another computer) using C #? All I know is their username. This is done in an Active Directory environment where the execution of this account will be the administrator (Domain Admin). I assume that security will be handled. I would like to avoid the need to install the application on the machine.

It seems that the API exists, although I don’t know what it uses, since the "logoff.exe" provided with windows provides this capability. In the end, I can use this, but would rather avoid calling Process.Start and rely on it (plus it does not accept the username, just the session identifier).

+3
source share
5 answers

This is more than the server side of user management, but I really like to use Cassia


Another option is to do it

System.Diagnostics.Process.Start("shutdown.exe", String.Format(@"/l /f /m \\{1}", remoteComputerName));

/l- output. /f- power. /m \\computername- the name of the remote computer to perform the operation. If you are not in a domain and the user on whom the application is running does not have domain administrator rights, I can not guarantee that the above command will work.


Third option: get PsExec , then run the shutdown command on the remote computer with it ( shutdown.exe /l /f)

+1
source

Take a look at ServerRemoteControl .

0
source

WMI win32_operatingsystem wmi , win32shutdown ( ).

0

. , . , "" .

private void runRemoteApp(string[] processToRun, string machineName)
{
    var connection = new ConnectionOptions();
    var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", machineName), connection);
    var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
    wmiProcess.InvokeMethod("Create", processToRun);
}

private void logoffMachine(string machineName)
{
    var processToRun = new[] { "logoff.exe console" };
    runRemoteApp(processToRun, machineName);
}
0
source

Source: https://habr.com/ru/post/1768128/


All Articles