Solved

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

Posted on 2008-06-25
2
429 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

758 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

19 Experts available now in Live!

Get 1:1 Help Now