Reputation: 1828
I am currently using the following code to add a certificate from the Local Machine store to the Current User Store, where $cert is the certificate.
$DestStoreScope = 'CurrentUser'
$DestStoreName = 'My'
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$DestStore.Add($cert)
$SourceStore.Close()
$DestStore.Close()
Is there a way that I could add this certificate to another users current store on this machine. It would be ran under the administrator account. Any help would be appreciated. If you need anything else, let me know!
Upvotes: 2
Views: 6232
Reputation: 200293
CurrentUser
/HKEY_CURRENT_USER
is an abstraction in the registry. The actual user data is stored in the key HKEY_USERS\<SID>
. Since CurrentUser
always refers to the currently logged in user, and the API doesn't allow accessing the certificate store by a user's SID, your only option (AFAICS) is to run the script in the context of the user who you want to have the certificate installed.
Upvotes: 4