Solved

How can I output the results of a VBScript to an MS Access Database?

Posted on 2008-06-25
2
437 Views
Last Modified: 2010-08-05
I have written the following script that outputs the membership of the "Local Administrators" group on a computer.  Currently it appends to a tab delimited .txt file and I need to change the output so that it appends records to a Microsoft Access database table.  I am using the If-Then to exclude our standard Local Admin group membership and Developers workstations from the results.

Any assistance would be GREATLY appreciated...

'--------Script---------
Option Explicit
Dim strComputer, objGroup, objUser, strFile, objFSO, strDirectory
Dim objTextFile, strUserName, WshShell, DevMachine, DevMachineFound
Const forWriting = 2
Const ForAppending = 8
On Error GoTo 0

strDirectory = "C:\Data\LocalAdmin"
strFile = "\LocalAdminList.txt"
strComputer = GetComputerName

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
For Each objUser in objGroup.Members
strUserName = objUser.Name
    If (strUserName <> "Workstation Admins" And strUserName <> "Domain Admins" And _
    strUserName <> "Administrator" And DevMachine = "No") Then
    AppendToFile
    End If
Next

Function GetComputerName
    Set WshShell = CreateObject("WScript.Shell")
    strComputer = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName")
        If InStr(1,strComputer,"-d",1) Then
            DevMachine = "Yes"
        Else
            DevMachine = "No"
        End If
        GetComputerName=strComputer
End Function

Function AppendToFile
Set objFSO = CreateObject("Scripting.FilesystemObject")
Set objTextFile = objFSO.OpenTextFile (strDirectory & strFile, ForAppending, True)
objTextFile.WriteLine(Date & chr(9) & strComputer & chr(9) & UserName)
objTextFile.Close
End Function
0
Comment
Question by:tneubauertocg
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 21865724
0
 

Author Comment

by:tneubauertocg
ID: 21866630
OK, after manipulating the code from the 1st link I got it to work - thanks for assistance!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

914 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

23 Experts available now in Live!

Get 1:1 Help Now