Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

756 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