Jump to content

Recommended Posts

Posted (edited)

Look at the below code:

; Script Start - Add your code below here

; Counting the number of open shell windows

$oShell = ObjCreate("shell.application")    ; Get the Windows Shell Object
$oShellWindows=$oShell.windows          ; Get the collection of open shell Windows
$g_oGroupDict = ObjCreate("Scripting.Dictionary") ;Create the dictionary Object
$g_oNet = ObjCreate("Wscript.Network")

if Isobj($oShellWindows) then

  $string=""                    ; String for displaying purposes

  for $Window in $oShellWindows         ; Count all existing shell windows
    $String = $String & $window.LocationName & @CRLF
  next

  Msgbox(0,"Shell Windows","You have the following shell windows:" & @CRLF & @CRLF & $String);

endif

If IsMember("MDG_SGAI") Then
    
    Msgbox(0,"Shell Windows","You are a member of the SGAI group:" & @CRLF & @CRLF & $String);
    
EndIf   

Func IsMember($sGroup)
    Msgbox(0,"IsMember Function Msg","Group being passed:" & @CRLF & @CRLF & $sGroup);
     If IsObj($g_oGroupDict) Then
         $g_oGroupDict.CompareMode = 1
         $sAdsPath = $g_oNet.UserDomain & "/" & $g_oNet.UserName
         $oUser = ObjGet("WinNT://" & $sAdsPath & ",user")
         
         Msgbox(0,"IsMember Function Msg","The user being used is:" & @CRLF & @CRLF & $g_oNet.UserName);
         
         For $oGroup in $oUser.Groups
             $g_oGroupDict.Add $oGroup.Name, "-"
         Next    
         
    IsMember = CBool($g_oGroupDict.Exists(sGroup))
    
    EndIf
EndFunc

Exit

I apologize for not using the code tags but I haven't gotten your site cleared through bluecoat yet and the active content is nuetralized. It takes the NOSC about a week to make a bluecoat entry, anyway, I disgress ...

In the IsMember function (which I converted from a VBS function, some of you may recognize it) the dictionary object add method fails. The only error message I get is "The requested action with this object has failed." Everything else is working spiffy. Obviously, I'm muffing it somewhere, I would be very thankful for some guidance here.

TIA

Edited by Larry

Steve WolfeScripting Dog

Posted

Update on my travels in the dictionary object.

Code:

Func IsMember($sGroup)

Msgbox(0,"IsMember Function Msg","Group being passed:" & @CRLF & @CRLF & $sGroup);

If IsObj($g_oGroupDict) Then

$g_oGroupDict.CompareMode = 1

$sAdsPath = $g_oNet.UserDomain & "/" & $g_oNet.UserName

$oUser = ObjGet("WinNT://" & $sAdsPath & ",user")

Msgbox(0,"IsMember Function Msg","The user being used is:" & @CRLF & @CRLF & $g_oNet.UserName);

For $oGroup in $oUser.Groups

Msgbox(0,"IsMember Function Msg","Group membership detected:" & @CRLF & @CRLF & $oGroup.Name);

;$g_oGroupDict.Add $oGroup.Name, "-"

Next

IsMember = CBool($g_oGroupDict.Exists(sGroup))

EndIf

EndFunc

End of code

Note that I commented out the add method and put a msgbox in to see if I was enumerating the $oGroups.Groups collection properly. The IsMember = CBool($g_oGroupDict.Exists(sGroup)) blows up but I really haven't done a conversion on that yet except for putting the '$' onto g_oGroupDict.

This is just a FYI, I probably should comment it out until I get the dictionary object right.

Steve

Steve WolfeScripting Dog

  • 5 weeks later...
Posted

You've probably figured out by now that the parameters need to be enclosed in parens. So

$g_oGroupDict.Add $oGroup.Name, "-"

would need to be

$g_oGroupDict.Add ($oGroup.Name, "-")

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...