Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,

I want to Save Computer Full Name in database table while am inserting records in database.

I have a webpage which consists of textboxes and submit button to save data in database table.

while inserting record in table, i want to save computer login username also.

This is my code, am using. But it stores Computer Name. I need full computer Name like this kumarPC/Rkumar


Declaring
--------
string machineName = System.Environment.MachineName;


In Insert Query
-----------
'" + machineName.ToString() + "'

Machine name is storing but need to save Users Computer login name also as kumarPC/Rkumar



Please help
THANKS.
Posted

C#
string machineName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;


The reason to prefer WindowsIdentity.GetCurrent() is that this returns the account that the application is running as. This is not necessarily the account that is currently logged into Windows (think "RunAs" or impersonation/delegation). So, if you want to know the logged-in user, use the Environment (if you trust it). If you want to know the security context your application is running as, using WindowsIdentity.GetCurrent(). See msdn.microsoft.com/en-us/library/… for more information.
 
Share this answer
 
v3
Comments
Software Engineer 892 20-Nov-14 3:02am    
Thank you...
have you had a look at System.Environment.UserName ?
 
Share this answer
 
Comments
Software Engineer 892 20-Nov-14 3:01am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900