C# Programming
10-21-2009, 10:41 PM
Hi,
I have created an application which runs on a Web Server. This web server in-turn runs as a windows service.
This windows service's account is configured as follows
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
Now I have a scenario in which I have to access a database and execute queries in it which needs the currently logged in user. The problem is that whenever I try to use
System.Security.Principal.WindowsIdentity.GetCurrent().Name
I am getting the name as "SYSTEM" and not the logged in user's name. And I know that this is because the service is run at the system level.
I can change the ServiceAccount as
serviceProcessInstaller.Account = ServiceAccount.User
I can now get the currently logged in user name. But, this requires the user to enter his user name and password when the service is being installed and I do not want that to happen.
Hence is there any other way in which I can get the WindowsIdentity object of the currently logged in user? Please suggest..
Thanks,
ramz_g
I have created an application which runs on a Web Server. This web server in-turn runs as a windows service.
This windows service's account is configured as follows
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
Now I have a scenario in which I have to access a database and execute queries in it which needs the currently logged in user. The problem is that whenever I try to use
System.Security.Principal.WindowsIdentity.GetCurrent().Name
I am getting the name as "SYSTEM" and not the logged in user's name. And I know that this is because the service is run at the system level.
I can change the ServiceAccount as
serviceProcessInstaller.Account = ServiceAccount.User
I can now get the currently logged in user name. But, this requires the user to enter his user name and password when the service is being installed and I do not want that to happen.
Hence is there any other way in which I can get the WindowsIdentity object of the currently logged in user? Please suggest..
Thanks,
ramz_g