Solved

Read/Write SAM Database

Posted on 2003-11-27
6
768 Views
Last Modified: 2008-02-01
How do I access information in the SAM database in NT4 Server?
API or Object interface?
Pointers to sample code or articles on this subject would be much apprieciated.
0
Comment
Question by:philjh
  • 3
  • 2
6 Comments
 
LVL 41

Expert Comment

by:graye
ID: 9833008
Microsoft considers the SAM to be a "black box".  It is therefore NOT documented.  There are lots of higher-level access methods (ADSI for example)

What are you trying to do?
0
 

Author Comment

by:philjh
ID: 9835806
I'm trying to read nt group and user information. I may also need to programmatically create user accounts.
0
 

Author Comment

by:philjh
ID: 9837223
I'd also like to mention that we are not using Active Directory Services.
0
 
LVL 41

Accepted Solution

by:
graye earned 100 total points
ID: 9838273
That's ok... the ADSI interface works with standalone servers, mixed domains, and WinNT servers.

As you can imagine, some of the objects in the ADSI interface won't work without Active Directory (but the majority of 'em will)

Here is a simple vb script that uses ADSI to gather that kind of info (and we're not using Active Directory either).  You might find it useful as an example:

dim fso, fso_log
dim DOMAIN, DPW, Accts, acct, first, grp, junk, expired, num
dim DC_LIST, DC, temp, last, dc_acct

DOMAIN = "Domain"
OUTPUT_FILE = "c:\temp_Accts.csv"
DC_LIST = array("DC1", "DC2", "DC3")

' create a log file
set fso = createobject("scripting.filesystemobject")
set fs_log = fso.CreateTextFile(OUTPUT_FILE, true)
fs_log.writeline("Name,Full_Name,Description,Login_Script,Acct_Disabled,Password_Reset,Password_Expires,Last_Login,Groups")

' let's get cranking      
num = 0
Set Accts = GetObject("WinNT://" & DOMAIN)
Accts.Filter = Array("User")

for each acct in Accts
            num = num +1
            fs_log.write(chr(34) & acct.name & chr(34) & ",")
            fs_log.write(chr(34) & acct.fullname & chr(34) & ",")
            fs_log.write(chr(34) & acct.Description & chr(34) & ",")
            fs_log.write(chr(34) & acct.LoginScript & chr(34) & ",")
            fs_log.write(acct.AccountDisabled & ",")
            if acct.passwordExpired > 0 then
                  fs_log.write("True,")
            else
                  fs_log.write("False,")
            end if                  
            fs_log.write(acct.PasswordExpirationDate & ",")
                        
            ' cycle thru each Domain Controller to find lasted LastLogin value
            last = cdate("01/01/1980")
            for each DC in DC_LIST
                  set dc_acct = getobject("WinNT://" & DC & "/" & acct.name & ",user")
                  temp = cdate("01/01/1980")
                  on error resume next
                  temp = dc_acct.lastlogin
                  on error goto 0
                  if datediff("d", last, temp) > 0 then
                        last = temp
                  end if
            next
            fs_log.write(last & ",")
            
            ' get the group membership list
            fs_log.write(chr(34))
            first = true
            for each grp in acct.groups
                  if first = false then
                        fs_log.write(", ")
                  end if
                  first = false
                  fs_log.write(grp.name)
            next
            fs_log.writeline(chr(34))
      'end if
next

fs_log.close
msgbox "Wrote " & num & " entries to " & OUTPUT_FILE, 64, "Done!"
0
 

Author Comment

by:philjh
ID: 10164048
Sorry for the delay - got side-tracked.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question