Automated Copy and Run Script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Automated Copy and Run Script

#1 Post by icabero0225 » 30 Jul 2016 18:33

Hi, my name is Ignacio Cabero.

I am new to batch programming.

I want to create a program that copies an executable, pastes it in the users c:\ drive, and then executes it.

Some information: I plan on distributing this to my friends via the internet. They visit mediafire and download my file, which contains the executable and the batch file. I know it sounds a little overly complex, but I have my reasons. I don't always know exactly where the file they download will be (it could be in their Desktop, Documents, Downloads, etc.), and I also don't know their PC's username. I tried using c:\Users\$USERNAME$ with no results.

Now, I would use

Code: Select all

xcopy /s ...
but I find that I need the exact path to the folder where the batch file is, which I don't always know, as I plan on distributing this software to my friends. So I was basically wondering if there was any way where I could copy the executable file (that is in the same file as my batch file) by using the current directory, regardless of what that may be.

I know it sounds confusing, and the closest thing I could think of is like in Linux when you type for example

Code: Select all

./program.py
the "."(period) signifies the current directory, that way you don't have to type the entire path. Don't know if that helps.

Anyways, if you have ANY questions, ask them. I promise I will answer all of them with as much detail as I can.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Automated Copy and Run Script

#2 Post by aGerman » 31 Jul 2016 03:08

The easiest way is working with relative pathes. If you run call "bar.exe" then it will execute bar.exe in the working directory. If you run call "foo\bar.exe" then it will execute bar.exe in the foo subfolder of the working directory.
Furthermore absolute pathes could be created either with the %cd% variable that contains the working directory (without trailing backslash) or the %~dp0 parameter that contains the location of the batch file (with trailing backslash).
Thus, I assume there is no need to copy something to a certain place.

Type set in a cmd window and hit Enter if you want to know what environment variables you could use elsewise. (E.g. %userprofile%)

Regards
aGerman

(FWIW What's the difference to your former question? viewtopic.php?f=3&t=7303&p=47952#p47952 )

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Automated Copy and Run Script

#3 Post by foxidrive » 01 Aug 2016 06:24

icabero0225 wrote:Hi, my name is Ignacio Cabero.

I am new to batch programming.

I want to create a program that copies an executable, pastes it in the users c:\ drive, and then executes it.


Ignacio, you cannot save a file to C:\ without administrator permissions.
That is a built-in restriction in modern Windows.

Why didn't you ask further questions in your last thread?

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Automated Copy and Run Script

#4 Post by Compo » 01 Aug 2016 09:21

I would suggest you look at packaging your executable file as a self-extracting archive, (a good one should offer options such as suitable extraction location and execution parameters).

Post Reply