Page 1 of 1

Simple "Copy/Run" Command

Posted: 22 Jul 2016 10:19
by icabero0225
Hello, my name is Ignacio Cabero.

I am trying to run a simple program that copies an executable file from my "E:\" drive to my "C:\" drive, and then run that executable.

I have no experience with batch. Seriously. I come from a python and C++ background, but I wanted to experiment with batch. Here is my code:

Code: Select all

xcopy /s E:\test.exe C:\

start "C:\test.exe

When I start the batch file, I get a black command prompt that starts for a few seconds, with a line that says

Code: Select all

Access denied

I run as administrator, and it copies.

There are two problems here:

1) I want this to work without having to run as administrator
2) I want the executable to not only copy the file to C:\, but I also want it to run automatically

Thank you. If you need ANY more information, just ask.

Thank you,

Ignacio Cabero

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 10:26
by Squashman
Why does it need to be copied to the root of the System Drive?
Why not just make a directory off the root of the system drive and copy it to that directory and then execute it?

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 10:29
by icabero0225
Squashman wrote:Why does it need to be copied to the root of the System Drive?
Why not just make a directory off the root of the system drive and copy it to that directory and then execute it?


If I understand you, you mean create a pathway, like "c:\Users\username\Desktop\*", for example? The problem with this is that I have made a program which I want to share with my friends, but I don't exactly know all of their usernames, nor do I want to create a separate program for all of them.

Thank you.

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 10:53
by Squashman
icabero0225 wrote:
Squashman wrote:Why does it need to be copied to the root of the System Drive?
Why not just make a directory off the root of the system drive and copy it to that directory and then execute it?


If I understand you, you mean create a pathway, like "c:\Users\username\Desktop\*", for example? The problem with this is that I have made a program which I want to share with my friends, but I don't exactly know all of their usernames, nor do I want to create a separate program for all of them.

Thank you.


No. I said create a directory off of the root of the system drive.
C:\MyFolder

How are you sharing this with your friends?
If you are sharing it with your friends why don't you let them decide where they want to put it?

If they are executing the file on their own computers you don't need to know their username on their computer to move it to their desktop or any folder within their user profile. There is an environmental variable called username that you can use.

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 11:31
by icabero0225
Squashman wrote:
icabero0225 wrote:
Squashman wrote:Why does it need to be copied to the root of the System Drive?
Why not just make a directory off the root of the system drive and copy it to that directory and then execute it?


If I understand you, you mean create a pathway, like "c:\Users\username\Desktop\*", for example? The problem with this is that I have made a program which I want to share with my friends, but I don't exactly know all of their usernames, nor do I want to create a separate program for all of them.

Thank you.


No. I said create a directory off of the root of the system drive.
C:\MyFolder

How are you sharing this with your friends?
If you are sharing it with your friends why don't you let them decide where they want to put it?

If they are executing the file on their own computers you don't need to know their username on their computer to move it to their desktop or any folder within their user profile. There is an environmental variable called username that you can use.


There is obviously some confusion between us, but that is not important.

I still need to know the command to execute. I also want a message to appear letting them know that the program has executed.

Thank you

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 11:38
by ShadowThief
You're missing a " in your code. Three, arguably, since the path should also be surrounded by quotes.

Code: Select all

start "" "C:\test.exe"

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 11:45
by icabero0225
ShadowThief wrote:You're missing a " in your code. Three, arguably, since the path should also be surrounded by quotes.

Code: Select all

start "" "C:\test.exe"


Okay, thank you.
Now is there any way so that I don't have to run as administrator? or is that only because I am trying to run a program in c:/ ?

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 12:40
by ShadowThief
Yeah, don't try to run programs directly out of C:\

You can run it from any user's profile by saying

Code: Select all

 start "" "%userprofile%\test.exe"

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 13:05
by icabero0225
ShadowThief wrote:Yeah, don't try to run programs directly out of C:\

You can run it from any user's profile by saying

Code: Select all

 start "" "%userprofile%\test.exe"


Thank you, this really helped.

What about running as administrator?

Thank you.

Re: Simple "Copy/Run" Command

Posted: 22 Jul 2016 13:07
by Squashman
icabero0225 wrote:
ShadowThief wrote:Yeah, don't try to run programs directly out of C:\

You can run it from any user's profile by saying

Code: Select all

 start "" "%userprofile%\test.exe"


Thank you, this really helped.

What about running as administrator?

Thank you.

You don't need to. The reason you are getting the Access Denied is because you are trying to write to the root of the C: drive. Just use the userprofile variable as ShadowTheif has suggested or the username variable that I suggested.