开发者

WMI - Update DCOM settings Programmatically

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:开发者_JAVA百科 " & ret)
End If


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜