Get the domain name that your SQL Server machine

Get the domain name that your SQL Server machine

I have tested this on SQL Server 2005 and on SQL Server 2000.  it might not be available in the future. Don't use it as production code!

DECLARE @chvDomainName NVARCHAR(100)
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon',
N'CachePrimaryDomain',@chvDomainName OUTPUT

SELECT @chvDomainName AS DomainName 

No comments:

Post a Comment