Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1008
  • Last Modified:

C# Logoff Users Remotely

I have an issue where one of our servers is diplaying the following message:

"A device attached to the system is not functioning"

Under any other instance I would just attached to server manager and logoff the users to clear the error.  But in this instance I found that this server is actually not on the domain and it host 10 production Hyper-V hosts.

Is there a way that I can do this through either a script or C#.  I tried using the shutdown /l command but I get access denied because I have no options to specify a username or password

Thank you all of your help in advance
0
thomasm1948
Asked:
thomasm1948
1 Solution
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
hi... Can you use this...

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

/l is logoff. /f is force. /m \\computername is the name of the remote computer to do the operation on. If you are not on a domain and the user running the app does not have domain admin rights I can not guarantee the above command will work.

Another option: get PsExec then run the shutdown command with it on the remote computer(shutdown.exe /l /f)
0
 
thomasm1948Author Commented:
I tried these.  The only option that worked was to restart the server being that the server is not part of the domain.  That is why I was looking for an option that gives you an option to inout a username and password
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now