Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to get NT Accounts from DOMAIN.

Total Hit ( 3663)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Get NT account names of the server or domain using NT commands from T-SQL.

Click here to copy the following block
-- CAUTION: This method will not work for NT account names that can
--     have spaces in them.

DECLARE @CmdStr varchar( 8000 );
-- Get accounts on the SQL Server m/c
SELECT @CmdStr = 'for /F "skip=4 tokens=1,2,3" %a in '+
         '(''net users^|findstr /V /C:"completed"'') ' +
         'do @if not (%a)==() echo %a&if not (%b)==() echo %b&' +
         'if not (%c)==() echo %c';
/*
    The command string below can be used for getting accounts from
    the NT domain. The output format is different for NET USERS on a
    local machine & the domain. The main parameter to change is the
    number of lines to skip initially.
*/

/*
SELECT @CmdStr = 'for /F "skip=7 tokens=1,2,3" %a in '+
         '(''net users /domain^|findstr /V /C:"completed"'') ' +
         'do @if not (%a)==() echo %a&if not (%b)==() echo %b&' +
         'if not (%c)==() echo %c';
*/

EXECUTE master..xp_cmdshell @CmdStr;
/*
output
---------------------
Administrator
Guest
IUSR_VALHALLA-MDD06H
IWAM_VALHALLA-MDD06H
Service Account
TsInternetUser
*/


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.