We have a setup program that runs an MSBuild script which imports a self-signed certificate in the local computer account's Personal/My certificate store. I am in the Administrators group on the server where setup is being run, and UAC is not enabled. When I run my script, and import the certificate, I am unable to use it in IIS. Process Monitor shows access denied errors when I try to assign it to a website.
However, when I explicitly run my script as an administrator (right-click and choose "Run As Administrator"), the certificate is imported successfully, and I can use it in IIS. This is extremely bizarre to me.
How can I tell if my script/program is running as an administrator? I'd like to add a check to the setup script that fails if it detects it isn't running with this weird "Run As Administrator" privilege. I would prefer an answer in C#/.NET.
I've tried using GetTokenInformation
, to get the elevation type, but that only works when UAC is enabled.
Using System.Security.Principal.WindowsIdentity.IsInRole(WindowsBuiltInRole.Administrator)
return true in a regular and "elevated" prompt.
I've compared the Owner, User, and Group SIDS exposed by System.Security.Principal.WindowsIdentity.GetCurrent
, and the list is the same in a regular and "elevated" prompt.