2011-02-04 20 views
2

我創建了一個小的exe文件來修改某些DCOM設置。當我嘗試修改EXE運行時不同服務器上的設置時,EXE正常工作,但在嘗試修改運行EXE的服務器上的相同服務器上的設置時無法運行WMI - 以編程方式更新DCOM設置

代碼低於

如果我設置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 

回答

0

我試着在Windows 7上運行你的程序,並遇到同樣的問題。最初我以爲加入Security參數你的Moniker string可以解決問題,但事實並非如此。然後我以管理員身份運行您的程序並運行。所以似乎缺少一些安全特權。

+0

對不起後期 - 已離開。即時通訊使用「以管理員身份運行」選項,但沒有取得任何成功。 – David 2011-02-21 03:03:54