I need a way to load all my domain user names into a table. The following script does basically want I want but I need to convert this into a stored procedure and NOT encode the username and password.
Thanks for your help in advance,
Sunny
Option Explicit
Dim sDomain
Dim oDomain
Dim sFilter
Dim oADobject
Dim MyConnection
Dim MyCommand
sDomain = "MyDomain"
sFilter = "User"
'Connect to domain
Set oDomain = GetObject("WinNT://" & sDomain)
oDomain.Filter = Array( sFilter )
Set MyConnection = CreateObject("ADODB.Connection"
'SQL Connection String
MyConnection.Open "Driver={SQL Server};server=(local);database=Employees;uid=myname;pwd=mypassword;"
Set MyCommand = CreateObject("ADODB.Command"
Set MyCommand.ActiveConnection = MyConnection
MyCommand.CommandText = "INSERT INTO [Employee] ([Username], [FullName], [Description]) VALUES(?,?,?)"
MyCommand.CommandType = 1
For Each oADobject In oDomain
MyCommand.Parameters(0).Value = oADobject.Name
MyCommand.Parameters(1).Value = oADobject.FullName
MyCommand.Parameters(2).Value = oADobject.Description
MyCommand.Execute
Next
MyConnection.Close()
Thanks for your help in advance,
Sunny
Option Explicit
Dim sDomain
Dim oDomain
Dim sFilter
Dim oADobject
Dim MyConnection
Dim MyCommand
sDomain = "MyDomain"
sFilter = "User"
'Connect to domain
Set oDomain = GetObject("WinNT://" & sDomain)
oDomain.Filter = Array( sFilter )
Set MyConnection = CreateObject("ADODB.Connection"
'SQL Connection String
MyConnection.Open "Driver={SQL Server};server=(local);database=Employees;uid=myname;pwd=mypassword;"
Set MyCommand = CreateObject("ADODB.Command"
Set MyCommand.ActiveConnection = MyConnection
MyCommand.CommandText = "INSERT INTO [Employee] ([Username], [FullName], [Description]) VALUES(?,?,?)"
MyCommand.CommandType = 1
For Each oADobject In oDomain
MyCommand.Parameters(0).Value = oADobject.Name
MyCommand.Parameters(1).Value = oADobject.FullName
MyCommand.Parameters(2).Value = oADobject.Description
MyCommand.Execute
Next
MyConnection.Close()