Solved

enumberating a dictionary to a text file in VBScript

Posted on 2013-06-18
3
257 Views
Last Modified: 2013-06-27
I have a need here at work to create a text file of the currently logged in user (at login) that would enumberate the groups the user is a member of and write it to a text file. I have a function I use to enumerate the groups, but I do not know how to read the dictionary itself and write those values to a text file. Here is the function I use at logon to identify the groups;

Function IsMember(sGroup)
 Dim sAdsPath, oUser, oGroup
 If IsEmpty(oGroupDict) Then
     Set oGroupDict         = CreateObject("Scripting.Dictionary")
     oGroupDict.CompareMode = vbTextCompare
     sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
     Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
     For Each oGroup In oUser.Groups
         oGroupDict.Add oGroup.Name, "-"
     Next
     Set oUser = Nothing
 End If
 IsMember = CBool(oGroupDict.Exists(sGroup))
End Function

Any help would be appreciated
0
Comment
Question by:Akish1960
[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
3 Comments
 
LVL 16

Accepted Solution

by:
cantoris earned 500 total points
ID: 39260359
Here's the sort of thing you could use.

strOutputFilePath = "C:\GroupsList.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile(strOutputFilePath, True)
For Each strKey In oGroupDict.Keys
   objOutputFile.WriteLine strKey
Next
objOutputFile.Close

Open in new window

0
 

Author Comment

by:Akish1960
ID: 39263632
thank you. i will try this out and comment or accept soon.
0
 

Author Closing Comment

by:Akish1960
ID: 39282633
So I put it into the function, as follows, and it works as advertised. Thank you so much for your help.

Function IsMember(sGroup)
Dim sAdsPath, oUser, oGroup

strOutputFilePath = strShare & "\" & strComputer & "_group.log"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = oFSO.CreateTextFile(strOutputFilePath, True)
 
 If IsEmpty(oGroupDict) Then
     Set oGroupDict         = CreateObject("Scripting.Dictionary")
     oGroupDict.CompareMode = vbTextCompare
     sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
     Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
     For Each oGroup In oUser.Groups
         oGroupDict.Add oGroup.Name, "-"
     Next
     For Each strKey In oGroupDict.Keys
    objOutputFile.WriteLine strKey
      Next
      objOutputFile.Close
     Set oUser = Nothing
 End If
 IsMember = CBool(oGroupDict.Exists(sGroup))
End Function
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

729 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