Solved

Connect to Domain

Posted on 2002-07-15
9
835 Views
Last Modified: 2008-02-01
I logged on my Local computer as Local user (ComputerName\LocalUser). How can I get list of the users from Domain? How can I enter (from my code) Domain name, User name and User password for a connecting to Domain to get users list?
I need to  get users list of Domain IN PROGRAMM CODE! How can I to connect to domain (IN CODE)? Which net function can I use for this?
*********************
Thank for everybody. I found the solution with function WNetAddConnection2
0
Comment
Question by:Marisha
9 Comments
 

Expert Comment

by:ferose
ID: 7154076
In General for NT / 2000 :

Whatever action u r trying to achieve ( Browsing Network neighbhour hood,  Folder permissions, adding computer to domain...etc...) you can usually browse the list of domains and workgroups on the Network.

You will be prompted for a user name and password for the corresponding domain ...

List of users can be viewed by trying anything related to security and permissions; or using user manager if u r on a NT server.

Rgds,
Ferose        
0
 
LVL 24

Expert Comment

by:SunBow
ID: 7154804
> How can I get list of the users from Domain?

1) You must have admin authority in the domain
2) User_Manager will do this, yes, but recognize they are different for whether you are logged in or not. The code is on the CD
3) For questions regarding specific programming languages, use the EE TA for that language
4) Best way to connect is to login, with ID+password, without running the scripts
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 7155014
Use a batch file and pipe the output to a file.

look under net view

Also
See
Auditing and utility tools

http://www.sysinternals.com/

http://www.sysinternals.com/ntw2k/freeware/ntfsdospro.shtml  NTFS for DOS
http://www.systemtools.com/
http://www.winternals.com
 www.bhs.com
http://www.bhs.com/soft_index.asp

http://www.sunbelt-software.com/search_category.cfm
www.optimumx.com

Also

:

 get DumpSec from www.somarsoft.com. It's free.
               
Net view yes  to view users and computers logged in
                 From: PatOBrien   Date: 03/12/2001 01:44PM PST

  Here's a batch file that will give you a list of users along with the groups that they belong to.  If
                 you want to save the output to a file for later printing, make the indicated changes....

                 To get permissions is another story.

                 ::---------------------start of bat file -------------
                 ::UserList.bat
                 ::by Pat O'Brien
                 @echo off

                 set OutFile=UserList.txt
                 for /f "tokens=1-4" %%u in ('net user /domain') do call :ListUsers %%u %%v %%w %%x

                 echo DOS Rules!

                 goto :eof

                 :ListUsers

                 if not .%4.==.. goto :eof

                 for %%h in (%1 %2 %3) do Call :GroupDisplay %%h

                 goto :eof

                 :GroupDisplay

                 ::when sending to file you may want to comment this line for speed purposes
          net user /domain %1 1>nul 2>nul && (echo. & echo %1 & net user /domain %1 |find "*")

 ::uncomment this next line to have output go to "outfile" defined above
::net user /domain %1 1>nul 2>nul && (echo. >>%OutFile% & echo %1 >>%OutFile% & net user /domain %1
                 |find "*" >>%OutFile%)

                 goto :eof
    ::--------------------------------end of bat file--------

Also
net user /domain >c:\domainusers.txt
3 columns of data.

nstall ADSI 2.5 for NT4 from
               http://www.microsoft.com/downloads/search.asp?
               Search for "all downloads" and your OS

               Have VBScript Engine 5.x installed
               http://msdn.microsoft.com

               Put the text between -------- in a any.vbs file

               '------------------------------
               '
               'Show users in each domain group
               '

               DomainString = "MyDomain"
               UserString = ""
               GrpString = ""
               List = ""

               Call Userss()

               Function Userss()
                 Set DomainObj = GetObject("WinNT://" & DomainString)
                 DomainObj.Filter = Array("user")
                    For Each UserObj In DomainObj
                       UserString = Userobj.Name
                       Call Groupss(UsersString)
                    Next
               End Function

               Function Groupss(UsersString)
                 Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
                     For Each GroupObj In UserObj.Groups
                         List = List & GroupObj.Name & VbCrLf
                     Next
                 Wscript.Echo UserString & VbCrLf & VbCrLf & List
                 List = ""
               End Function

               UserObj = Nothing
               GroupObj = Nothing
               '------------------------------

               Longbow
-----
From: Longbow      Date: 07/13/2001 09:36AM PST Dumps all objects.
 
               If you have VBSCRIPT and ADSI installed
               you may try my script. Copy it in a .vbs file.
               They may be find on microsoft site or
               http://cwashington.netreach.net/

               ----------------------
               Set WshShell = Wscript.CreateObject("Wscript.Shell")
               Set fso = CreateObject("Scripting.FileSystemObject")

               DomainString = "DomainName"
               List = ""
               Grp = "Domain Users"
               OutputFile = "C:\DomainUsers.txt"
               Count = 0

               Call Groupss()

               Set tf = fso.CreateTextFile(OutputFile, True)
                 tf.WriteLine(Count & " Domain Users listed in Domain " & DomainString)
                 tf.WriteBlankLines(3)
                 tf.Write (List)
                 tf.Close

               msgbox "END of Job" & VbCrLf & VbCrLf & "OutputFile created to " & OutputFile

               Return = WshShell.Run ("notepad " & OutputFile, 1, TRUE)


               Function Groupss()
                 Set DomainObj = GetObject("WinNT://" & DomainString)
                    For Each GroupObj In DomainObj
                       If GroupObj.Name = Grp Then Call Userss()
                    Next
               End Function

               Function Userss()
                 Set GroupObj = GetObject("WinNT://curie.dom/" & Grp)
                 For Each UserObj in GroupObj.Members
                    List = List & UserObj.Name & VbCrLf
                    Count = Count +1
                 Next
               End Function
               'End of Script.
               ----------------------
  http://www.jsiinc.com/subb/tip0800/rh0835.htm  list of machines and MAC addresses and IP address    
   in the reskit there is a utility called SHOWMBRS.  You can pipe the results to a text file

               eg
               SHOWMBRS "<DOMAIN>\DOMAIN USERS" >> USERS.TXT

               and
               SHOWMBRS "<DOMAIN>\DOMAIN ADMINS" >> USERS.TXT
----------------

I hope this helps !
0
 

Accepted Solution

by:
Marisha earned 0 total points
ID: 7156567
Dear SysExpert!
My problem was not to get Users list , my problem was TO CONNECT to Domain for getting Users list! If I see Domain but have not permission to take information from it! So, I found solution with function WNetAddConnection2 !
Thank you for your help.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 63

Expert Comment

by:SysExpert
ID: 7158358
I'm glad you got this resolved.

Please post how you did this so that others can learn.

Then request that this question be PAQed and your points returned since you resolved it yourself, unless you want to distribute your points.

you may contact  Community Support for help in dividing your points or requesting that they be refunded.

I hope this helps !
0
 

Author Comment

by:Marisha
ID: 7158890
Option Explicit
Public Type NETRESOURCE
  dwScope As Long
  dwType As Long
  dwDisplayType As Long
  dwUsage As Long
  lpLocalName As String
  lpRemoteName  As String
  lpComment As String
  lpProvider  As String
End Type
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _
      "WNetAddConnection2A" (lpNetResource As NETRESOURCE, _
      ByVal lpPassword As String, ByVal lpUserName As String, _
      ByVal dwFlags As Long) As Long

Public Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _
      "WNetCancelConnection2A" (ByVal lpName As String, _
      ByVal dwFlags As Long, ByVal fForce As Long) As Long
Declare Function WNetGetLastError Lib "mpr.dll" Alias "WNetGetLastErrorA" (lpError&,lpErrorBuf$,nErrorBufSize&, lpNetProviderNameBuf$, nNetProviderNameBufSize&) As Long

      Public Const RESOURCETYPE_ANY = &H0
      Public Const RESOURCE_GLOBALNET = &H2
      Public Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
      Public Const RESOURCEUSAGE_CONNECTABLE = &H1
      Public Const CONNECT_UPDATE_PROFILE = 1&

      Public Const ERROR_ACCESS_DENIED = 5&
      Public Const ERROR_ALREADY_ASSIGNED = 85&
      Public Const ERROR_BAD_DEV_TYPE = 66&
      Public Const ERROR_BAD_DEVICE = 1200&
      Public Const ERROR_BAD_NET_NAME = 67&
      Public Const ERROR_BAD_PROFILE = 1206&
      Public Const ERROR_BAD_PROVIDER = 1204&
      Public Const ERROR_BUSY = 170&
      Public Const ERROR_CANCELLED = 1223&
      Public Const ERROR_CANNOT_OPEN_PROFILE = 1205&
      Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202&
      Public Const ERROR_EXTENDED_ERROR = 1208&
      Public Const ERROR_INVALID_PASSWORD = 86&
      Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
      Public Const ERROR_BAD_NETPATH = 53&
      Public Const ERROR_OPEN_FILES = 2401&
      Public Const ERROR_NOT_CONNECTED = 2250&
      Public Const ERROR_DEVICE_IN_USE = 2404&

Private Sub cmdConnect_Click()
On Error GoTo Connect_error
    Dim ErrInfo As Long
    Dim strPassword As String, strUserName As String
    Dim typNetResource As NETRESOURCE
    With typNetResource
      .dwScope = RESOURCE_GLOBALNET
      .dwType = RESOURCETYPE_ANY
      .dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN
      .dwUsage = RESOURCEUSAGE_CONNECTABLE
      .lpRemoteName = "\\" + Trim$(txtDomain)
    End With
      strPassword = Trim$(txtPassword)
      strUserName = Trim$(txtUsername)
      ErrInfo = WNetAddConnection2(typNetResource, strPassword, strUserName, CONNECT_UPDATE_PROFILE)
      If ErrInfo = ERROR_SUCCESS Then
        Unload Me
      Else
        Err.Raise ErrInfo
      End If
Exit Sub
Connect_error:
Select Case Err.Number
Case ERROR_ALREADY_ASSIGNED, _
      ERROR_BAD_DEV_TYPE, _
      ERROR_BAD_DEVICE, _
      ERROR_BAD_NET_NAME, _
      ERROR_BAD_PROFILE, _
      ERROR_BAD_PROVIDER, _
      ERROR_BUSY, _
      ERROR_CANCELLED, _
      ERROR_CANNOT_OPEN_PROFILE, _
      ERROR_DEVICE_ALREADY_REMEMBERED, _
      ERROR_EXTENDED_ERROR, _
      ERROR_INVALID_PASSWORD, _
      ERROR_NO_NET_OR_BAD_PATH, _
      ERROR_BAD_NETPATH
      MsgBox LoadResString(Err.Number + 5000), vbCritical, "Connect To Domain"
Case Else
    MsgBox Err.Description, vbCritical, "Connect To Domain"
End Select
End Sub
Public Function DisconnetFromDomain(DomainName As String) As Boolean
Dim lngErr&
Dim strErrMsg$, lngErrMsgLen&, strProviderName$, lngProviderNameLen&
Dim blnDisconnectFlaf As Boolean
On Error GoTo Disconnect_Error
blnDisconnectFlaf = False
Discon:
DisconnetFromDomain = True
lngErr = WNetCancelConnection2(DomainName, CONNECT_UPDATE_PROFILE, blnDisconnectFlaf)
If lngErr <> ERROR_SUCCESS Then
    Err.Raise lngErr
End If
Exit Function
Disconnect_Error:
DisconnetFromDomain = False
Select Case Err.Number
Case ERROR_NOT_CONNECTED
    DisconnetFromDomain = True
Case ERROR_EXTENDED_ERROR
    WNetGetLastError lngErr, strErrMsg, lngErrMsgLen, strProviderName, lngProviderNameLen
    MsgBox strErrMsg
Case ERROR_BAD_PROFILE, ERROR_CANNOT_OPEN_PROFILE, _
    ERROR_DEVICE_IN_USE
    MsgBox LoadResString(Err.Number + 5000)
Case ERROR_OPEN_FILES
    If MsgBox(LoadResString(Err.Number + 5000), vbQuestion + vbYesNo) = vbYes Then
        blnDisconnectFlaf = True
        Resume Discon
    End If
Case Else
    MsgBox Err.Description
End Select
End Function
0
 

Expert Comment

by:CleanupPing
ID: 9155528
Marisha:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 17

Expert Comment

by:John Gates
ID: 9356820
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund points (User answered their own question) =-)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Dimante
EE Cleanup Volunteer
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Occasionally you run into the website or two that will not resolve properly using your own DNS servers.  Some people simply set up global forwarders for their DNS server.  I don’t recommend doing this because it can cause problems resolving addresse…
PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now