Simple "Copy/Run" Command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
icabero0225
Posts: 6
Joined: 22 Jul 2016 10:11

Simple "Copy/Run" Command

#1 Post by icabero0225 » 22 Jul 2016 10:19

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

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Simple "Copy/Run" Command

#2 Post by Squashman » 22 Jul 2016 10:26

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?

icabero0225
Posts: 6
Joined: 22 Jul 2016 10:11

Re: Simple "Copy/Run" Command

#3 Post by icabero0225 » 22 Jul 2016 10:29

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Simple "Copy/Run" Command

#4 Post by Squashman » 22 Jul 2016 10:53

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.

icabero0225
Posts: 6
Joined: 22 Jul 2016 10:11

Re: Simple "Copy/Run" Command

#5 Post by icabero0225 » 22 Jul 2016 11:31

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

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Simple "Copy/Run" Command

#6 Post by ShadowThief » 22 Jul 2016 11:38

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"

icabero0225
Posts: 6
Joined: 22 Jul 2016 10:11

Re: Simple "Copy/Run" Command

#7 Post by icabero0225 » 22 Jul 2016 11:45

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:/ ?

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Simple "Copy/Run" Command

#8 Post by ShadowThief » 22 Jul 2016 12:40

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"

icabero0225
Posts: 6
Joined: 22 Jul 2016 10:11

Re: Simple "Copy/Run" Command

#9 Post by icabero0225 » 22 Jul 2016 13:05

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Simple "Copy/Run" Command

#10 Post by Squashman » 22 Jul 2016 13:07

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.

Post Reply