Vbsedit includes all these samples. Try it now!


' Retrieve Object Instance Permissions



Const adVarChar = 200
Const MaxCharacters = 255

strInstanceKey="SMS00001"
iObjectKey = 1
'1-Collection,2-Package,3-Advertisement,4-StatusMessage,6-Site,7-Query,8-Report,9-SoftwareMeteringRule

On Error Resume Next
Set DataList = CreateObject("ADOR.Recordset")
With DataList.Fields
    .Append "UserName", adVarChar, MaxCharacters
    .Append "PermissionName", adVarChar, MaxCharacters
End With
DataList.Open

Set ProviderLoc = GetObject("winmgmts:{impersonationLevel=impersonate}!root/sms:SMS_ProviderLocation")
If err.number<;>;0 Then
    wscript.echo "Couldn't Get SMS Provider"
    wscript.quit
End If

For Each Location In ProviderLoc.Instances_
    If Location.ProviderForLocalSite = True Then
        Set objSWbemServices = GetObject("winmgmts:" & Location.NamespacePath)
        Exit For
    End If
Next

Select Case iObjectKey
   Case 1 strObjectKeyName = "Collection"            
   Case 2 strObjectKeyName = "Package"
   Case 3 strObjectKeyName = "Advertisement"
   Case 4 strObjectKeyName = "Status Message"
   Case 6 strObjectKeyName = "Site" 'ObjectKey #5 is unused
   Case 7 strObjectKeyName = "Query"
   Case 8 strObjectKeyName = "Report"
   Case 9 strObjectKeyName = "Software Metering Rule"
   Case 10 strObjectKeyName = "Software Updates"
End Select

Wscript.Echo "Permissions for " & strObjectKeyName & ": " + UCase(strInstanceKey)

Set colInstancePermissionNames=objSwbemServices.InstancesOf("SMS_UserInstancePermissionNames")
For Each objInstancePermissionName In colInstancePermissionNames
    If Ucase(objInstancePermissionName.InstanceKey)=Ucase(strInstanceKey) Then
        AddNewData objInstancePermissionName.UserName, objInstancePermissionName.PermissionName
    End If
Next

Set colClassPermissionNames=objSwbemServices.InstancesOf("SMS_UserClassPermissionNames")
For Each objClassPermissionName In colClassPermissionNames
    If Ucase(objClassPermissionName.ObjectKey)=Ucase(iObjectKey) Then
        AddNewData objClassPermissionName.UserName, objClassPermissionName.PermissionName
    End If
Next

DataList.Sort = "PermissionName"
DataList.MoveFirst
Do Until DataList.EOF
    wscript.echo DataList.Fields.Item("PermissionName")&; " - " & DataList.Fields.Item("UserName")
    DataList.MoveNext
Loop

Function AddNewData (UserName, Permission)
    Datalist.AddNew
    Datalist("UserName") = UserName
    Datalist("PermissionName") = Permission
End Function

Wscript.Quit

search for scripts


VbsEdit includes all these samples!


VbsEdit now supports .vbs, .js, .wsf and .hta scripts.
The evaluation version never expires.




Home   Scripts

Copyright © 2001-2019 adersοft