Run bat file as administrator

Akhil Babu 1 Reputation point
2020-08-07T15:10:00.47+00:00

Hi all,

Could you please help me to execute a bat file silently as an administrator. Is it possible to add run as administrator option in a bat file. I tried the below command, but its not worked for me.

msiexec.exe /i "F:\Test\DesktopCentral_Agent.msi" /quiet /norestart

I am getting this error below.

The installer has insufficient privileges to access this directory: C:\Program Files (x86)\DesktopCentral_Agent. The installation cannot continue. Log on as administrator or contact your system administrator.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,705 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. MotoX80 32,076 Reputation points
    2020-08-07T15:58:23.377+00:00

    Based on the question, I am assuming that the user who is running the bat file is a standard user and not an administrator and does not know the administrator password. Is that a correct assumption?

    If so, is this what you are looking for?

    standard-users-run-program-admin-rights

    There is no magic switch to allow a standard user to gain administrator access without somehow providing administrator credentials. That would be a security hole. Of course if you save the credentials of the administrator account as that page describes, that may also be a security hole.

    There may be other alternatives (task scheduler) that you could use, but you would need to explain more about what you are trying to accomplish.

    1 person found this answer helpful.

  2. Akhil Babu 1 Reputation point
    2020-08-08T08:34:07.653+00:00

    Hi

    User has admin rights and able to execute the command. But its need to run as admin to execute the command properly, otherwise it wont work and shows the error mentioned below

    "The installer has insufficient privileges to access this directory: C:\Program Files (x86)\DesktopCentral_Agent. The installation cannot continue. Log on as administrator or contact your system administrator."

    0 comments No comments

  3. 2020-08-12T03:29:56.363+00:00

    Hi,

    Refer to the link below:

    https://social.technet.microsoft.com/Forums/en-US/53ff7268-a82c-4fdb-92b1-6e5b5c206826/installation-failed-in-windows-server-2016?forum=ws2016
    Note: This is a third-party link and we do not have any guarantees on this website. And Microsoft does not make any guarantees about the content.

    Best regards,
    Sylvia

    0 comments No comments

  4. MotoX80 32,076 Reputation points
    2020-08-12T16:28:37.277+00:00

    Try this bat file. If the user right clicks the bat file and selects "Run as Administrator", it will detect that it is elevated and will call the installer. If it is not elevated it will use powershell to invoke the UAC prompt and run the installer.

    @echo off
    whoami /all | findstr S-1-16-12288 > nul
    if %errorlevel%==1 goto NotAdmin
    @echo This command prompt is already elevated. Performing install.
    msiexec.exe /i "F:\Test\DesktopCentral_Agent.msi" /quiet /norestart
    goto end
    :NotAdmin 
    @echo This command prompt is not elevated. Using Powershell to invoke UAC prompt.
    Powershell.exe Start-process msiexec.exe -verb runas  -argumentlist "/i F:\Test\DesktopCentral_Agent.msi /quiet /norestart" 
    :end
    
    0 comments No comments

  5. 2020-08-14T10:38:06.817+00:00

    Just to check if the above reply could be of help, if yes, you may mark useful reply as answer, if not, welcome to feedback.

    Best regards,
    Sylvia