Hi, I would like to know if it's possible to retreive Windows user logged on to the PC (domainuserid) using Sql, if possible please provide code? Regards
[quote user="Ismailc"] Hi, I would like to know if it's possible to retreive Windows user logged on to the PC (domainuserid) using Sql, if possible please provide code? Regards [/quote] Check this...DECLARE @chvDomainName NVARCHAR(100) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftWindows NTCurrentVersionWinlogon', N'CachePrimaryDomain',@chvDomainName OUTPUT SELECT @chvDomainName AS DomainName if you wants the other info please query this: sp_who Thanks, Sandy.
Hi Ismailc, here is your script......./* Dimain Name */DECLARE @chvDomainName NVARCHAR(100) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftWindows NTCurrentVersionWinlogon', N 'CachePrimaryDomain',@chvDomainName OUTPUT SELECT @chvDomainName AS DomainName/* User Name */DECLARE @UserName NVARCHAR(100) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftWindows NTCurrentVersionWinlogon', N 'DefaultUsername',@UserName OUTPUT SELECT @UserName AS UserName Thanks, Sandy.
Great stuff - Thank You All. I did not think this was possible & was thinking of other ideas to get the PC user logged on. Unfortunately the query works but not completely the way i need it to be. The query returns the login details of the user logged on to the SQL server PC eg the DB lies on a server and it retreives the user logged on the the server. I'm looking to retreive the information from the user's PC executing the script on the server. eg. It must return my details running the script & not the user on the server. Regards
Only if the user is logged on to SQL with Windows authentication ...select x.nt_domain, x.nt_user_name from sys.dm_exec_sessions x where x.session_id = @@SPID Otherwise, it will have to come from the client app.
If you're looking for the user actually executing the script or stored procedure can't you just use system_user select system_user ???
Hi, I got the userid using the web application in server side code, system_user returns the id logged onto the database & not the NT user. Thank You All
For a web application you need to have the application coded in a way that it sends you the username for the user who connecting through a browser. SQL Server has no way of knowing it when you use SQL authentication.
Hi, I created an SSRS report with a parameter based on the userid the wep application returns. Regards
That's what I do here as well. Inside the db then I check the rest based on what RS supplies me with. []