iexpress extract files then run script referring extracted file - file

I was trying to deploy my project with IExpress. I have the following scenario. I want to extract some files to a location preferably c:\program files\. Then after it copies all the files i want it to run a .cmd file (which is a script). the script is also added in the project itself and it would refer to a file which is copied by IExpress. Now how can access the path on which the file was extracted. So that i can access it in my script.

If the script is in the project itself, thus being extracted in the same directory when you send your files to, it should start in the same directory.
Test it easy, make a cmd like this:
cmdsetup.cmd:
#echo Source path: %~dp0 >> %temp%\%~n0.log
Put this in your package and when it's done, go check the %temp% directory, locate the cmdsetup.log file and look in it. This should be the path where your files are.
If so, go from there. If I got this wrong, come back and comment, also amend your question to make it clearer.
I hope this helps.
P.s.: Voted for the question as I don't see why the negative vote was given.

The answer is use this format:
start /wait .\hello.cmd
I did this with the following two files. One key thing is that the file I was calling had to be in 8.3 format. In otherwords it failed to find hello.cmd the first time because i called it hello.world.cmd.
First file (start.cmd)
#echo off
cls
echo this is start.cmd
pause
dir
pause
echo going to hello world
start /wait .\hello.cmd
echo back in start.cmd
pause
Second file (hello.cmd)
#echo off
echo HELLO WORLD!
pause
exit
Directions
Use IEXPRESS to create a package that contains both files above. Have it launch START.CMD.

Related

How to get the current path of my batch file? [duplicate]

I have a batch file that I intend to distribute to our customers to run a software task.
We distribute them as a folder or .zip with the files inside. Inside, there is the batch files and another folder with the files needed to run the batch.
Normally, when you make a batch, you type the path where the files are. But I won't know where the files are. The files will still be kept inside the master folder, but I need to have the batch find that folder to run the files.
So for example: If they have the master folder on the desktop and they run it, it would need to be something like "C:\Users\Username\Desktop" to run. You would have the batch CD to that location.
But what if they run it from documents? I don't know the username, so I have to somehow have the batch find this. Any code and/or instructions would be great.
There is no need to know where the files are, because when you launch a bat file the working directory is the directory where it was launched (the "master folder"), so if you have this structure:
.\mydocuments\folder\mybat.bat
.\mydocuments\folder\subfolder\file.txt
And the user starts the "mybat.bat", the working directory is ".\mydocuments\folder", so you only need to write the subfolder name in your script:
#Echo OFF
REM Do anything with ".\Subfolder\File1.txt"
PUSHD ".\Subfolder"
Type "File1.txt"
Pause&Exit
Anyway, the working directory is stored in the "%CD%" variable, and the directory where the bat was launched is stored on the argument 0. Then if you want to know the working directory on any computer you can do:
#Echo OFF
Echo Launch dir: "%~dp0"
Echo Current dir: "%CD%"
Pause&Exit
ElektroStudios answer is a bit misleading.
"when you launch a bat file the working dir is the dir where it was launched"
This is true if the user clicks on the batch file in the explorer.
However, if the script is called from another script using the CALL command, the current working directory does not change.
Thus, inside your script, it is better to use %~dp0subfolder\file1.txt
Please also note that %~dp0 will end with a backslash when the current script is not in the current working directory.
Thus, if you need the directory name without a trailing backslash, you could use something like
call :GET_THIS_DIR
echo I am here: %THIS_DIR%
goto :EOF
:GET_THIS_DIR
pushd %~dp0
set THIS_DIR=%CD%
popd
goto :EOF
You can also do
Pushd "%~dp0"
Which also takes running from a unc path into consideration.
Try in yourbatch
set "batchisin=%~dp0"
which should set the variable to your batch's location.

Batch script does not run in temporary folder after decompressing SFX WinRAR file

I have a program with a separate setup for 32 and 64 bits. My goal is to create a single executable that can run the appropriate setup. So I created a folder and placed the two setups inside, then wrote the following script:
#echo off
if %PROCESSOR_ARCHITECTURE%==AMD64 goto :x64
if %PROCESSOR_ARCHITEW6432%==AMD64 goto :x64
:x86
"%cd%"\setup.exe
exit
:x64
"%cd%"\setup-x64.exe
exit
Afterwards, I created the SFX file with this folder in WinRAR, pointing to the BAT file. But when I run it, a command line window pops up and shuts down instantly and nothing happens. I go to the temporary folder and double click the BAT file and the setup starts. The same happens in the original folder. What is happening and how can I fix it? Thanks!
%cd% reffers to the directory of the call of the batch-file.
For example a batch-file is in %USERPROFILE%\Desktop\Folder\bat.bat:
echo %cd%
pause
and you start it for example from the command-line like this:
C:\>%USERPROFILE%\Desktop\Folder\bat.bat
it should echo C:\ as that is where you called it from.
Two ways from the comments to solve the problem:
Push the directory of the batch-file using pushd "%~dp0" -> will result in a change of the variable value of %cd%
or
do not use "%cd%" but "%~dp0"
Both ways use the fact that the zeroth argument of a batch-file is its path.
You can prevent the command-line window from closing if you are debugging the file from the command-prompt itself if possible. With that you should have seen an error that state something like ...\setup.exe not found. After that nothing had to be done from the batch-file so it closed.

changing the path in the batch script dynamically on run time

I am working on a batch script file to copy and trigger a .exe file installation
So i have coded it as follows:
set path = "c:\path_to_install_exe\"
set installationfilepath=%cd%
(this one gives, d:\installation_file_path\commands)
the installation file is present in the above path and i want to copy from my current working directory
so i gave the it as
echo xcopy "%installationfilepath%\..\install.exe" "%path_to_install_exe%"
But this does not do the necessary operation. i get d:\installation_file_path\commands..\install.exe as an output.
Can anyone please help me on this, as i am new to batch file scripting.
You could always use pushd and popd to change the directory the batch file assumes.
Like how
pushd C:\Users\Arescet\Desktop\
echo Hello world! > Hi.txt
popd
Will create "Hi.txt" with 'Hello world!' no matter where you launch the bat.
For shorter commands, you're better off setting a different fileName, in the list of default variables 'path' is already a system variable, and it is unwise to change it, as 'MC ND' stated.
For just one single file, you're better off with the copy command as it lets you indicate the path type.

I am trying to overwrite sticky keys(sethc.exe) with cmd.exe but when running the script it cant find files

I am trying to overwrite two files with each other but it gives me a message that it cant find the files specified.
#echo off
set /p Drive=Enter local hard drive letter:
if "%Drive%"=="" goto :eof
xcopy Drive:\windows\system32\sethc.exe Drive:
xcopy Drive:\windows\system32\cmd.exe Drive:\windows\system32\sethc.exe
Make sure you files are in the same path as your batch file is, for example:
#echo off
start minecraft.exe
In this example, obviously it starts minecraft, but in the format it currently is, it would require minecraft to be located on your desktop if your batch file is on your desktop, if minecraft.exe is in a folder named "Folder1" then you would type:
#echo off
Start "C:\Users\<your name>\Desktop\Folder1\minecraft.exe"
In order for this to work, your batch file will also need to be located in Folder1 as well. Obviously, instead of minecraft.exe, you would use the files that you are using.
As long as your batch file is in the same path as your files then it should work. I hope the example I used helped you.
You are using %drive% where you should use drive
and using drive where you should use %drive%

wkhtmltopdf in batch file

I am trying to make batch file for wkhtmltopdf.exe to convert html to pdf, and come up with this code.
#echo off &setlocal enabledelayedexpansion
for %%i in (*.html) do (
set "line="
for %%j in ("%%~ni.*") do set line=!line! "%%~j"
start "" wkhtmltopdf.exe !line!
)
However, it din't convert anything and gave 2 lines of result
wkhtmltopdf.exe awb112312.html awb112312.pdf
wkhtmltopdf.exe invoice.html invoice.pdf
I suppose, there is the error message
wkhtmltopdf.exe not recognized as an internal or external command, operable program or batch file.
output on running this batch file.
The reason is wkhtmltopdf.exe is used in batch file without complete path. Therefore Windows searches first in current working directory of the batch file and next in all directories included in environment variable PATH separated by semicolons for the file wkhtmltopdf.exe and does not find it anywhere as the application is most likely installed into a subdirectory of %ProgramFiles% or %ProgramFiles(x86)%.
wkhtmltopdf is a console application according to homepage of wkhtmltopdf and therefore the command START should not be really needed at all.
Also the inner FOR loop does not make much sense for me if simply each *.html file in current working directory should be converted to a PDF file. Why searching for other files with same name as already found *.html file with any file extension in current working directory and concatenate all found file names to one string?
I think, all really needed is:
#echo off
for %%i in (*.html) do "Complete path to wkhtmltopdf\wkhtmltopdf.exe" "%%i" "%%~ni.pdf"
This works just fine for me in Windows 10 1809 Just FYI took me forever to figure it out.
#echo off
"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" estimate.html estimate.pdf
echo Complete!
#pause
This happened to me on windows when trying to run it through system call in a PHP application. The quick and dirty solution is to Copy the contents of the bin directory to the directory of your php/web application.
I've tried setting the path, restarting the web server etc. It works correctly when invoked from the command line but not when run through a system call in a PHP app... even if you give it the full path.
Once you port your app to a correctly configured unix based web server it will work without having to mess about copying files.
Life is too short to figure out MSFT's quirks but if someone does figure it out I'd be happy to know!

Resources