使用vb.net

问题描述

我已经成功设法提出了一个使用vb.net更改“应用程序特定的”访问权限”的过程。这等效于运行“ dcomcnfg”并通过选择“组件服务\计算机\我的计算机\ DCOM Config文件夹和特定的应用程序来更改设置。通过右键单击该应用程序并选择属性和安全性选项卡,可以添加删除不同的用户帐户。可以使用下面显示代码来正常工作。

我正在努力提出一些代码,这些代码将更改SYstem WIDE等效的“访问权限”。该代码应等效或运行“ dcomcnfg”,然后通过右键单击“组件服务\计算机\我的计算机”中的“我的电脑”,然后选择属性和安全性选项卡来更改设置。

我希望可以修改现有代码,但是因为我试图更改系统范围的设置而不是应用程序特定的设置,所以遇到了障碍。我在Google上做了很多搜索,但无法解决。任何建议表示赞赏。

Private Sub ChangeApplicationDcomAccessSecuritySettings(AddUser As Boolean,RemoveUser As Boolean)
    Dim strComputer As String = "."
    Dim objWMIService As New Object
    objWMIService = Getobject("winmgmts:" & "{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\root\cimv2")

    ' Get an instance of Win32_SecurityDescriptorHelper
    Dim objHelper As New Object
    objHelper = Getobject("winmgmts:\\" & strComputer & "\root\CIMV2:Win32_SecurityDescriptorHelper")

    ' Obtain an instance of the the class
    ' using a key property value.
    Dim objCosmosApp As Object = objWMIService.Get("Win32_DCOMApplicationSetting.AppID='" & OPCServerApplicationID.Trim & "'")

    ' Get the existing security descriptor for the App
    Dim objSD As New Object
    objSD = nothing

    Dim ret As Object
    ret = objCosmosApp.GetAccessSecurityDescriptor(objSD)
    If ret <> 0 Then
        MessageBox.Show("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
        MessageBox.Show("Could not convert to SDDL: " & ret)
    Else
    End If

    ' Set the Launch security descriptor for the App
    '  the sidString here the is the securityidentifier for the username that is to be added or removed converted to a string
    If AddUser = True And RemoveUser = False Then
        SDDLstring = SDDLstring & "(A;;CcdclCSWRP;;;" & sidString & ")"
    End If
    If AddUser = False And RemoveUser = True Then
        Dim temporarystring As String = "(A;;CcdclCSWRP;;;" + sidString + ")"
        SDDLstring = SDDLstring.Replace(temporarystring,"")
    End If
    ret = objHelper.SDDLToWin32SD(SDDLstring,objSD)
    If ret <> 0 Then
        MessageBox.Show("Could not translate SDDL String to Win32SD: " & ret)
    End If
    ret = objCosmosApp.SetaccessSecurityDescriptor(objSD)
    If ret <> 0 Then
        MessageBox.Show("Could not set security descriptor: " & ret)
    End If
End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)