JSI Tip 9543. How can a script determine if a user exists in a remote computers SAM?


Using the Nltest.exe utility from the Support Tools on the operating system CD-ROM, I have scripted UserExists.bat to determine if a user account is defined in a remote computers SAM (Security Accounts Manager) database.

The syntax for using UserExists.bat is:

call UserExists Computer User YorN

Where:

Computer is the NetBIOS computer name of the remote computer.

User     is the user logon name on the remote computer.

YorN     is a call directed environment variable that will contain a
         Y if the user exists, or an N if the user does NOT exist.
UserExists.bat contains:
@echo off
if \{%3\}==\{\} @echo Syntax: call UserExists Computer User YorN&goto :EOF
set %3=N
for /f  "Tokens=*" %%a in ('nltest /Server:%1 /User:%2^|Find "User:"') do (
 set %3=Y
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish