1

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?

2 Answers 2

4

Use the runas command.

or

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

or

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

1
  • 1
    Props for the Scheduled Task idea - that's lateral thinking!
    – Izzy
    Sep 23, 2009 at 18:14
3

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>)

0

You must log in to answer this question.