THIS IS A VBSCRIPT (.VBS)
Below is code that i created. The connection to the dB works perfect. I have tested it with insert statements and it has been established.
My issue is that my connection is not retrieving any records from my database source. Every time I try to use the connection above I get no error but, in the same sense I return no values. I have validated the query and it works inside the database. I need to figure out why it will not read the database any ideas based on the code?
Below is code that i created. The connection to the dB works perfect. I have tested it with insert statements and it has been established.
Code:
Set Conn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
Conn.Open "Provider=sqloledb;" & _
"Data Source=" & MyDBServer & ";" & _
"Initial Catalog=" & myDB & ";" & _
"User Id=" & myDB_User & ";" & _
"Password=" & myDB_pwd & ""
' group name to remove user from
Set oGroupAdm = GetObject("WinNT://" & strComputer & "/Administrators")
' loop through all members of the Administrators group
For Each oAdmGrpUser In oGroupAdm.Members
' get the name and make it lowercase
sAdmGrpUser = LCase(oAdmGrpUser.Name)
' Leave administrator and Domain Admins alone
' use lowercase letters in the names in the If statement!
If (sAdmGrpUser <> "administrator") And (sAdmGrpUser <> "domain admins") Then
WScript.Echo sAdmGrpUser
rSql = "SELECT dbo.tbl_Access_List.SAM_Account, dbo.tbl_Assets.Comp_Name, dbo.tbl_Activity_log.exDate" _
& " FROM dbo.tbl_Access_List RIGHT OUTER JOIN" _
& " dbo.tbl_Activity_log ON dbo.tbl_Access_List.UID = dbo.tbl_Activity_log.UID LEFT OUTER JOIN" _
& " dbo.tbl_Assets ON dbo.tbl_Activity_log.SUID = dbo.tbl_Assets.AID" _
& " WHERE(dbo.tbl_Activity_log.active = 1) AND (dbo.tbl_Access_List.SAM_Account = '" & sAdmGrpUser & "') AND (dbo.tbl_Assets.Comp_Name = '" & strComputer & "')"
Code:
rs.Open rSql, Conn, adOpenStatic, adLockOptimistic rs.MoveFirst While Not rs.EOF WScript.Echo objrs.Fields.Item(1).Value ' remove users from Administrators group 'oGroupAdm.Remove oAdmGrpUser.ADsPath rs.MoveNext Wend End if Next
Comment