470,594 Members | 1,162 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Get command arguments in Windows Service

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
Jul 19 '05 #1
5 6955
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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
Subject: Get command arguments in Windows Service
Date: Fri, 5 Sep 2003 11:14:28 -0700
Lines: 9
Message-ID: <22****************************@phx.gbl>
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


Jul 21 '05 #2
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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
Subject: Get command arguments in Windows Service
Date: Fri, 5 Sep 2003 11:14:28 -0700
Lines: 9
Message-ID: <22****************************@phx.gbl>
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:107449NNTP-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, whatframework method should I use to get an arguement?
Thanks in advance.

Eric


.

Jul 21 '05 #3
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/is...v/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.
--------------------
Content-Class: urn:content-classes:message
From: "Eric Chong" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
References: <22****************************@phx.gbl> <Gx**************@cpmsftngxa06.phx.gbl>Subject: RE: Get command arguments in Windows Service
Date: Mon, 8 Sep 2003 09:16:28 -0700
Lines: 56
Message-ID: <41****************************@phx.gbl>
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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
Subject: Get command arguments in Windows Service
Date: Fri, 5 Sep 2003 11:14:28 -0700
Lines: 9
Message-ID: <22****************************@phx.gbl>
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.gblmicrosoft.public.dotnet.general:107449NNTP-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,whatframework method should I use to get an arguement?
Thanks in advance.

Eric


.


Jul 21 '05 #4
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" textbox 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 ServiceEasy
http://msdn.microsoft.com/msdnmag/is...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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
References: <22****************************@phx.gbl>

<Gx**************@cpmsftngxa06.phx.gbl>
Subject: RE: Get command arguments in Windows Service
Date: Mon, 8 Sep 2003 09:16:28 -0700
Lines: 56
Message-ID: <41****************************@phx.gbl>
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:107680NNTP-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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
Subject: Get command arguments in Windows Service
Date: Fri, 5 Sep 2003 11:14:28 -0700
Lines: 9
Message-ID: <22****************************@phx.gbl>
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.0300Thread-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
.


.

Jul 21 '05 #5
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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
References: <22****************************@phx.gbl> <Gx**************@cpmsftngxa06.phx.gbl>
<41****************************@phx.gbl>
<og**************@cpmsftngxa06.phx.gbl>Subject: RE: Get command arguments in Windows Service
Date: Tue, 9 Sep 2003 09:37:41 -0700
Lines: 120
Message-ID: <01****************************@phx.gbl>
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/is...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" <ec********@hotmail.com>
Sender: "Eric Chong" <ec********@hotmail.com>
References: <22****************************@phx.gbl>

<Gx**************@cpmsftngxa06.phx.gbl>
Subject: RE: Get command arguments in Windows Service
Date: Mon, 8 Sep 2003 09:16:28 -0700
Lines: 56
Message-ID: <41****************************@phx.gbl>
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.gblmicrosoft.public.dotnet.general:107680NNTP-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" <ec********@hotmail.com>
>Sender: "Eric Chong" <ec********@hotmail.com>
>Subject: Get command arguments in Windows Service
>Date: Fri, 5 Sep 2003 11:14:28 -0700
>Lines: 9
>Message-ID: <22****************************@phx.gbl>
>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 MimeOLEV5.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
>

.


.


Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by tuckkhai | last post: by
5 posts views Thread by Eric Chong | last post: by
4 posts views Thread by Fei | last post: by
2 posts views Thread by Chris Mullins | last post: by
2 posts views Thread by =?Utf-8?B?dmlzaHJ1dGg=?= | last post: by
1 post views Thread by =?Utf-8?B?dmlzaHJ1dGg=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.