Require password prompt on batch file.

Gurudas 951 Reputation points
2022-06-09T18:58:42.21+00:00

Hello Team,

We have below batch file that needs to ask me for administrative credentials. Please make suitable changes.

Remove temporary files from Windows 10 via below batch file which needs to ask anyone Username and Password.

@Echo off
del "%tmp%*." /s /q /f
FOR /d %%p IN ("%tmp%*.
") DO rmdir "%%p" /s /q

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Reza-Ameri 17,336 Reputation points Volunteer Moderator
    2022-06-11T15:30:09.183+00:00

    The Temp files are in user mode, and they won't required administrator or any credential. Standard users would be able to remove it manually. In case you want to require them to add credential, you will have to add scripts to ask for credential and if the login succeed execute this part or change permission in the TEMP folder which is possible but not a good practice and standard users might face multiple access denied messages while working with PC.

    0 comments No comments

  2. Gurudas 951 Reputation points
    2022-06-14T01:26:58.12+00:00

    Hello Reza-Ameri,

    Greetings!

    I am currently working a Powershell script that requires a username and password prompt so that a user with administrative credentials can only execute this batch file via Powershell. However removing temporary files is just an example for your reference. Cheers!

    Thank you and have a great day ahead!


  3. Gurudas 951 Reputation points
    2022-06-15T09:45:43.58+00:00

    Hello MotoX80,

    I was looking for "Get-Credentials" command for executing above batch file in a test environment. Cheers!

    Url : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-credential?view=powershell-7.2


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.