Launch an Application After Installing using Visual Studio 2010 Setup Project - c#

I followed this link http://www.codeproject.com/Articles/19560/Launching-Your-Application-After-Install-using-Vis
& it has given a good guid to my problem. But in my scenario, I also have a folder with the exe. after installation my exe starts running. but it is not properly linked with the conetent in my folder which is also in same location. How can I link that folder to my exe.
The problem is I added both folder & its contents to Application folder directory given by the setup project wizard. But I can add only the exe to the commit folder as I want my exe to run after after clicking on first initial exe. How ever after first installation both my exe & folder creates & when I click on exe manually it works. But in installation it only copies exe & folder & start running copied exe but could nt find the folder properly.

The working directory of your exe will be different when launched as a commit action.
You either need to change the working directory in your exe or build an absolute path to the folder you are trying to find.
You could pass the application path from the installer to your exe by setting CustomActionData to '[TARGETDIR]\', or extract it from the exe path at runtime, e.g.:
string exepath = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
string abspath = Path.Combine(exepath, "yoursubfolder");

I think this is what you want
http://blogs.msdn.com/b/astebner/archive/2006/08/12/696833.aspx

Related

How to set the current\working directory of a WPF application to the installation path

In my C# WPF application I need to access some configuration files via a 3rd party library. This library requires to have the configuration file located in the same folder as the executable of my application. So i have no chance to change this behaviour.
While running my application in Visual Studio 2013 it works fine. I can access the configuration file since I have just copied it to the relevant folder.
But if I install my application an run it it cant locate my configuration files because it tries to find it under: Windows\system32.
No my approach is to make it happen that my application looks for the configuration file in the applications install folder.
How can I do that? How can I set the current\working directory of my application to a specific (installation) path in Visual Studio 2013?
try this
string path = AppDomain.CurrentDomain.BaseDirectory.ToString();
This will give path like "c:\\program...\\installdir\\" where your .exe is located.

Include Chromedriver In Your Application

I have developed several programs with selenium chromedriver. Getting the correct path to chromedriver on end users computer is sometimes an issue, how can I include the chromedriver exe in the program file, that it should automatically deploy and able to be used with messing around with the path to the driver file.
First you will need to add the exe to your project. Right click add existing item and navigate to the exe.
secondly you need right click on the exe in your project and get to the properties. set the exe to copy to output directory -> copy if newer or copy always.
this should get the file publishing with your installation. this all depends on how you are deploying, but with clickOnce or web deploy this will work. Ultimately setting the copy to output directory will get the exe into your bin folder on build.
If you need the location of the exe you should be able to use something like System.Reflection.Assembly.GetExecutingAssembly().Location to get the location of where the execution is taking place.

How to deploy properly?

I am trying to make a software that will execute .exe installation files of some other software using c# vs2013. I have used
Process.Start()
I added the files to be extracted in my resources and then I gave the resources path of those files
Process.Start("C:\\Users\\Farjad\\Documents\\Visual Studio 2013\\Projects\\RoyalComputerProject\\RoyalComputerProject\\Resources\\wrar501.exe");
It works fine on my computer However if I try to run it on some other computer it gives me an error saying that specified files are missing. I think It is because of the path I am passing to Process.Start() is of my computer. How should I correct this? What path should I pass? or How should I deploy it?
Ship your app along with dlls and this exe file in a package so when you extract it on another computer, you will get something like
C:/.../Downloads/YourAppName/
- MyApp.exe
- SomeLibrary.dll
- Config.xml
- MyOtherApp.exe
And now, you need to get a correct path of the running assembly which you could do using
string path;
path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
I found this code on MSDN.
For testing purposes, put that exe in bin/Debug or bin/Release folder, depending on how you build your app (debug vs release mode).

Defining where files are installed

I am trying to deploy a .NET application as a ClickOnce Application, but I am having trouble defining where the application is installed. I need to know this because I have to include support files. I have already added the support files as "existing items". I had assumed that the program would install in Program Files, but it does not exist there. Instead, there is just a shortcut on the desktop. Can someone explain how/where the install path is defined using VS2012?
One solution I found was to use some of the Application class properties to determine where ClicOnce installed an instance of my program. But be aware that some those are deleted on uninstall of the program.
// To get the path for the executable file that started the application, not including the executable name.
PATH_RESOURCES = Application.StartupPath ;
For persistant data I created references to specific paths like :
PATH_USERDATA = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + #"\myAppName\";
if (!System.IO.Directory.Exists((string)PATH_USERDATA))
{
System.IO.Directory.CreateDirectory((string)PATH_USERDATA);
}
PATH_REPORTS = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + #"\myAppName\";
if (!System.IO.Directory.Exists((string)PATH_REPORTS ))
{
System.IO.Directory.CreateDirectory((string)PATH_REPORTS );
}
Clickonce application gets installed under the user profile, not the Program Files path.
On windows Vista and Windows 7, clickonce application path will be somewhere in c:\users\username\AppData\Local\Apps\2.0\
On Windows XP, clickonce application path will be somewhere in c:\document and Settings\username\LocalSettings\Apps\2.0\
Note that Clickonce application path is different everytime upon installation, I found the best way is to make your app to write its own app path to the reg key, this way you know exactly where the app path is by looking at the reg.
So as user831062 pointed out, ClickOnce apps get installed under the user profile, not the Program Files path. Because of this, the install directory is different on every machine and almost impossible to access directly.
The part that I was hung-up on, was where are the files that I have included in the project located, and more importantly - how do I access them?
Well, as mentioned IN THIS LINK, if you mark the file as a "data file", under:
Project Properties > Publish > Application Files > Publish Status
you'll be able to access them using something like:
textBox = File.ReadAllLines(ApplicationDeployment.CurrentDeployment.DataDirectory + #"\myFile.txt")).ToList();
If you don't mark it as a "data file", but rather as just an "Include (Auto)", it will just be located in the install directory itself, which can be accessed by calling the file directly using something like:
textBox = File.ReadAllLines(#"myFile.txt")).ToList();
Anyway, took me an hour or so to find this, so hopefully it helps someone else out.
If you have added your files to your project, set the property for "build action" to "content" and set "copy to output directory" to "copy always". This way, the files will be included in your deployment. When the application is run, retrieve the location of the assembly and look in the same relative folder as where they were included in the project. For example, if they are in the top folder of the build output directory (/bin/debug/ or /bin/release/), they will be included in the same folder as the executable, which you can discover using this:
System.Reflection.Assembly.GetExecutingAssembly().Location

Embedding a PDF as a resource in WPF application

I want to embed a PDF file (which is basically have Product details, Release notes) and wants to open that file from menu bar. What would be the best approach. I need to use this file in installer also. So i'm looking for an approach in which file will be moved to BIN on compilation and from there installer can access that file.
IDEAS ...
Add the file to the project the builds the EXE (use Add existing file in visual studio). Then right click on the file in visual studio, go to properties, and verify that the build action is "Content" and the copy to output directory is "Always" or "If newer" (whichever suits you).
Then this file will always be copied to the same directory where the EXE resides and your application will be able to access it because it's always in the application's directory.
If the installer just takes the BIN directory then it will also be able to access it because the file will reside in the BIN directory.
Have fun!
Finally i did it in following way:
a. We've a folder which contains notes.pdf (used by installshield).
b. Created a pre build command to copy the pdf file from installshield folder to output directory.
c. use process.start("notes.pdf"); to open the file. As it would look in bin directory first for pdf file and we've already copied it there.
It worked for both Installer version and running application from code.

Categories