Home > Software design >  Trusted Publisher Certificate installation
Trusted Publisher Certificate installation

Time:03-28

Is there any way we can add certificate using cmd/shell/bat silently without administrator rights in windows 10.

I have a command which silently add cert in "Trusted Publisher" :

certutil -addstore "TrustedPublisher" my_certificate.cer

But this command needs administrator command prompt to run.

CodePudding user response:

According to comments below question, this batch should answer your needs:

@echo off
setlocal EnableExtensions EnableDelayedExpansion

REM Check admin mode, auto-elevate if required.
openfiles > NUL 2>&1 || (
    REM Not elevated. Do it.
    echo createObject^("Shell.Application"^).shellExecute "%~dpnx0", "%*", "", "runas">"%TEMP%\%~n0.vbs"
    cscript /nologo "%TEMP%\%~n0.vbs"
    goto :eof
)
del /s /q "%TEMP%\%~n0.vbs" > NUL 2>&1

REM Can't be here without elevation.
certutil -addstore "TrustedPublisher" my_certificate.cer

goto :eof

The batch will ask for elevation automatically and then execute your command, in an elevated cmd, and terminate.

  • Related