我创建了一个小 exe 来修改一些 DCOM 设置。当我尝试在运行 exe 的不同服务器上修改设置时,exe 工作正常,但当我尝试在运行 exe 的同一服务器上修改设置时,exe 无法正常工作
如果我将 strComputer 设置为另一台远程计算机的名称,则代码可以工作并更新远程计算机上的正确设置
尝试更新同一服务器时运行此程序时遇到的错误是我抛出的错误:
无法获取安全描述符',返回码为 -2147023582
代码:
Dim strComputer As String = "." 'localhost
Dim objWMIService As Object = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' Get an instance of Win32_SecurityDescriptorHelper
Dim objHelper = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2:Win32_SecurityDescriptorHelper")
' Obtain an instance of the the class using a key property value.
Dim objApp As Object = objWMIService.Get("Win32_DCOMApplicationSetting.AppID='{E9E35B75-5B49-4C13-B928-239F78D695A6}'")
' Get the existing security descriptor for the App
Dim objSD As Object
Dim ret = objApp.GetLaunchSecurityDescriptor(objSD)
If ret <> 0 Then
Throw new ApplicationException("Could not get security descriptor: " & ret)
End If
' Convert file security descriptor from Win32_SecurityDescriptor format to SDDL format
Dim SDDLstring As String
ret = objHelper.Win32SDToSDDL(objSD, SDDLstring)
If ret <> 0 Then
Throw new ApplicationException("Could not convert to SDDL: " & ret)
End If
' Set the Launch security descriptor for the App
SDDLstring = SDDLstring & "(A;;CCDCLCSWRP;;;NS)"
ret = objHelper.SDDLToWin32SD(SDDLstring, objSD)
If ret <> 0 Then
Throw new ApplicationException("Could not translate SDDL String to Win32SD: " & ret)
End If
ret = objApp.SetLaunchSecurityDescriptor(objSD)
If ret <> 0 Then
Throw new ApplicationException("Could not set security descriptor: " & ret)
End If