2

Is there any way to log on to a Windows machine using WCF and C#? I am creating a Test Harness and it will needed to remotely logon a Windows user.

So far we have not been able to do it successfully as once the user has been log off from the machine, self-hosted WCF is shut down.

oleksii
  • 35,458
  • 16
  • 93
  • 163
Manolete
  • 3,431
  • 7
  • 54
  • 92
  • there is no answer from the service on the machine? how is the service hosted? – Sam Holder May 31 '11 at 14:29
  • You run the self-hosted WCF under IIS? Try hosting your WCF service in a Windows service. Then it can start whenever the server starts, even if there are no interactive users. – Roy Dictus May 31 '11 at 14:51
  • @Roy self-hosted is basically a Console App, not IIS-hosted. Tnx for the Win Service suggestion. – oleksii May 31 '11 at 15:09

2 Answers2

4

your problem is that you are hosting the service as a console app. When the user logs off, the app stops.

Host your service in a windows service, which will enable it to start and run without a user being logged on.

MSDN on hosting in a windows service

as a tip, in the OnStart method add the following line:

Debugger.Launch(); 

and a using statement:

using System.Diagnostics;

if you have problems with the service starting and immediately stopping. This should allow you to attach a debugger to the service as it is starting to debug the issue.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
0

Using supplied credentials on the web end you could try logging in via WMI? but, it does depend what you intend to do to the remote machines - other option would be a client on the remote machines

BugFinder
  • 17,474
  • 4
  • 36
  • 51
  • can you pls explain a bit more in details: is there remote WMI logon? What do you mean by _a client on the remote machines_ and how I can communicate with it when the PC is logged off? – oleksii May 31 '11 at 14:51
  • WMI is a method of connecting to remote machines and performing actions - a quick google has plenty of examples - however to do pretty much anything you would need to provide it credentials - eg, get a username + password eg from your website. – BugFinder May 31 '11 at 14:53