runas can’t execute the copy command: The system cannot find the file specified

Today I was trying to create a script to copy files using runas, but it is failing with:
"C:\>runas /user:user "copy test.txt test2.txt””
Enter the password for user:
Attempting to start copy test.txt as user user…
RUNAS ERROR: Unable to run – copy test.txt
2: The system cannot find the file specified.

Of course the file exists, so after several attempts I found that the problem was not related to the file to be copied but to the copy command itself!

In order to solve I run the following command

"C:\>runas /user:user /env "cmd /k copy test.txt test2.txt

The /env flag is to use current environment instead of user’s.

The /k flag is to block the output shell in order to read the output of the command.

Advertisements

3 thoughts on “runas can’t execute the copy command: The system cannot find the file specified

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s