views:

118

answers:

1

Hi,

I have a Windows service running as LocalSystem that needs to access some network resources. I found a way to impersonate a user that is currently logged on, by retrieving the token with OpenProcessToken, duplicating it and calling WindowsIdentity.Impersonate. That way I can access the same network resources as the impersonated user.

However, that means my service will only work if there is a logged on user... So I was thinking that, since the LocalSystem has all privileges on the machine, perhaps it can impersonate a user that is not currently logged on ? Or log on as any (local) user without knowing its password ? Assuming it's possible, how can I do it ?

Thanks in advance for any help

A: 

Try using the WindowsIdentity constructor taking the username as a string.

Amnon
Won't work in my case... the documentation states : *This constructor is intended for use on computers joined only to Windows Server 2003 domains. An exception is thrown for other domain types.*. Apparently I'm not on a Server 2003 domain, since I get a `SecurityException` with the following message : "Incorrect function"
Thomas Levesque
I think it may be possible with the API call CreateToken(), but I've never tried it.
Amnon