WMI - 以编程方式更新 DCOM 设置

发布于 2024-10-15 12:50:02 字数 1738 浏览 1 评论 0原文

我创建了一个小 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

I created a little exe to modify some DCOM settings. The exe works fine when I try to modify the settings on a different server from where the exe is running but does not work when I try to modify the settings on the same server where the exe is running

If I set strComputer to the name of another Remote machine the code works and updates the correct settings on the Remote machine

The error I get when running this when trying to update the same server is the error that I throw:

Could not get security descriptor' with return code of -2147023582

Code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

居里长安 2024-10-22 12:50:02

我尝试在 Windows 7 上运行你的程序并遇到了同样的问题。最初我认为添加 Security 参数是您的 名字字符串 可以解决问题,但事实并非如此。然后我以管理员身份运行你的程序并且它起作用了。所以看来缺少一些安全特权。

I tried running your program on Windows 7 and encountered the same problem. Initially I thought that adding the Security parameter your Moniker string would resolve the problem, but it didn't. I then ran your program as an administrator and it worked. So it seems that some security privilege is missing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文