Find Domain Name Using T-SQL | SansSQL

Monday, November 17, 2008

Find Domain Name Using T-SQL

DECLARE @Domain varchar(100), @key varchar(100)

SET @key = 'SYSTEM\ControlSet001\Services\Tcpip\Parameters\'
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key=@key,@value_name='Domain',@value=@Domain OUTPUT
SELECT 'Server Name: '+@@servername + ' Domain Name:'+convert(varchar(100),@Domain)

Alternative ways,
1. SELECT DEFAULT_DOMAIN()
2. EXEC Master.dbo.xp_LoginConfig 'Default Domain'

13 comments:

Anonymous said...

Worked for me. Thank you.
(Nice site)

Paul Goldy said...

Thanks Sandesh. Very helpful SQL.

Paul Goldy said...

Thanks Sandesh. Very helpful SQL.

ArdentAj said...

When I tried this query it is throwing up Access Denied error.I think DBA haven't granted access for registry variables.

So is there any another way I can get Full computer name

Sandesh Segu said...

You can try either of the below queries

SELECT DEFAULT_DOMAIN()

EXEC Master.dbo.xp_LoginConfig 'Default Domain'

mtom said...

I do trust all of the ideas you’ve introduced for your post. They’re very convincing and will definitely work. Still, the posts are very short for beginners. May you please prolong them a bit from next time? Thank you for the post. Premium Domains

Mtom service said...

Gnarly article mate, keep the good work, just shared this with ma friendz website design company

Mtom service said...

I’m really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the excellent quality writing, it is rare to see a great blog like this one these days.. top web design companies

Alexander Albert said...

just couldn’t leave your web site before suggesting that I really loved the standard information a person provide for your visitors? Is gonna be again ceaselessly to check up on new posts web design

jacob olivia said...

Hi there! Do you use Twitter? I’d like to follow you if that would be ok. I’m undoubtedly enjoying your blog and look forward to new posts. web designer

khanabaaz said...

I totally understand what you have explained. Actually, I browsed throughout your several other content articles and I do believe you are absolutely correct. Congrats with this particular blog. ipad psd

Unknown said...

Hey i’m for the first time here. I came across this board and I find It seriously helpful & it helped me out much. I hope to give something back and aid others as you aided me. android phone template

relxindo said...

I like this website very much, Its a very nice post to read and find information. naveed ahmed poetry

Post a Comment

Ads