?
Solved

enumberating a dictionary to a text file in VBScript

Posted on 2013-06-18
3
Medium Priority
?
268 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
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
cantoris earned 2000 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
It is a real story and is one of my scariest tech experiences. Most users think that IT experts like us know how to fix all computer problems. However, if there is a time constraint and you MUST not fail the task or you will lose your job, a simple …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

829 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