473,831 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1228
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************ ****@discussion s.microsoft.com > wrote
in message news:ED******** *************** ***********@mic rosoft.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.Set EnvironmentVari lable.

In Visual Studio 2002-3 :
P/Invoke to SetEnvironmentV ariable

[DllImport("Kern el32.dll")]
public static extern int SetEnvironmentV ariable( 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.goo glegroups.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.Set EnvironmentVari lable.

In Visual Studio 2002-3 :
P/Invoke to SetEnvironmentV ariable

[DllImport("Kern el32.dll")]
public static extern int SetEnvironmentV ariable( 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
1580
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 things can't be changed without dropping the original object (e.g Tables) and
1
4705
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 based on a server name passed in, and whether ornot the PDA is in the active sync cradle. IE. If the PDA is in the cradle, use localhost. If the PDA isn'tin the cradle, then allow connection over wi-fi to any validwebservice by changing the computer...
6
4833
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 local machine using ServiceInstaller.StartType, but I cannot seem to find a way to specify the name of a remote machine to perform this action upon. I know that ServiceController will allow me to talk to a remote system and start/stop services,...
6
4299
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 the ProjectInstaller section seemed to have no effect on the event log. I finally found that in *.Designer.vb there is an InitializeComponent Sub that was still setting Me.Servicename = "Service1". However, there were cautions not to edit it in...
1
920
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 computer started and then stopped," error. I commented almost all of the code in my OnStart subroutine yet the error persists. Any ideas why this might be?
0
9642
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
10494
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10534
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7748
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
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4416
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
2
3963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
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.