?
Solved

enumberating a dictionary to a text file in VBScript

Posted on 2013-06-18
3
Medium Priority
?
260 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 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