Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bat file which will delete files in some folder (Profile Folder). But i do-not have access to that folder. But another account has access to the folder. How to run a batch file from one account by login into the another account which has access and delete those files?

share|improve this question

Use the runas command.


In Windows Explorer you can right-click on the bat file and choose Run As... then enter your credentials.


You could run it from a scheduled task which lets you set credentials.

share|improve this answer
Props for the Scheduled Task idea - that's lateral thinking! – Izzy Sep 23 '09 at 18:14

You have two options. One means you'll have to manually pass the password each time (not ideal), the other will let you pass with password from the batch file (but this means anyone can read the batch file and discover the password). You choose which flaw you would rather live with:

Option 1 (Manual Password Entry)

rem This is the test.bat file
runas /noprofile /env /user:myDomain\myAccount "cmd.exe /c del c:\temp\*.log"

Option 2 (Automatic Password Entry)

Use the PsExec command from Microsoft SysInternals PsTools suite:

rem This is the test.bat file
psexec -u myDomain\myAccount -p myPassword -d -e cmd.exe /c "del c:\temp\*.log"

Please note: The quote marks are in different places for each example. This is intentional. Both commands have have quirks when it comes to passing a command with lots of arguments/switches. The quote marks need to be in the exact locations I've displayed (in relation to command <arguments>)

share|improve this answer
+1 Or do this :) – squillman Sep 23 '09 at 18:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.