【发布时间】:2012-07-06 23:30:52
【问题描述】:
我的任务是编写 Powershell 脚本以从头开始设置服务器以将我们的一项服务作为 Web 应用程序的一部分运行,设置此服务器所需的步骤之一是更改 DCOM 配置安装的服务,特别是将帐户添加到“启动和激活”/“访问”权限,并在添加这些帐户后设置这些帐户的权限。
有没有使用 Powershell 的方法?我还没有找到一种具体的方法来实现我的目标,所以任何帮助都会很棒
【问题讨论】:
标签: powershell dcom
我的任务是编写 Powershell 脚本以从头开始设置服务器以将我们的一项服务作为 Web 应用程序的一部分运行,设置此服务器所需的步骤之一是更改 DCOM 配置安装的服务,特别是将帐户添加到“启动和激活”/“访问”权限,并在添加这些帐户后设置这些帐户的权限。
有没有使用 Powershell 的方法?我还没有找到一种具体的方法来实现我的目标,所以任何帮助都会很棒
【问题讨论】:
标签: powershell dcom
看起来你会使用 WMI 来做。
像这样获取Win32_DCOMApplicationSetting的实例:
$dcom = Get-WMIObject -Class Win32_DCOMApplicationSetting -Filter 'Description="Something"'
现在您可以访问SetAccessSecurityDescriptor 和SetLaunchSecurityDescriptor 方法。
发件人: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)
【讨论】:
我和 OP 有同样的问题。安迪发布的答案非常有帮助,让我半途而废。然后我找到了某人写的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)
【讨论】: