VBscript to retrieve Access Rights Reporting from

2019-07-21 18:33发布

问题:

While I'm working on SID conversion, I found the workable script with the VirsualSVN installed on the test machine, but the script was not working on the server. I saved file as test.vbs put on the desktop and use the following command to execute the code and produce the output as the text file: cscript test.vbs > c:\output.txt

On the test machine, I installed VisualSVN version 2.5.8 and root repositories is on C:\Repositories

While on the server, installed VisualSVN version 1.6.3 and root repositories is on E:\Repositories

From the script below, I'm lack in coding and no idea where should I modify the script to make it work on the server? I'm seeking your expert help on this.

'
' Print permissions in the form: user_name,path,level
'
strComputer = "."
Set wmi = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\VisualSVN")

Set win = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\cimv2")

' Return text representation for the Access Level
Function AccessLevelToText(level)
  If level = 0 Then
    AccessLevelToText = "No Access"
  ElseIf level = 1 Then
    AccessLevelToText = "Read Only"
  ElseIf level = 2 Then
    AccessLevelToText = "Read/Write"
  Else 
    AccessLevelToText = "Unknown"
  End If
End Function

' Return repository path for the object
Function GetPath(obj)
  cname = assoc.Path_.Class
  If cname = "VisualSVN_Service" Then
    GetPath = "Repositories Root"
  ElseIf cname = "VisualSVN_Repository" Then
    GetPath = assoc.Name
  ElseIf cname = "VisualSVN_RepositoryEntry" Then
    GetPath = assoc.RepositoryName & ": " & assoc.Path
  Else
    GetPath = "Unknown"
  End If
End Function

' Convert SID to user name
Function SidToUserName(sid)
  Set account = win.Get("Win32_SID.SID='" & sid & "'")
  user = account.AccountName
  domain = account.ReferencedDomainName
  SidToUserName = domain & "\" & user
End Function

' Iterate over all security descriptions
Set objs = wmi.ExecQuery("SELECT * FROM VisualSVN_SecurityDescriptor")
For Each obj In objs
  Set assoc = wmi.Get(obj.AssociatedObject)

  For Each perm in obj.Permissions
    sid = perm.Account.SID
    level = AccessLevelToText(perm.AccessLevel)

     Wscript.Echo SidToUserName(sid) & "," & GetPath(assoc) & "," & level
   Next
Next

Code reference from http://www.svnforum.org/threads/38790-Access-Rights-Reporting-in-Subversion-or-Viusal-SVN

回答1:

0x8004100e means that the namespace (/root/VisualSVN) doesn't exist. Perhaps the version installed on the server is too old and doesn't create this namespace in WMI.



回答2:

Following @Ansgar's answer.

VisualSVN Server versions older than 2.0 can't be managed via WMI.