473,372 Members | 1,084 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,372 software developers and data experts.

Append to PATH Environment Variable

I have an application that uses PInvoke to call into native DLLs. My
DLLimport attribute only has the name of the DLL that I need to import (i.e.
I leave it up to the OS to search the PATH for the DLL.) This all works
great when the user's PATH variable is setup correctly.

Unfortunately, there are times when the user's PATH is too full or whatever
to have the correct search path for my application.

What I was wondering is if there is a way to set the PATH variable to have
the correct search directory after my application starts up (yet before any
call to DLLImport). This way I can guarantee that the search is correct for
the running instace of my application.

I tried this at the beginning of my application to no avail:

System.Diagnostics.ProcessStartInfo info =
System.Diagnostics.Process.GetCurrentProcess().Sta rtInfo;

string origpath = info.EnvironmentVariables["path"];
string newpath = "C:\\mypath;" + origpath;
info.EnvironmentVariables["path"] = newpath;

****

I know I could create a separate executable that sets the Environment
variables and calls StartProcess to launch my application. I was hoping that
my application could set this path infromation without requiring another
executable to launch my application.

Thanks!
Nov 16 '05 #1
1 9612
Chris,

You could always call the SetEnvironmentVariable function through the
P/Invoke layer.

Also, if you can wait for .NET 2.0, you are able to take a function
pointer and assign it to a delegate to call. This will allow you to load
the dll (LoadLibrary, LoadLibraryEx), get the procedure address
(GetProcAddress), and then get a delegate that you can call which will call
the function at that address.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris B" <Ch****@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
I have an application that uses PInvoke to call into native DLLs. My
DLLimport attribute only has the name of the DLL that I need to import
(i.e.
I leave it up to the OS to search the PATH for the DLL.) This all works
great when the user's PATH variable is setup correctly.

Unfortunately, there are times when the user's PATH is too full or
whatever
to have the correct search path for my application.

What I was wondering is if there is a way to set the PATH variable to have
the correct search directory after my application starts up (yet before
any
call to DLLImport). This way I can guarantee that the search is correct
for
the running instace of my application.

I tried this at the beginning of my application to no avail:

System.Diagnostics.ProcessStartInfo info =
System.Diagnostics.Process.GetCurrentProcess().Sta rtInfo;

string origpath = info.EnvironmentVariables["path"];
string newpath = "C:\\mypath;" + origpath;
info.EnvironmentVariables["path"] = newpath;

****

I know I could create a separate executable that sets the Environment
variables and calls StartProcess to launch my application. I was hoping
that
my application could set this path infromation without requiring another
executable to launch my application.

Thanks!

Nov 16 '05 #2

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

Similar topics

3
by: Jeff Wagner | last post by:
Is it possible to append a new Path to some file permanently? It seems like a sys.path.append('/my/new/path') statement is temporary. In other words, where and in what file on a Win32 box or...
1
by: jwpioneer | last post by:
I have a need within an application to modify the path environment variable, as I need to find specific directories and remove them. I use the following code to do this: RegistryKey rkey = ...
1
by: Bonj | last post by:
Hi My application installs a front-end GUI, which runs code when buttons are clicked. It also installs a command-line utility, that is a console application. They are both installed to the...
6
by: Garfield | last post by:
We have written a small function to append a couple of paths to the path environmental variable. The code is: string PathValue = ""; string sAdd = ""; sAdd = ";" + <path1> + "Bin;" +...
10
by: mirandacascade | last post by:
O/S: Win2K Vsn of Python:2.4 Based on a search of other posts in this group, it appears as though os.environ is one way to obtain the PATH environment variable. My questions: 1) is it...
3
by: HMS Surprise | last post by:
Is sys.path setup differnently in jython vs python? I have environment variables pythonpath and jythonpath set to include C:\python22 but the initial printout indicates it is being ignored. Also...
3
by: Wolfgang Meister | last post by:
I would like to append text to a file which might exist or not. What is the easiest way to open or create it depending if it exists or not and to set it into an "append" text mode?
0
by: cnathaide | last post by:
Hi, I have written a simple command line application in C# and created the accompanying setup project in VS 2005. When the user installs the application on the his/her machine, I would like...
2
by: Blair | last post by:
Hello, I have a old enviromantal path in LIB file that, every time I compile gives a error message. It does not stop the compiler just gives a warning. This has become very annoying. I...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.