470,815 Members | 1,293 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Changing to service

Gav
Hi all,

I have written a program which seriously depends on an environment variable.
When I set the env var for the system it caused me major problems unrelated
to what I was trying to achieve. So in order to get around this I just used
a simple script which would set the variable using the 'set' command and
then call my program. This worked and only held the env var for that script
session so once my program was finished it was gone and therefore not
affecting anything else...

I now want to convert this program to a windows service, all was going well
until I remembered this fine point. Is there a way I can programatically set
an environment variable just for the use of the service?

Regards
Gavin
May 9 '06 #1
4 1121
You can pass data to your windows service when it starts in Main function.

"Gav" wrote:
Hi all,

I have written a program which seriously depends on an environment variable.
When I set the env var for the system it caused me major problems unrelated
to what I was trying to achieve. So in order to get around this I just used
a simple script which would set the variable using the 'set' command and
then call my program. This worked and only held the env var for that script
session so once my program was finished it was gone and therefore not
affecting anything else...

I now want to convert this program to a windows service, all was going well
until I remembered this fine point. Is there a way I can programatically set
an environment variable just for the use of the service?

Regards
Gavin

May 10 '06 #2
Gav
Thanks for the reply however this will not get me what I'm after, I'm not
using the variable directly in my program.

I'm using an ODBC connection (third party ODBC driver) in my program when I
setup the system ODBC connection going through the control panel I cannot
type in the full path to the data files, it doens't allow for enough
characters. The workaround for this (provided by the company who makes the
driver) is to only put a '.' (just the full stop) in the path of the ODBC
connection and set an environment variable, it will then automatically use
that variable as the path. As I said before if I set this for the system it
causes me problems (the ODBC driver is just an add on to a set of other
programs, if the env var is set the programs will also use this as the path,
which is fine unless you have more that one instance of the program using
different data paths - you set the env var for the system and they ALL start
using the same data path, big problem).

Any other suggestions? anyone?

be much appreciated, Gav

"Altaf Al-Amin Najwani" <Al****************@discussions.microsoft.com> wrote
in message news:ED**********************************@microsof t.com...
You can pass data to your windows service when it starts in Main function.

"Gav" wrote:
Hi all,

I have written a program which seriously depends on an environment
variable.
When I set the env var for the system it caused me major problems
unrelated
to what I was trying to achieve. So in order to get around this I just
used
a simple script which would set the variable using the 'set' command and
then call my program. This worked and only held the env var for that
script
session so once my program was finished it was gone and therefore not
affecting anything else...

I now want to convert this program to a windows service, all was going
well
until I remembered this fine point. Is there a way I can programatically
set
an environment variable just for the use of the service?

Regards
Gavin

May 10 '06 #3
V
Hi Gav,

There is a managed way to do it with .Net 2.0 and an unmanaged way to
do it through .Net 1.1 (both are below)

In Visual Studio 2005 Whidbey :
Environment.SetEnvironmentVarilable.

In Visual Studio 2002-3 :
P/Invoke to SetEnvironmentVariable

[DllImport("Kernel32.dll")]
public static extern int SetEnvironmentVariable( string name , string
value ) ;

In 1.1, you can always use WMI (but that is an overkill for only this
little thing).

Regards,
Vaibhav

May 10 '06 #4
Gav
Sorry I forgot to thanks you, this worked great, thank you very much.

Regards
Gav

"V" <va*************@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Hi Gav,

There is a managed way to do it with .Net 2.0 and an unmanaged way to
do it through .Net 1.1 (both are below)

In Visual Studio 2005 Whidbey :
Environment.SetEnvironmentVarilable.

In Visual Studio 2002-3 :
P/Invoke to SetEnvironmentVariable

[DllImport("Kernel32.dll")]
public static extern int SetEnvironmentVariable( string name , string
value ) ;

In 1.1, you can always use WMI (but that is an overkill for only this
little thing).

Regards,
Vaibhav

Jun 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul Reddin | last post: by
1 post views Thread by Nick via .NET 247 | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.