473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to retrieve service name at runtime

I have a Windows service that we need to have multiple instances running. We
achieve this by using InstallUtil Service.exe /name="SomeServiceName". I
need to know the name of the instance of the service that is running at
runtime, the name displayed in the Services UI. If I examine ServiceName at
runtime I do not get the name assigned by InstallUtil that is shown in the
services UI nor do I get the default name assigned by the ServiceInstaller
class. Is there some way to retrieve this information at runtime?
Jul 29 '08 #1
3 7516
Hi

This is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.

Best regards,
Feng Chen
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications .

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 30 '08 #2
Hello,

By InstallUtil, I assume you mean the Installer Tool (Installutil.exe) -
http://msdn.microsoft.com/en-us/libr...95(VS.90).aspx. However, this
tool does not have the '/name' argument. If I have misunderstood you,
please let me know.

For a windows service with multi-instance running at the same time, we can
use WMI Win32_Service
class(http://msdn.microsoft.com/en-us/libr...18(VS.85).aspx) to
query the DisplayName of a service by specifying the Process ID of the
running service. And I write a code snippet:

using System;
using System.Diagnostics;
using System.Management; // Add System.Management as reference to the
project.

{
// Get process ID of current running service instance
int Pid = Process.GetCurrentProcess().Id;

ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"root\\CIMV2", "SELECT DisplayName FROM Win32_Service WHERE
ProcessId = " + Pid);

foreach (ManagementObject queryObj in searcher.Get())
{
String displayName = queryObj["DisplayName"].ToString();
break;
}

Debug.WriteLine( "Display name of the current service: " + displayName
);
}

Please try the code above and let me know if it does not help you you need
any other help.

Best regards,
Feng Chen
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights

Jul 31 '08 #3
Sorry I had missed your reply.

I tried the code and it does work as you said.

BTW we added the parameter ‘name’ to change the display name of the service .

Thank you for your help.
"Feng Chen[MSFT]" wrote:
Hello,

By InstallUtil, I assume you mean the Installer Tool (Installutil.exe) -
http://msdn.microsoft.com/en-us/libr...95(VS.90).aspx. However, this
tool does not have the '/name' argument. If I have misunderstood you,
please let me know.

For a windows service with multi-instance running at the same time, we can
use WMI Win32_Service
class(http://msdn.microsoft.com/en-us/libr...18(VS.85).aspx) to
query the DisplayName of a service by specifying the Process ID of the
running service. And I write a code snippet:

using System;
using System.Diagnostics;
using System.Management; // Add System.Management as reference to the
project.

{
// Get process ID of current running service instance
int Pid = Process.GetCurrentProcess().Id;

ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"root\\CIMV2", "SELECT DisplayName FROM Win32_Service WHERE
ProcessId = " + Pid);

foreach (ManagementObject queryObj in searcher.Get())
{
String displayName = queryObj["DisplayName"].ToString();
break;
}

Debug.WriteLine( "Display name of the current service: " + displayName
);
}

Please try the code above and let me know if it does not help you you need
any other help.

Best regards,
Feng Chen
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights

Aug 4 '08 #4

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

Similar topics

9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
1
by: vijay | last post by:
Hello I am learnign Dot NEt I have implemted 1. remote object 2.Listener 3.Client Listener started and listening to requests Client started and able to nstantiate remote object But when a...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
0
by: dpp | last post by:
Hi I am calling a method of a .NET component from both win forms and web service applications. Strangly, it is working fine from win forms application, but when i call the same method (same...
0
by: Dave A | last post by:
When I register a remoting service programmatically things work great but when I register the service using a config file I get the error "Requested Service not found" when invoking a server...
2
by: Richard Collette | last post by:
Hi, I have a service, that runs perfectly when executed outside of the web service environment. When called as a web service I get the exception listed below sporadically. A call to the web...
0
by: =?Utf-8?B?QWRyaWFuIENvbGU=?= | last post by:
I have written a simple WCF service hosted in a Windows console application and a simple WCF client console application that connects successfully to that service and retrieves data. I then ported...
8
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
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...

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.