473,378 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Running Batch files from Installer to set Environmental variables

Hi

I'm using Visual Studio Installer to make my installer, and have not as yet
figured out a straightforward way to use it to set environmental variables.
Amongst the various things I tried, I'm thinking the following might help. I
would appreciate if someone could comment on this idea and possibly suggest a
better one:

The environement variable in question is 'Path' in the HKCU registry
folder's Environment key. I want to add some new values to it, which I want
the installer to remove upon uninstallation.

-----------------
GIVEN
-----------------
1. Using Setx, the new value can be appended to Path

2. What I would then need is to save the already exsisting path value in a
dummy key:
setx TempKey "%Path%"

3. Next, the new value is appened to path:
setx Path "%Path% theValueString"

4. On uninstallation, path can be restored by overwriting with the value
present in TempKey and the temporary key itself can be discarded.

----------------------------
REQUIRED:
----------------------------
Given the above, I'm guessing I would need to make two batch files, one for
installation and one for the uninstallation, and then somehow use the custom
actions editor to run these two batch files at the right time.

----------------------------
POSSIBLE BOTTLENECK:
----------------------------
I have never worked with batch files (though they don't seem overly
complicated), and I have yet to figure out how to use the custom actions
feature for vsi.

----------------------------
DILEMMA:
----------------------------
a) I haven't yet tried out this solution, so I don't absolutely know if it's
attainable.
b) Does there exsist a cleaner way to achieving the same?

Any help would be great.

Thanks a lot!
Jan 12 '06 #1
4 6403
Well, it's this doesn't exactly address your question, but......

I *despise* any program whose installer adds folders to my PATH evar.
Create a shortcut in the start menu with properly set "Target" & "Start in"
fields. If still need something in the PATH, you probably should reconsider
the design of your application rather than screwing with your user's
configuration.
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Shiraz" <Sh****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi

I'm using Visual Studio Installer to make my installer, and have not as yet figured out a straightforward way to use it to set environmental variables. Amongst the various things I tried, I'm thinking the following might help. I would appreciate if someone could comment on this idea and possibly suggest a better one:

The environement variable in question is 'Path' in the HKCU registry
folder's Environment key. I want to add some new values to it, which I want the installer to remove upon uninstallation.

-----------------
GIVEN
-----------------
1. Using Setx, the new value can be appended to Path

2. What I would then need is to save the already exsisting path value in a
dummy key:
setx TempKey "%Path%"

3. Next, the new value is appened to path:
setx Path "%Path% theValueString"

4. On uninstallation, path can be restored by overwriting with the value
present in TempKey and the temporary key itself can be discarded.

----------------------------
REQUIRED:
----------------------------
Given the above, I'm guessing I would need to make two batch files, one for installation and one for the uninstallation, and then somehow use the custom actions editor to run these two batch files at the right time.

----------------------------
POSSIBLE BOTTLENECK:
----------------------------
I have never worked with batch files (though they don't seem overly
complicated), and I have yet to figure out how to use the custom actions
feature for vsi.

----------------------------
DILEMMA:
----------------------------
a) I haven't yet tried out this solution, so I don't absolutely know if it's attainable.
b) Does there exsist a cleaner way to achieving the same?

Any help would be great.

Thanks a lot!

Jan 12 '06 #2
I dont know the overall design/reason of what you are trying to achieve, but
you can take advantage of the fact that Windows processes inherit the env
variables of the parent process... For example, if you change the PATH
variable from within your app, you are not really modifying it machine-wide,
only withing your process space. Then if you need to start a child process
that depends on the modified path setting, just make sure you start the
process as a child of your current process (which has the changed
environment variable)...

If this does not exactly fit what you need then tell us a little more about
what you are trying to do... It looks like you are writing an installer or
a program launcher of some sort. Like James, I hate programs that modify
the path globally, but it might not be necessary in this case...
"Shiraz" <Sh****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi

I'm using Visual Studio Installer to make my installer, and have not as
yet
figured out a straightforward way to use it to set environmental
variables.
Amongst the various things I tried, I'm thinking the following might help.
I
would appreciate if someone could comment on this idea and possibly
suggest a
better one:

The environement variable in question is 'Path' in the HKCU registry
folder's Environment key. I want to add some new values to it, which I
want
the installer to remove upon uninstallation.

-----------------
GIVEN
-----------------
1. Using Setx, the new value can be appended to Path

2. What I would then need is to save the already exsisting path value in a
dummy key:
setx TempKey "%Path%"

3. Next, the new value is appened to path:
setx Path "%Path% theValueString"

4. On uninstallation, path can be restored by overwriting with the value
present in TempKey and the temporary key itself can be discarded.

----------------------------
REQUIRED:
----------------------------
Given the above, I'm guessing I would need to make two batch files, one
for
installation and one for the uninstallation, and then somehow use the
custom
actions editor to run these two batch files at the right time.

----------------------------
POSSIBLE BOTTLENECK:
----------------------------
I have never worked with batch files (though they don't seem overly
complicated), and I have yet to figure out how to use the custom actions
feature for vsi.

----------------------------
DILEMMA:
----------------------------
a) I haven't yet tried out this solution, so I don't absolutely know if
it's
attainable.
b) Does there exsist a cleaner way to achieving the same?

Any help would be great.

Thanks a lot!

Jan 12 '06 #3
Thanks for your reponse. This application uses some dlls imported from C,
which are referenced in the source code. I'm guessing that is why there has
to be a reference to them in the path environment variable. Personally, I
wouldn't like to mess around with the registry either, but the application
doesn't run without these settings in the environment variables.

The reason why I'm not 'entirely sure' if it's because of the dlls that I
have to change the path is that this application has been developed primarily
by other developers. While setting up the environment on my machine though, I
had to make these changes in the env variable setting in order to work on the
application and at that time, I had assumed this to be the reason for making
these changes.

That's why I wanted my installer to append the dlls folder location to the
Path variable during installation and to remove these links after the
application uninstalls.


"Gabriel MagaƱa" wrote:
I dont know the overall design/reason of what you are trying to achieve, but
you can take advantage of the fact that Windows processes inherit the env
variables of the parent process... For example, if you change the PATH
variable from within your app, you are not really modifying it machine-wide,
only withing your process space. Then if you need to start a child process
that depends on the modified path setting, just make sure you start the
process as a child of your current process (which has the changed
environment variable)...

If this does not exactly fit what you need then tell us a little more about
what you are trying to do... It looks like you are writing an installer or
a program launcher of some sort. Like James, I hate programs that modify
the path globally, but it might not be necessary in this case...
"Shiraz" <Sh****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi

I'm using Visual Studio Installer to make my installer, and have not as
yet
figured out a straightforward way to use it to set environmental
variables.
Amongst the various things I tried, I'm thinking the following might help.
I
would appreciate if someone could comment on this idea and possibly
suggest a
better one:

The environement variable in question is 'Path' in the HKCU registry
folder's Environment key. I want to add some new values to it, which I
want
the installer to remove upon uninstallation.

-----------------
GIVEN
-----------------
1. Using Setx, the new value can be appended to Path

2. What I would then need is to save the already exsisting path value in a
dummy key:
setx TempKey "%Path%"

3. Next, the new value is appened to path:
setx Path "%Path% theValueString"

4. On uninstallation, path can be restored by overwriting with the value
present in TempKey and the temporary key itself can be discarded.

----------------------------
REQUIRED:
----------------------------
Given the above, I'm guessing I would need to make two batch files, one
for
installation and one for the uninstallation, and then somehow use the
custom
actions editor to run these two batch files at the right time.

----------------------------
POSSIBLE BOTTLENECK:
----------------------------
I have never worked with batch files (though they don't seem overly
complicated), and I have yet to figure out how to use the custom actions
feature for vsi.

----------------------------
DILEMMA:
----------------------------
a) I haven't yet tried out this solution, so I don't absolutely know if
it's
attainable.
b) Does there exsist a cleaner way to achieving the same?

Any help would be great.

Thanks a lot!


Jan 13 '06 #4
Alright, I think I have a better perception of assemblies and environment
variables now. Perhaps I could re-formulate my question better.

My application uses dlls made in c++/c, which have been wrapped for using in
C#. Initially, we had set the environment variables manually on our machines
to point to the location of these dlls. As expected, that worked without any
problem, though in retrospect, this approach could perhaps have been avoided.

Configuration files seem to be a better way for locating assemblies. Since
the dlls in question were not strongly types, I modified the <probing> tag of
the app.config file instead of the <codeBase> tag. I assumed the application
base folder to be the one where my application executable is located, and
subsequently had my installer place all the folders containing the different
dlls into this directory, so that they may be accessed as subfolders by the
probing tag.

All seemed well so far. One of those folders had the dll in question.
Installing and running the application however, made the application raise an
exception when this dlls was needed, a System.DllNotFoundError.

Thanks to a software one of my colleagues gave me, I was able to monitor the
files that were being accessed by all processes on my computer. On studying
the log, it appeared that my application was searching in all paths, except
for the one specified in the probing tag's privatePath attribute. It is
correctly defined; I have checked up the syntax and examples, so that's not
the reason for the problem. It seems like the application is not able to pick
up this information from the application configuration file, so it does not
look into the concerned subfolder and therefore, raises the given exception.

As a test, I physically copied this dll from the subfolder into the
application folder, and yes, this time the exception was not raised.

I'm not sure where the problem is now. Could it be the config file? Or since
this wrapped dll needs to be invoked by another one, somehow that's not
working (though it does placed in the application folder).

I would appreciate if you could perhaps give me some sort of feedback
regarding this

Thanks a lot!

"Gabriel MagaƱa" wrote:
I dont know the overall design/reason of what you are trying to achieve, but
you can take advantage of the fact that Windows processes inherit the env
variables of the parent process... For example, if you change the PATH
variable from within your app, you are not really modifying it machine-wide,
only withing your process space. Then if you need to start a child process
that depends on the modified path setting, just make sure you start the
process as a child of your current process (which has the changed
environment variable)...

If this does not exactly fit what you need then tell us a little more about
what you are trying to do... It looks like you are writing an installer or
a program launcher of some sort. Like James, I hate programs that modify
the path globally, but it might not be necessary in this case...
"Shiraz" <Sh****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi

I'm using Visual Studio Installer to make my installer, and have not as
yet
figured out a straightforward way to use it to set environmental
variables.
Amongst the various things I tried, I'm thinking the following might help.
I
would appreciate if someone could comment on this idea and possibly
suggest a
better one:

The environement variable in question is 'Path' in the HKCU registry
folder's Environment key. I want to add some new values to it, which I
want
the installer to remove upon uninstallation.

-----------------
GIVEN
-----------------
1. Using Setx, the new value can be appended to Path

2. What I would then need is to save the already exsisting path value in a
dummy key:
setx TempKey "%Path%"

3. Next, the new value is appened to path:
setx Path "%Path% theValueString"

4. On uninstallation, path can be restored by overwriting with the value
present in TempKey and the temporary key itself can be discarded.

----------------------------
REQUIRED:
----------------------------
Given the above, I'm guessing I would need to make two batch files, one
for
installation and one for the uninstallation, and then somehow use the
custom
actions editor to run these two batch files at the right time.

----------------------------
POSSIBLE BOTTLENECK:
----------------------------
I have never worked with batch files (though they don't seem overly
complicated), and I have yet to figure out how to use the custom actions
feature for vsi.

----------------------------
DILEMMA:
----------------------------
a) I haven't yet tried out this solution, so I don't absolutely know if
it's
attainable.
b) Does there exsist a cleaner way to achieving the same?

Any help would be great.

Thanks a lot!


Jan 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Herb Stevenson | last post by:
Hello all. I need to set up a batch file to work w/ the Visual Studio.NET 2003 command prompt. However, when I run the batch file it uses the standard command prompt. Is there a way to...
9
by: Doug at SAU | last post by:
I need to run a batch file on a remote machine from an ASP page. I dummied up a test ASP page as follows: <% Set WshShell = Server.CreateObject("Wscript.Shell") wshshell.run...
9
by: Sathyaish | last post by:
In which physical file are the python environmental variables located? I know I can access them using the: os.environ.get('PYTHONSTARTUP') or os.environ.get('PYTHONPATH')
9
by: Jeff Groves | last post by:
I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I...
18
by: cjl | last post by:
Hey: I am trying to run python from a usb drive under windows xp. I installed python "for this user" on to a machine, then copied the entire Python24 directory to the usb drive. I have the...
6
by: Mat N | last post by:
Hello access friends, (Originally posted on access.formsprogramming which I think was the wrong place) I'm precalculating a bunch of data for my clients as per a profile I have for each of...
0
by: sunrt | last post by:
We have an As400 system that has program which executes batch files which resides on the SQL server 7.0 computer . Those batch files run SQL server jobs using isql. The whole idea about this is...
5
by: anand4nk | last post by:
Hi, I am installing postgreSQL 8.2 using batch files in windows xp machine. I am installing postgres using postgresql-8.2.msi installer. Installation was successful. When i tried to run...
3
by: Mohit | last post by:
Hi All, I have some batch files which needs to be executed when installer is running. How can I achieve this functionality using .Net MSI installers. I didn't found any option where I can include...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.