Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Advice in Xamarin 21 79
Update Access FrontEnd by Version # 9 42
draw a Christmas tree by using a nested loop? 26 62
printf performancy 11 36
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …

776 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