473,387 Members | 1,453 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,387 software developers and data experts.

Coding service dependencies

Hi all,
I've got a windows service that depends on some other services. On the
project installer I state this by using:

Me.myService.ServicesDependedOn = New String() {"Print Spooler", "Net
Logon", "Network Connections"}

The problem:
If the server is not an english version I have to translate the service
names. Here is how I do it for portuguese and "other" (english):

Dim ci As CultureInfo = CultureInfo.CurrentUICulture
If InStr(ci.TwoLetterISOLanguageName, "pt", CompareMethod.Text) 0 Then
Me.myService.ServicesDependedOn = _
New String() {"Spooler de impressão", "Início de sessão de rede",
"Ligações de rede"}
Else
Me.myService.ServicesDependedOn = _
New String() {"Print Spooler", "Net Logon", "Network Connections"}
End If

But what if it gets deployed to a German, Spanish or French server?

Do I need to code every possibility or is there a way to reference these
services in a language independent way?

Best regards,
Manuel Alves
Aug 24 '06 #1
3 5598
Hi Manuel,

Sorry, I do not have these localized version of Windows for testing. I
assume that the *Display Name* for these services on the localized Windows
will be different from the English Windows. However, I suspect the "Service
Name" of these services will still use the english name. You may use
Services.msc on these localized Windows to help me to confirm this.

If my suspect is correct, we can just enumerate all the services and
compare *Service Name* with stored english service name. Once one is found,
we can get its "Display Name" for ServicesDependedOn usage. To enumerate
all the serivces and get the *Service Name*, you may use the following code
snippet:

Dim sc As ServiceController() = ServiceController.GetServices()
Dim i As Integer
For i = 0 To sc.Length - 1
If(sc(i).ServiceName) = "Spooler" Then
.....
End If
Next i

If my suspect is incorrect, that is, the *Service Name* is also localized
to non-english name, then we have to use the service binary file name as
the information to identify the service we want.

To get this done, we have to enumerate all the services on the system, and
for each service, we have to p/invoke OpenService win32 API to get the
handle to the this service, finally, we can p/invoke QueryServiceConfig API
to query the full information of this service now. The retrieved
QUERY_SERVICE_CONFIG structure has a field of lpBinaryPathName, which
contains the full binary path of the service. You may use this full binary
path for comparison and identify the service you want. The reason that we
have to p/invoke win32 API to get this done is that .Net did not
encapsulate this function currently.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
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.

Aug 25 '06 #2
Thanks a lot.
The ServiceName is language invariant.
I can just use
Me.myService.ServicesDependedOn = New String() {"Spooler", "Netlogon",
"Netman"}
and it works for all languages.

Here is a small windows form app with a textbox to get the services names
and display names
Imports System.ServiceProcess
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
With TextBox1
.Text = ""
.ScrollBars = ScrollBars.Both
.Dock = DockStyle.Fill
End With
Dim sc As ServiceController() = ServiceController.GetServices()
Dim i As Integer
For i = 0 To sc.Length - 1
TextBox1.Text += sc(i).ServiceName & vbTab & vbTab &
sc(i).DisplayName & vbCrLf
Next i
End Sub
End Class

Best regards,
Manuel Alves
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:15*************@TK2MSFTNGXA01.phx.gbl...
Hi Manuel,

Sorry, I do not have these localized version of Windows for testing. I
assume that the *Display Name* for these services on the localized Windows
will be different from the English Windows. However, I suspect the
"Service
Name" of these services will still use the english name. You may use
Services.msc on these localized Windows to help me to confirm this.

If my suspect is correct, we can just enumerate all the services and
compare *Service Name* with stored english service name. Once one is
found,
we can get its "Display Name" for ServicesDependedOn usage. To enumerate
all the serivces and get the *Service Name*, you may use the following
code
snippet:

Dim sc As ServiceController() = ServiceController.GetServices()
Dim i As Integer
For i = 0 To sc.Length - 1
If(sc(i).ServiceName) = "Spooler" Then
.....
End If
Next i

If my suspect is incorrect, that is, the *Service Name* is also localized
to non-english name, then we have to use the service binary file name as
the information to identify the service we want.

To get this done, we have to enumerate all the services on the system, and
for each service, we have to p/invoke OpenService win32 API to get the
handle to the this service, finally, we can p/invoke QueryServiceConfig
API
to query the full information of this service now. The retrieved
QUERY_SERVICE_CONFIG structure has a field of lpBinaryPathName, which
contains the full binary path of the service. You may use this full binary
path for comparison and identify the service you want. The reason that we
have to p/invoke win32 API to get this done is that .Net did not
encapsulate this function currently.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
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.

Aug 25 '06 #3
Hi Manuel,

Cool! I have never known that ServicesDependedOn can be passed with
ServiceName instead of Display Name. The PlatformSDK document for
*lpDependencies* parameter of CreateService also does not clarify this
point.

Also, since the "Dependencies" tabpage of Services.msc MMC always displays
the depended service with display name instead of Service Name, I used to
think that "Display Name" is the only valid option for ServicesDependedOn
property. However, after viewing the services configuration stored in
HKLM\SYSTEM\CurrentControlSet\Services\, I found that many services really
store the "Service Name" as the *DependOnGroup* key of under the service.
So you are right!

Thank you again for sharing this with us :-)

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
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.

Aug 28 '06 #4

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

Similar topics

9
by: Alan Pretre | last post by:
I have a Windows service that is having trouble starting up at boot time. It requires SQL Server to start up. I have added MSSQLSERVER to the service dependencies (as explained in...
3
by: mailme.faisal | last post by:
I have created a service that create a process. The service is running in local system account & it also create the new process in system account. In process i have to access network resource ....
2
by: John Olbert | last post by:
We have a large application (the Exe is about 10 mb Released) built as a C++ unmanaged Solution under Vs2003. This App is targeted for Win2000. The latest Service Pack for Windows 2000 has...
29
by: Ken Allen | last post by:
I have a number of services developed in C# (.Net), and they have been working fine for the most part. Recently someone reported that ipon occassion (originally rarely, but more frequently on some...
3
by: adasilva | last post by:
I have create a Windows service that uses a timer to access a Web Service. The service is set to start Automatically and its using the local system account. The service also logs events to the...
3
by: ct-86 | last post by:
http://www.cdbook.cn/book.asp?id=2393 Organizational and Policy Issues 1 0. Don't sweat the small stuff. (Or: Know what not to standardize.) 2 1. Compile cleanly at high warning levels. 4 2....
1
by: Usman | last post by:
Hi I've created a windows service in .Net and want it to be dependant on some other service. Can someone please tell how to do it programatically instead of editing the registry. Just like...
8
by: DF Dev | last post by:
I have created a Windows Service using Visual Studio .Net 2005 and C# which executes a series of database jobs on a time basis. I am using SqlConnections and SqlCommand objects to connect to a SQL...
3
by: davey23crocket | last post by:
Hi, I am using C# 2.0 and DotNet 2.0. I created a Windows client service with start-up type: Automatic. But upon reboot it won't start. How can I find out what service dependencies I have?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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...

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.