472,958 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1201
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Reddin | last post by:
Hi, Can anyone tell me if the changing of DB Objects in Stinger has been improved ? e.g Changing optionality, renaming etc..... I spend an awful lot of time changing objects because many...
1
by: Nick via .NET 247 | last post by:
I have a similar problem trying to use web services with awindows form application. I currently use a static web referencein my project. What I am trying to do is to programaticallychange the url...
6
by: NetworkElf | last post by:
I am trying to write a little utility and it needs to check the startup type of a given service on a remote machine and, if it is disabled, set it to manual. I have found out how to do this on the...
6
by: kdd21 | last post by:
Hi, Just got my first service written in VB-- works fine but the event log was showing the start stop entries as Service1 so I went in to change it, but changing the servicename properties in...
1
by: David | last post by:
"David" <davidd31415@yoowhoo.comwrote in message news:3dmdnQe_FOWLdWHanZ2dnUVZ_veinZ2d@comcast.com... No luck yet. I created a service from scratch but keep getting the "service on local...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.