2013-02-19 294 views
1

我正在寫,創建自簽名作爲管理員,工作正常,但無法作爲管理員證書PowerShell腳本:X509Enrollment.CX509PrivateKey創建沒有管理員權限

的一段代碼,當我調用Create方法失敗:

$PrivateKey = New-Object -ComObject X509Enrollment.CX509PrivateKey 
$PrivateKey.ProviderName = "Microsoft RSA SChannel Cryptographic Provider" 
$PrivateKey.KeySpec = 0x1 
$PrivateKey.Length = 2048 

# set security descriptor 
$PrivateKey.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)" 

# key will be stored in local machine certificate store 
$PrivateKey.MachineContext = 0x1 

# export will be allowed 
$PrivateKey.ExportPolicy = 0x1 
$PrivateKey.Create() 

它拋出這個錯誤:

Exception calling "Create" with "0" argument(s): "CertEnroll::CX509PrivateKey::Create: Access is denied. 0x80070005 
(WIN32: 5)" 
At C:\dev\LinoaSSC.ps1:106 char:1 
+ $PrivateKey.Create() 
+ ~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
+ FullyQualifiedErrorId : ComMethodTargetInvocation 

我應該如何解決或解決這個錯誤?多謝你們!

回答

1

您需要成爲本地計算機上的管理員才能執行此操作,並且我相信大多數使用證書的操作。我不知道任何可接受的方法來解決這個問題,但有辦法提升您的權限。