Share via

need to run a cmd command as administrator within batch file

Anonymous
2018-07-16T13:09:33+00:00

Hey,

Probable pretty easy for some of you but after a bit of googling I can't quite figure it out.

I need to run a command within CMD as administrator within a batch file which then users can just run. 

Any ideas would be great.

Dan

Windows for home | Windows 10 | Settings

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

11 answers

Sort by: Most helpful
  1. Anonymous
    2018-07-16T13:55:48+00:00

    OK just to clarify. Batch files a series of shell commands run by the shell progeram (cmd.exe). Therefore you cannot make a call to the cmd.exe within the cmd.exe.

    With that said, I believe what you are trying to do is run a batch file in administrator mode.

    To do what I think you are trying to do is:

    1. Create the batch file
    2. Create a shortcut to the batch file
    3. Right click on the batch file shortcut
    4. Select properties
    5. Go to the Shortcut tab
    6. Click on the Advanced button
    7. Click the checkbox next to Run as Administrator
    8. Click on OK
    9. Click on OK

    Your batch file should run in administrator mode.

    20+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2018-07-16T13:42:39+00:00

    Hi DanTov,

    My name is Fernando. I am an Independent Advisor. I am here to guide you with your batch file.

    Are you trying to run batch file in administrator mode?

    Respectfully,

    Fernando Y.

    9 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2018-07-16T14:48:19+00:00

    Hi Dan for security reasons that cannot be done . . .

    Commands that require Admin privileges, whether in a batch or in a CMD window, will always ask the user for permission.

    Otherwise malware would use this method to bypass the Admin requirement and wreak havoc on our systems . . .

    8 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2018-07-16T14:29:18+00:00

    Ok thanks, for that Fernando.

    But I need to for it to run without prompting me. Like it automatically puts in the credentials and doesn't keep them on the system.

    8 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2018-07-16T15:20:07+00:00

    Couldn't i add the credentials into the batch file so it already has the info it needs. I want to be able to run a script on a pc and no matter who is logged in it will run. but the script needs to be as administrator.

    4 people found this answer helpful.
    0 comments No comments