inno setup - batch change InstallDircation - batch-file

I am trying to run a batch file right before the installation begins,
Just after the user chooses the component he wants to install.
fortunately, I don't build it from basic, I have a ready iss file which depending on the component runs a batch file that you have created already.
In the batch file I trying to change the directory of the installer to specific one.
I tried to do so as I set INSTALLBINDIR and appfolder to my directory but it haven't work.
Do you know the variables I need to set so the installer will install where I want?
Edit:
I found out that I don't need to use a batch file.
To fixed a position to file you just need to put your Directory in the DestDir in [files]

You can't change the install directory directly from a sub script/program run from the installer.
You will need to set the WizardForm.DirEdit.Text in [Code] to the new value.
Alternatively, you can use a {code:...} constant for the DefaultDirName directive to get a suitable value to start with.

Related

How to specify in windows batch file to open spyder, change the working directory and run a script?

I have created a windows batch file to run a code which is located in a particular folder. However, I am running the batch file but it does not work. What I want it to do is:
Change working directory in Spyder (Spyder is already openned so I don't want it to open it first)
Run the script I want to execute
Basically, the script I am running is plotting a bunch of graphs and all the files needed to create this are located in the working directory.
#echo off
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe"
chdir /D "F:\optimisation"
"F:\optimisation\plot.py"
pause
The batch file runs fine without any errors, but nothing happens in Spyder e.g. it doesn't change the working directory and neither executes the code.
I'd suggest
#echo off
setlocal
chdir /D "F:\optimisation"
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe" "F:\optimisation\plot.py"
pause
That is, switch to the required directory, having set a local environment (this restores the original environment when the batch terminates).
Then run the spyder executable, providing it with the name of the file. It would be normal practice to use this structure to provide a significant filename to an executable (eg notepad fred,txt)
Since the current directory when spyder runs is f:\optimisation, it is probably not necessary to specify the entire path in spyder's argument.
Note this is all just speculation using normal practice. I have no experience of spyder- in fact, this is the first I've heard of it.

Command Line Installation with SCCM 2012

I have a few applications that I am trying to deploy with SCCM 2012 but the installations are failing through the application catalog. So what I have for the deployment type is a script installer. I have "cmd.exe" (Without quotations) in the Installation program field and "Installer.bat" in the installation start in field.
When I look at the ccmcache folder, all the contents over that application are there but the following error displays the Software Center:
0x8007010B(-217024629)
I have done some reading online and the "10B" is a common command line error for invalid directory. I have tested the batch file when hard coding a path but my question is, how can I edit the batch file or SCCM to pull from the CCMCache path where the files are downloaded to on the local client? Currently the Batch File is simply:
#echo off
ApplicationName.exe
Do I need to edit the file to cd into the CCMCache folder where the files are placed? How can I get the batch file to run the executable that is downloaded to the CCMCache folder?
Thank You!
You need to have the full path to the installation in your script
#echo Off
\\path to .exe
The way the command is written will not be able to find the .exe file. You need to add the full unc path to the .exe into your .cmd file. You should have your installation .exe and .cmd file in the same location on the distribution share
Recommended Solution:
Before starting, since you are only launching an exe with your batch file, I would recommend just using your ApplicationName.exe as your command line parameter in SCCM instead of using a batch. This will eliminate the need to engineer any further.
Modifying the existing solution to work:
If you do still want to use a batch file, keep a few things in mind. The syntax you are using to launch the batch file will not work. I would recommend just using the batch file name "installer.bat" as your command line. If you still want to preface the batch with the cmd.exe, you absolutely need to use the /c switch with it
cmd.exe /c installer.bat
If you don't use /c the console host will only open to a promopt and not execute your batch.
This is not an ideal solution though because using "cmd.exe /c" will set your working directory to the location of cmd.exe (ie "C:\windows\system32") and since your content is staged in ccmcache, you will need to specify its location within your batch. To do this, you would use %~dp0 variable which gives you the directory the current batch is running from. This means modifying your batch to read
#echo off
%~dp0ApplicationName.exe

Can't run program after set path as environment variable

I have set a new environment variable pointing to msbuild.exe folder.
C:\temp\Test>echo %DOT_NET4%
C:\Windows\Microsoft.NET\Framework\v4.0.30319
Now, if I start a new cmd and run "msbuild.exe", the programs runs ok, but after running this simple bat, the program is not found anymore:
"C:\Program Files\TortoiseSVN\bin\svn.exe" checkout %CHECKOUT% %PATH%
cd %PATH%
nuget restore OpenText.sln
msbuild.exe OpenText.sln
msbuild not recognized as an internal or external command.
Thanks in advance
I am seeing the same thing as Joey in his comment. Your use of CD %PATH% is a red flag that indicates a problem.
PATH is a critical environment variable that contains a delimited list of folder paths where important executables are located. The command processor uses that list to locate programs when an external command is issued without the full path to the command.
If PATH is set correctly, then your command CD %PATH% cannot work. But I suspect you have some script that defines PATH to a specific folder, perhaps where nuget is located. In this case, your CD %PATH% command works, but now cmd.exe has no idea where msbuild.exe is located.
Moral of the story - don't ever use PATH for your own purposes. Pick some other variable name that is not reserved.
First things first, where are you setting the msbuild path? To resolve your issues, please check if you have followed this process:
Open your system control panel, check for advanced system settings.
Click on Environment variables and edit PATH
Add a semicolon followed by the msbuild path.
Open a new command prompt and check if it is working or not.
Please note if you set msbuild in one command prompt, it will not be available in another command prompt.
Another issue which I see when I look at your logic is, you are trying to cd to %PATH% which should be avoided, you are either resetting the Environment variable path to a new path and trying to cd to it or you will land up file name longer issues, please use another variable instead.
In the bat which you are invoking, add a condition at the root level, such that if msbuild is not found, basing on %ERRORLEVEL%, try adding msbuild to path again at batch level, so that you build will proceed.

How do i combine a bat file with an MSI?

I have an MSI Installer that I created in WIX that i would like to be run from a .bat file, but I need it to be in one MSI file. How would i do that? for example i have a .bat file that does this
MD C:\TEMP\BATS
START /W msiexec /i Installer.msi /l*v C:\TEMP\BATS\INSTALLERLOG.txt
SLEEP 5
DEL C:\TEMP\INSTALLERLOG.txt
RD C:\TEMP
I want to create an .msi or .exe file that contains both the .bat file and the .msi file and will unpackage the two files and run the .bat file. Is this possible? I am doing it just to force Logging that will be displayed to the user through a custom action if the installer fails some how.
It sounds like you are caught by the technical details of the counterparts of your solution. Try to forget what you have for a moment and think of what you actually need.
As far as I can tell from your code snippet, the bat file creates a temporary directory, runs MSI package installation with verbose logging option, and then deletes the generated log file... Sounds a bit of no sense to me...
This is whatI would do in your case:
Get rid of that bat file
Ask yourself what its purpose is. If it is there to modify the target system, then revise this logic and move it to your MSI package following all the best practices you can find. If it has to to some service work, e.g. prepare parameters for the main MSI package, then consider authoring a bootstrapper.
You can try IExpress to generate a single EXE file. Another solution would be to use a self-extracting EXE archive which can launch a specific file when it finishes extracting.

How to run a ".bat" file during installation?

In a Setup project the executable files such as ".exe , .dll , .js , .vbs" are acceptable but there is no way to run a .bat file in a Custom Action.
The question is how to run the *.bat files during installation?
Well, after much searching and trial and error I have solved this. I'm not sure if this is the best way, but it works.
Here's the scenario: I have an application I would like to deploy via a Visual Studio Setup project. In addition to my application files, I would like to create a subdirectory in the target directory that contains a batch (.bat) file. I would like this file to run at the end of the installation process.
Here's what you do:
Create a setup project and configure as you normally would, including the subdirectory in which you'll place your batch file (you can just place it in the Application Folder directly if you don't want it in a subdirectory).
In the "File System" view (right-click on the project in Solution Explorer->View->File System), add the batch file you want to execute and cmd.exe (C:\Windows\System32\cmd.exe)
Open the "Custom Actions" view (right-click on the project in Solution Explorer->View->Custom Actions)
Right-click on "Commit" and choose "Add Custom Action"
Navigate to and select cmd.exe.
Open the properties panel for the newly created custom action.
Delete /Commit from the Arguments property.
Enter: /c "[TARGETDIR]subdirectoryname\batchfile.bat" in the Arguments property, where subdirectoryname should be replaced by the name of your subdirectory (if you put the batch file in a subdirectory like I did... if you didn't, the value should be /c "[TARGETDIR]batchfile.bat") and batchfile.bat should be the filename of your batch file.
That's it. The batch file will now be executed once the rest of the installation process is completed.
Here's an example for the sake of clarity:
My batch file: blah.bat
My subdirectory: mydir
The value of the Arguments for my custom action targeting cmd.exe would then be
/c "[TARGETDIR]mydir\blah.bat"
One other way to reach the same result is put a .vbs file in custom actions that runs the correspondent .bat file.
The following code is the "RunRegisterComponents.vbs" I put in setup application folder. Of course I put [TARGETDIR] as .vbs parameter in Visual Studio property window.
dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Read the "CustomActionData" property holding the install directory.
dim programDir
programDir= property("CustomActionData")
' Make the batch full file name and parameter
commandString = chr(34) & programDir & "RegisterComponents.bat" & chr(34) & " " & chr(34) &
programDir& chr(34)
' Set the current directory
WshShell.CurrentDirectory = programDir
' Run batch.
ret = WshShell.Run (commandString, 0, 0)
That is as I set my custom actions:
I hope this can help you!
Check this article (article is deprecated), even though it is in VB.NET it applies to C# as well. The most important part is (translated to C#) creating a new Class Library, and adding a new Installer Class with the following content: As stated in the article you can then create a new custom action with a reference to your just created project.
override void Commit(IDictionary savedState)
{
base.Commit(savedState);
System.Diagnostics.Process.Start("myApp.bat","your bat arguments");
}
Now we are adding batch file to your installer project. Create a setup project and configure as you normally would, including the subdirectory in which you'll place your batch file (you can just place it in the Application Folder directly if you don't want it in a subdirectory).
In the "File System" view (right-click on the project in Solution Explorer->View->File System), add the batch file you want to execute.
Build the installer project.
If you are trying to run a batch file that have relative paths during the installation process, that will fail for sure. That's because the batch file will take into account the directory where the installer is running, and not where the files were being installed. Use installer builders that copies batch files into temporary directory.

Resources