VBA – 检查用户的Excel工作簿在服务器上打开

我正在尝试使用VBA来确定哪个用户在共享networking服务器上打开了一个excel工作簿。 我用两个独立的函数编写了一个基本的例程,它们使用'winmgmts'和'ADsSecurityUtility'对象来实现这个function,函数基于以下链接:

如何判断Excel 2007电子表格是否打开,世卫组织是否使用VBScript打开它

获取磁盘上文件的所有者

我的代码如下:

Sub wkbk_open() wkbk_name = "Project List LIVE.xlsm" wkbk_lock_file_path = "X:\~$" & wkbk_name Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(wkbk_lock_file_path) Then Debug.Print "The file is locked by " & GetFileOwner(wkbk_lock_file_path) Debug.Print "The file is locked by " & GetFileOwner2(wkbk_lock_file_path) Else Debug.Print "The file is available" End If End Sub Function GetFileOwner(strFileName) 'http://www.vbsedit.com/scripts/security/ownership/scr_1386.asp Set objWMIService = GetObject("winmgmts:") Set objFileSecuritySettings = _ objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFileName & "'") intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD) If intRetVal = 0 Then GetFileOwner = objSD.Owner.Name Else GetFileOwner = "Unknown" End If End Function Function GetFileOwner2(strFileName) As String 'On Error Resume Next Dim secUtil As Object Dim secDesc As Object Set secUtil = CreateObject("ADsSecurityUtility") Set secDesc = secUtil.GetSecurityDescriptor(strFileName, 1, 1) GetFileOwner2 = secDesc.Owner End Function 

但是,当我执行这个代码。 函数1返回:

 The file is locked by 

并有两个返回函数:

 The file is locked by S-1-5-21-3895087902-3842375508-912246676-1159 

有谁知道如何让winmgts服务返回一个所有者或将SID(安全标识符)转换为用户名?