473,763 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6433
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****@discuss ions.microsoft. com> wrote in message
news:B5******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. com> wrote in message
news:B5******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. com> wrote in message
news:B5******** *************** ***********@mic rosoft.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.DllNotFo undError.

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****@discuss ions.microsoft. com> wrote in message
news:B5******** *************** ***********@mic rosoft.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
2738
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 differentiate batch files between the two prompts? Also, where might I find information on the differences between the 2 prompts? Thanks, Herb
9
8848
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 "c:\inetpub\wwwroot\logasp\getdr.bat > c:\tstlog.txt" %> the batch file is as follows:
9
10818
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
6110
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 can't get the environmental variables to stick because all of Pythons' system start/open functions split off into their own little subshells, therefore the .bat file doesn't affect the main shell. How can I use the .bat file to set environmental...
18
6779
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 following in a batch file at the root of the drive: @path=%PATH%;%CD%Python24;%CD%Python24\libs;%CD%Python24\Scripts;%CD%Python24\Lib\site-packages;%CD%Python24\DLLs @set pythonpath = %CD%Python24
6
2125
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 them. Each data set that I generate, I put into an separate Access file which I eventually move to a server location that the particular client and I share access to.
0
2235
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 when ever some jobs will run on As400 to populate some files the program will be called to execute the batch files which will run the sql jobs to populate sql tables. This process working fine. But now we have installed SQL 2005 and trying to move ....
5
8204
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 createdb command using the following command from another batch file "createdb -U dbname username"
3
5171
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 all my executables(here it is .bat) so that they can be run at the time of installation. Thanks in advance!!!
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.