473,883 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7203
Hi Eric,

You may try the Environment.Get CommandLineArgs 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.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.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:107449
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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
GetCommandLineA rgs method.

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

You may try the Environment.Get CommandLineArgs 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.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.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:107449NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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 misunderstandin g 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.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+Az dR9ucVL9fs0/JAw==
Newsgroups: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:107680
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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
GetCommandLine Args method.

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

You may try the Environment.Get CommandLineArgs 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.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.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gblmicrosoft.publ ic.dotnet.gener al:107449NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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 misunderstandin g 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.com>
References: <22************ *************** *@phx.gbl>

<Gx*********** ***@cpmsftngxa0 6.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+Az dR9ucVL9fs0/JAw==
Newsgroups: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:107680NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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
GetCommandLin eArgs method.

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

You may try the Environment.Get CommandLineArgs 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.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= =
Newsgroup s: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl

microsoft.pub lic.dotnet.gene ral:107449
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.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+pEb hRPyiRqQ==
Newsgroups: microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:107813
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

Thank you very much!!! It works.

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

Sorry for misunderstandin g 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********@hot mail.com>
Sender: "Eric Chong" <ec********@hot mail.com>
References : <22************ *************** *@phx.gbl>

<Gx********** ****@cpmsftngxa 06.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+Az dR9ucVL9fs0/JAw==
Newsgroups : microsoft.publi c.dotnet.genera l
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gblmicrosoft.publ ic.dotnet.gener al:107680NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.publi c.dotnet.genera l

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
GetCommandLi neArgs method.

Eric

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

You may try the Environment.Get CommandLineArgs 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********@hot mail.com>
>Sender: "Eric Chong" <ec********@hot mail.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.030 0>Thread-Index: AcNz2Yt3Dhmj8jm/RlO1ml5VJWd4bw= =
>Newsgroups : microsoft.publi c.dotnet.genera l
>Path: cpmsftngxa06.ph x.gbl
>Xref: cpmsftngxa06.ph x.gbl
microsoft.pu blic.dotnet.gen eral:107449
>NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
>X-Tomcat-NG: microsoft.publi c.dotnet.genera l
>
>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
>framewor k method should I use to get an arguement?
>Thanks in advance.
>
>Eric
>

.


.


Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4996
by: tuckkhai | last post by:
Hi, I am a newbie in this area. I would like to know whether is it possible to execute shell command in windows service. I had install a program in the server which i would like it to be executed using windows services. Is it possible. If yes, how? Thanks
4
15571
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C# application. The command runs successfully from a Windows Form but fails if the application is recasted as a Windows service. The application is essentially a File Watcher that should run the process when a file is dropped into a specific directory. ...
3
8674
by: BROQ | last post by:
Hi, I am using a windows service to extract every hour a log from our mailserver in order to parse the logfile. To do this I used the folowing code: Shell("""C:\pscp"" -pw ******* mgm@192.168.1.240:/var/log/qmail/current C:\_var_log_qmail_current.txt", AppWinStyle.MaximizedFocus)
5
418
by: Eric Chong | last post by:
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
4
1312
by: Fei | last post by:
Hi, I got a strange problem. I use Macrovision installshield x express edition to build a simple MSI file. I can install this mis silently, i.e using /qn. It has no problem to run either in the command prompt or in a windows application. However when I put the same code to run this msi in a small windows service, it does NOTHING !!! It only starts the thread, but it does not do installation.Why? Here are codes:
1
1055
by: dmuralikumar | last post by:
Hi All, I am finding it difficult to send some parameters to the exe corresponding to a Windows Service that has been installed.Its the same case with the exe i.e., I dont where i have to make the exe accept those arguments sent in. Please provide me assistance in this regard at the earliest.. Thanks and Regards, Murali.
2
2629
by: Chris Mullins | last post by:
For some reason the question, "Can I make an EXE that is both a Windows Service and a Console Application?" has come up quite a bit for me over the last few weeks. I've been doing this for years, but for some reason I've never seen it documented anywhere. C# (or VB.Net) is perfectly happy to create an EXE that can be: 1 - Both a WinForms App or a Windows Service 2 - Both a Console App or a Windows Service
2
4505
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My main process is Windows service.
1
4858
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My main process is Windows service.
0
9953
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
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
11166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9588
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
7980
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
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
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
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.