Get command arguments in Windows Service

  • Thread starter Thread starter Eric Chong
  • Start date Start date
E

Eric Chong

I created a Windows Service in C# that requires to get
passed command arguments like a Console App. I noticed
that there is an option "Start parameters" text box in
the property of a Windows Service in MMC. Is there any
way to get arguments using this option? If possible, what
framework method should I use to get an arguement?
Thanks in advance.

Eric
 
Hi Eric,

You may try the Environment.GetCommandLineArgs Method.
Here is a helpful link.
Did I answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
Thank you for your reply. However, your solution doesn't
work. I've already tried this. I think a Start parameter
of Windows Service doesn't pass any argument to
GetCommandLineArgs method.

Eric
 
Hi Eric,

Sorry for misunderstanding your quesiton.
Did you mean that you want to get the parameters in "Start parameters" text
box in
the property of a Windows Service in MMC in your services program?

If so, I think the args argument in the function
protected override void OnStart(string[] args)
is what you want.

Here is simple sample. You may have a check.
Windows Services: New Base Classes in .NET Make Writing a Windows Service
Easy
http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/default.aspx


Did I misunderstand your question?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
Thank you very much!!! It works.

Eric
-----Original Message-----
Hi Eric,

Sorry for misunderstanding your quesiton.
Did you mean that you want to get the parameters in "Start parameters" text
box in
the property of a Windows Service in MMC in your services program?

If so, I think the args argument in the function
protected override void OnStart(string[] args)
is what you want.

Here is simple sample. You may have a check.
Windows Services: New Base Classes in .NET Make Writing a Windows Service
Easy
http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/def ault.aspx


Did I misunderstand your question?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Eric Chong" <[email protected]>
Sender: "Eric Chong" <[email protected]>
References: <[email protected]>
Subject: RE: Get command arguments in Windows Service
Date: Mon, 8 Sep 2003 09:16:28 -0700
Lines: 56
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcN2JI7qoR2H+AzdR9ucVL9fs0/JAw==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:107680
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.general

Thank you for your reply. However, your solution doesn't
work. I've already tried this. I think a Start parameter
of Windows Service doesn't pass any argument to
GetCommandLineArgs method.

Eric

.
 
Hi Eric,

Cool!
I am glad that it works for you.
Cheers!


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Eric Chong" <[email protected]>
Sender: "Eric Chong" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: Get command arguments in Windows Service
Date: Tue, 9 Sep 2003 09:37:41 -0700
Lines: 120
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcN28K/Xk95AzBuTTU+pEbhRPyiRqQ==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:107813
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Thank you very much!!! It works.

Eric
-----Original Message-----
Hi Eric,

Sorry for misunderstanding your quesiton.
Did you mean that you want to get the parameters in "Start parameters" text
box in
the property of a Windows Service in MMC in your services program?

If so, I think the args argument in the function
protected override void OnStart(string[] args)
is what you want.

Here is simple sample. You may have a check.
Windows Services: New Base Classes in .NET Make Writing a Windows Service
Easy
http://msdn.microsoft.com/msdnmag/issues/01/12/NETServ/def ault.aspx


Did I misunderstand your question?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Eric Chong" <[email protected]>
Sender: "Eric Chong" <[email protected]>
References: <[email protected]>
Subject: RE: Get command arguments in Windows Service
Date: Mon, 8 Sep 2003 09:16:28 -0700
Lines: 56
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcN2JI7qoR2H+AzdR9ucVL9fs0/JAw==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:107680
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.general

Thank you for your reply. However, your solution doesn't
work. I've already tried this. I think a Start parameter
of Windows Service doesn't pass any argument to
GetCommandLineArgs method.

Eric

-----Original Message-----
Hi Eric,

You may try the Environment.GetCommandLineArgs Method.
Here is a helpful link.
Did I answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and
confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Eric Chong" <[email protected]>
Sender: "Eric Chong" <[email protected]>
Subject: Get command arguments in Windows Service
Date: Fri, 5 Sep 2003 11:14:28 -0700
Lines: 9
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNz2Yt3Dhmj8jm/RlO1ml5VJWd4bw==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.general:107449
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

I created a Windows Service in C# that requires to get
passed command arguments like a Console App. I noticed
that there is an option "Start parameters" text box in
the property of a Windows Service in MMC. Is there any
way to get arguments using this option? If possible,
what
framework method should I use to get an arguement?
Thanks in advance.

Eric


.

.
 
Back
Top