Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - How to retrieve service name at runtime

Reply
 
Old 07-29-2008   #1 (permalink)
QSIDeveloper


 
 

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?

My System SpecsSystem Spec
Old 07-30-2008   #2 (permalink)
Feng Chen[MSFT]


 
 

RE: How to retrieve service name at runtime

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:
msdnmg@xxxxxx.
==================================================
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.

My System SpecsSystem Spec
Old 07-31-2008   #3 (permalink)
Feng Chen[MSFT]


 
 

RE: How to retrieve service name at runtime

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:
msdnmg@xxxxxx.

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

My System SpecsSystem Spec
Old 08-04-2008   #4 (permalink)
QSIDeveloper


 
 

RE: How to retrieve service name at runtime

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:
Quote:

> 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:
> msdnmg@xxxxxx.
>
> This posting is provided "AS IS" with no warranties, and confers no rights
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Anyone know what .NET Runtime Optimization Service is? General Discussion
How to retrieve Service Pack of the .net Version PowerShell
Microsoft Visual C++ Runtime Library ...Runtime Error Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46