![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||