使用Powershell更改DCOM配置安全设置

时间:2012-07-06 13:40:39

标签: powershell dcom

我已经完成了编写Powershell脚本以从头开始设置服务器以运行我们的服务作为Web应用程序的一部分的任务,并且设置此服务器所需的步骤之一是更改DCOM配置已安装的服务,特别是将帐户添加到“启动和激活”/“访问”权限,并在添加这些帐户后设置这些帐户的权限。

是否有使用Powershell执行此操作的方法?我无法找到一种具体的方法来实现我的目标,所以任何帮助都会很棒

2 个答案:

答案 0 :(得分:13)

看起来你会使用WMI。

像这样获取Win32_DCOMApplicationSetting的实例:

$dcom = Get-WMIObject -Class Win32_DCOMApplicationSetting -Filter 'Description="Something"'

现在,您可以访问SetAccessSecurityDescriptorSetLaunchSecurityDescriptor方法。

来自:http://msdn.microsoft.com/en-us/library/windows/desktop/aa384905(v=vs.85).aspx

  

DCOM应用程序

     

DCOM应用程序实例有几个安全描述符。开始   在Windows Vista中,使用Win32_DCOMApplicationSetting的方法   用于获取或更改各种安全描述符的类。安全   描述符作为Win32_SecurityDescriptor的实例返回   类。

     

要获取或更改配置权限,请致电   GetConfigurationSecurityDescriptor或   SetConfigurationSecurityDescriptor方法。

     

要获取或更改访问权限,请致电   GetAccessSecurityDescriptor或SetAccessSecurityDescriptor方法。

     

要获取或更改启动和激活权限,请致电   GetLaunchSecurityDescriptor或SetLaunchSecurityDescriptor方法。

     

Windows Server 2003,Windows XP,Windows 2000,Windows NT 4.0和   Windows Me / 98/95:Win32_DCOMApplicationSetting安全性   描述符方法不可用。

还有一个名为DCOMPERM的工具,Windows SDK中提供了源代码:http://www.microsoft.com/en-us/download/details.aspx?id=8279

如果您搜索已编译的DCOMPERM,可以在线查找已编译的版本。

以下是命令行选项:

Syntax: dcomperm <option> [...] 
Options:

Modify or list the machine access permission list 
-ma <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r"] 
-ma list

Modify or list the machine launch permission list 
-ml <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r,ll,la,rl,ra"] 
-ml list

Modify or list the default access permission list 
-da <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r"] 
-da list

Modify or list the default launch permission list 
-dl <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r,ll,la,rl,ra"] 
-dl list

Modify or list the access permission list for a specific AppID 
-aa <AppID> <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r"] 
-aa <AppID> default 
-aa <AppID> list

Modify or list the launch permission list for a specific AppID 
-al <AppID> <"set" or "remove"> <Principal Name> ["permit" or "deny"] ["level:l,r,ll,la,rl,ra"] 
-al <AppID> default 
-al <AppID> list

level: 
    ll - local launch (only applies to {ml, dl, al} options) 
    rl - remote launch (only applies to {ml, dl, al} options) 
    la - local activate (only applies to {ml, dl, al} options) 
    ra - remote activate (only applies to {ml, dl, al} options) 
    l - local (local access - means launch and activate when used with {ml, dl, al} options) 
    r - remote (remote access - means launch and activate when used with {ml, dl, al} options)

答案 1 :(得分:7)

我和OP有同样的问题。 Andy发布的答案非常有帮助,让我半途而废。然后我找到了某人编写的Set-DCOMLaunchPermissions来帮助他们部署SharePoint。

我根据自己的目的调整了自己的功能,并提出了一个设置我需要的权限的解决方案。

$user = "sql2012agent"
$domain = "MYDOMAIN"
$appdesc = "Microsoft SQL Server Integration Services 11.0"
$app = get-wmiobject -query ('SELECT * FROM Win32_DCOMApplicationSetting WHERE Description = "' + $appdesc + '"') -enableallprivileges
#$appid = "{83B33982-693D-4824-B42E-7196AE61BB05}"
#$app = get-wmiobject -query ('SELECT * FROM Win32_DCOMApplicationSetting WHERE AppId = "' + $appid + '"') -enableallprivileges
$sdRes = $app.GetLaunchSecurityDescriptor()
$sd = $sdRes.Descriptor
$trustee = ([wmiclass] 'Win32_Trustee').CreateInstance()
$trustee.Domain = $domain
$trustee.Name = $user
$fullControl = 31
$localLaunchActivate = 11
$ace = ([wmiclass] 'Win32_ACE').CreateInstance()
$ace.AccessMask = $localLaunchActivate
$ace.AceFlags = 0
$ace.AceType = 0
$ace.Trustee = $trustee
[System.Management.ManagementBaseObject[]] $newDACL = $sd.DACL + @($ace)
$sd.DACL = $newDACL
$app.SetLaunchSecurityDescriptor($sd)
相关问题