Welcome Guest! To enable all features please Register.

Notification

Icon
Error

New Topic Post Reply
Find current directory of set up file while installing through C# 3.5 Setup Project
Soan
#1 Posted : Wednesday, July 14, 2010 6:14:34 PM(UTC)
Rank: Administration
Soan

Joined: 1/9/2010(UTC)
Posts: 393
Points: 1,158
Location: India
I am currently creating a Visual Studio 2008 Setup Project using C#. I
am successfully running some custom actions and need to add another
based on the current directory the application is running in. So far I
have tried:

Directory.GetCurrentDirectory()
Environment.CurrentDirectory

Nothing in the Environment.GetEnvironmentVariables Dictionary helps me
either.

No matter how I try to get the current directory, it always ends up
being c:\windows\system32.

This is the case no matter where I run this
application from.

If I run the application from c:\TEMP I expect the current directory to
be c:\TEMP.

Can anyone shed some light on this issue?
Sponsor

Soan
#2 Posted : Wednesday, July 14, 2010 9:18:45 PM(UTC)
Rank: Administration
Soan

Joined: 1/9/2010(UTC)
Posts: 393
Points: 1,158
Location: India
SOLUTION:

There is an environment variable called SOURCEDIR which stores the path of the directory from which the msi or the setup.exe is running or has been launched.

You should follow the following steps to set and get the value of this variable:

1) Go to your Visual Studio Set Up project and right click. Select 'View'->'Custom Actions'.

2) On 'Custom actions' screen, you would see the various steps listed as 'Install', 'Commit', 'Rollback', 'Uninstall' etc. Click the '+' sign beside the 'Install' action and you would see an entry like 'Primary output from YOUR_SERVICE_NAME (Active)'. Right-click on this entry and select 'Properties window'.

3) Now add the following entry in 'CustomActionData' field:
/sourcedir="[SOURCEDIR]\"

If there are other entries also mentioned in your 'CustomActionData' field, then do not forget to place a space(blank) between this and other entries.

4) Now you can access this value using the following code in your custome action code:
string sourceDirectory = this.Context.Parameters["sourcedir"];

That's it. You are Done!!

Note:
If you looking to add a custom action screen in your visual studio set up(installer) project, the you can read the steps here.
Guest
#4 Posted : Sunday, February 20, 2011 1:50:50 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
Thanks very much. Your solution is clear and very helpful.
Soan
#5 Posted : Sunday, February 20, 2011 10:46:50 PM(UTC)
Rank: Administration
Soan

Joined: 1/9/2010(UTC)
Posts: 393
Points: 1,158
Location: India
Thanks...I am glad that it worked for you.
Guest
#6 Posted : Wednesday, November 09, 2011 7:40:25 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
it will not work if you running installer from network
Guest
#3 Posted : Monday, January 23, 2012 8:26:49 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
Hi,

Great solution. Thanks. Your solution worked for me.




Soan;273 wrote:
SOLUTION:

There is an environment variable called SOURCEDIR which stores the path of the directory from which the msi or the setup.exe is running or has been launched.

You should follow the following steps to set and get the value of this variable:

1) Go to your Visual Studio Set Up project and right click. Select 'View'->'Custom Actions'.

2) On 'Custom actions' screen, you would see the various steps listed as 'Install', 'Commit', 'Rollback', 'Uninstall' etc. Click the '+' sign beside the 'Install' action and you would see an entry like 'Primary output from YOUR_SERVICE_NAME (Active)'. Right-click on this entry and select 'Properties window'.

3) Now add the following entry in 'CustomActionData' field:
/sourcedir="[SOURCEDIR]\"

If there are other entries also mentioned in your 'CustomActionData' field, then do not forget to place a space(blank) between this and other entries.

4) Now you can access this value using the following code in your custome action code:
string sourceDirectory = this.Context.Parameters["sourcedir"];

That's it. You are Done!!

Note:
If you looking to add a custom action screen in your visual studio set up(installer) project, the you can read the steps here.

Guest
#7 Posted : Monday, January 30, 2012 4:06:38 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
Will it work if i try to install from a CD or USB.
SourceDir parameter is unable to retrieve the path in that case.
Can anybody guide me on this.
Guest
#8 Posted : Thursday, April 05, 2012 1:15:33 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
thanks works fine...........
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.