Solved

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

Posted on 2008-06-25
2
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
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…

734 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