 |
|
 |
Very good article deserves a good rating.
|
|
|
|
 |
|
 |
well done for its time
cheers,
Donsw
My Recent Article : CDC - Change Data Capture
|
|
|
|
 |
|
 |
In .Net 1.1, just create a setup project for your service (which you probably did already) and add a registry keyin Registry Editor. BTW, in Server2003, you have to put Description string directly under YourServiceName key, not in Parameters key...
|
|
|
|
 |
|
 |
On your ServiceInstaller class;
service.Description = "Your project description";
|
|
|
|
 |
|
 |
Not in .NET 1.0/1.1. Look at when this article was written.
|
|
|
|
 |
|
 |
In .net 2.0 you can do that with the property Description of the ServiceInstaller.
...
this.serviceInstaller1.Description = "The description to display";
...
|
|
|
|
 |
|
 |
It Helped me a lot....
The other solutions posted have also been very usefull..
Thanks for all for sharing
|
|
|
|
 |
|
 |
Perhaps a cleaner approach over the posted code is to simply exploit the ServiceInstaller.Committed event handler. As an example,<br>public ProjectInstaller()<br>{<br> InitializeComponent();<br> serviceInstaller.Committed += new System.Configuration.Install.InstallEventHandler(serviceInstaller_Committed);<br>}<br><br>private void serviceInstaller_Committed(object sender, System.Configuration.Install.InstallEventArgs e)<br>{<br> serviceInstaller_ServiceDescription("service description text");<br>}<br><br>private void serviceInstaller_ServiceDescription(string description)<br>{<br> RegistryKey registrykey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Services\\" + serviceInstaller.ServiceName,true);<br> registrykey.SetValue("Description",description);<br>}<br>This can still be optimized further by incorporating a try/catch on the registry operations, etc. But you get the general idea.
c.sharpener
|
|
|
|
 |
|
 |
I like that. I put it into a class for reuse -
public static void SetServiceDescription(string serviceName, string description)
{
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Services\" + serviceName, true);
regKey.SetValue("Description", description);
regKey.Close();
}
|
|
|
|
 |
|
 |
If your windows service used setup project to deploy, then you can optionally use Registry Editor to faclitate this code.
|
|
|
|
 |
|
 |
LPSTR lpszDescription = "Service Description Here";
ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &lpszDescription);
Napalm
|
|
|
|
 |
|
 |
Just what I was looking for. Thanks for sharing!
Cheers,
Caio Proiete
MCT, MCSD, MCDBA, MCAD .NET, MCSD .NET
|
|
|
|
 |
|
 |
The code below seems to work for me. It enables the Windows Service developer to enter the ServiceDescription text in the ServiceInstaller properties window in the designer. Put the WindowsServiceInstaller class in its own class library project that references the System.ServiceProcess assembly, and reference that project in your Window Service project(s). In each ProjectInstaller.vb, just replace the two references to System.ServiceProcess.ServiceInstaller with WindowsServiceInstaller.
Imports System.ServiceProcess Public Class WindowsServiceInstaller : Inherits ServiceInstaller Private m_serviceDescription As String <ComponentModel.Description("A lengthy description of the service that will display in the Description column of the Services MMC applet.")> _ Public Property ServiceDescription() As String Get Return m_serviceDescription End Get Set(ByVal Value As String) m_serviceDescription = Value End Set End Property Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary) MyBase.Install(stateSaver) Dim serviceKey As Microsoft.Win32.RegistryKey Try Dim strKey As String = String.Format( _ "System\CurrentControlSet\Services\{0}", Me.ServiceName) serviceKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strKey, True) serviceKey.SetValue("Description", Me.ServiceDescription) Finally If Not serviceKey Is Nothing Then serviceKey.Close() End Try End Sub End Class Scott Hutchinson s.c.o.t.t.h.u.t.c.h.i.n.s.o.n@usa.net (to contact me, remove all dots left of @)
|
|
|
|
 |
|
 |
Hi Scott, I think your solution is more elegant than the solution proposed by the article.
I just converted it to C#, in order to use in my projects
Here it goes:
using System;
namespace System.ServiceProcess
{
///
/// Summary description for WindowsServiceInstaller.
///
public class WindowsServiceInstaller : ServiceInstaller
{
[ComponentModel.Description("A lengthy description of the service that will display in the Description column of the Services MMC applet.")]
public string ServiceDescription
{
get { return serviceDescription; }
set { serviceDescription = value; }
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install (stateSaver);
Microsoft.Win32.RegistryKey serviceKey = null;
try
{
string strKey = string.Format(
@"System\CurrentControlSet\Services\{0}", this.ServiceName);
serviceKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strKey, true);
serviceKey.SetValue("Description", this.ServiceDescription);
}
finally
{
if (serviceKey != null)
serviceKey.Close();
}
}
private string serviceDescription;
}
}
Cheers,
Caio Proiete
MCT, MCSD, MCDBA, MCAD .NET, MCSD .NET
|
|
|
|
 |
|
 |
Excellent article. Just to help any VB coders out there, here is a quick translation.
Thanks
Jon
Public Overrides Sub Install(ByVal v_IDstateserver As System.Collections.IDictionary)
Dim rgkSystem As Microsoft.Win32.RegistryKey
Dim rgkCurrentControlSet As Microsoft.Win32.RegistryKey
Dim rgkServices As Microsoft.Win32.RegistryKey
Dim rgkService As Microsoft.Win32.RegistryKey
Dim rgkConfig As Microsoft.Win32.RegistryKey
Try
' 'Let the project installer do its job
MyBase.Install(v_IDstateserver)
'Open the HKEY_LOCAL_MACHINE\SYSTEM key
rgkSystem = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System")
'Open CurrentControlSet
rgkCurrentControlSet = rgkSystem.OpenSubKey("CurrentControlSet")
'Go to the services key
rgkServices = rgkCurrentControlSet.OpenSubKey("Services")
'Open the key for your service, and allow writing
rgkService = rgkServices.OpenSubKey(Me.ServiceInstaller1.ServiceName, True)
'Add your service's description as a REG_SZ value named "Description"
rgkService.SetValue("Description", "My service description")
'(Optional) Add some custom information your service will use...
rgkConfig = rgkService.CreateSubKey("Parameters")
Catch ex As Exception
Console.WriteLine("An exception was thrown during service installation:" & vbCrLf & ex.ToString())
End Try
End Sub
Public Overrides Sub Uninstall(ByVal v_IDstateserver As System.Collections.IDictionary)
Dim rgkSystem As Microsoft.Win32.RegistryKey
Dim rgkCurrentControlSet As Microsoft.Win32.RegistryKey
Dim rgkServices As Microsoft.Win32.RegistryKey
Dim rgkService As Microsoft.Win32.RegistryKey
Dim rgkConfig As Microsoft.Win32.RegistryKey
Try
'Drill down to the service key and open it with write permission
rgkSystem = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System")
rgkCurrentControlSet = rgkSystem.OpenSubKey("CurrentControlSet")
rgkServices = rgkCurrentControlSet.OpenSubKey("Services")
rgkService = rgkServices.OpenSubKey(Me.ServiceInstaller1.ServiceName, True)
'Delete any keys you created during installation (or that your service created)
rgkService.DeleteSubKeyTree("Parameters")
'...
Catch ex As Exception
Console.WriteLine("Exception encountered while uninstalling service:" & vbCrLf & ex.ToString())
Finally
'Let the project installer do its job
MyBase.Uninstall(v_IDstateserver)
End Try
End Sub
zz[
|
|
|
|
 |
|
 |
I had better luck putting the code in AfterInstall and AfterUninstall...
|
|
|
|
 |
|
 |
Hi,
I run my service in context of a normal user. The idea was to log serious errors and then to stop the service by it self. But since the user does not seam to have the correct privilege it does not stop when using code like
ServiceController sc = new ServiceController("MyService");
sc.Stop();
instead I get an exception.
When I run my service in context of LocalSystem stopping works.
The thing is I don't want to give my user account privileges like
'act as a part of the operating system'.
Would have been very nice if they also had implemented sort of privilege
'can stop windows services'
Thanks for any idea or help.
|
|
|
|
 |
|
 |
Hi everybody...
i have made a windows service which call winzip from service and make a zip file, i have tested it on windows 2000 professional which is under XYZ domain and it is working fine, but when i isntalled it on Widnows 2000 Server which is under workgroup, is not working means unable to create a zip file.
so kindly reply me if any body have any idea...
looking farward for kind reply
with best regards,
Adeel Ahmad
|
|
|
|
 |
|
 |
1st. excellent article, you got my 5
Do you know if Install() is called once or is it called for every Installer.Add() ?
Reason I ask is that I have an application that loads more than one service and would like to set the description for each service dynamicly
public MyInstaller() {
ServiceProcessInstaller process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service1 = new svcInstaller();
service1.StartType = ServiceStartMode.Manual;
service1.ServiceName = "Svc1";
service1.DisplayName = "1st service";
service1.Description = "This is my first service";
service2 = new svcInstaller();
service2.StartType = ServiceStartMode.Manual;
service2.ServiceName = "Svc2";
service2.DisplayName = "2nd service";
service2.Description = "This is my second service";
Installers.Add(service1);
Installers.Add(service2);
}
internal class svcInstaller : ServiceInstaller
{
public string Description;
}
privat svcInstaller service1,service2;
public override void Install(IDictionary stateServer)
{
Microsoft.Win32.RegistryKey system,currentControlSet,services,service
try
{
base.Install(stateServer);
.
.
.
}
}
../Per
|
|
|
|
 |
|
 |
thanks for the code. it worked fine after I added the two lines to close the keys and so flush the Values into the registry:
for install:
"//(Optional) Add some custom information your service will use...
config = service.CreateSubKey("Parameters");
config.Close();"
for uninstall:
"//Delete any keys you created during installation (or that your service created)
service.DeleteSubKeyTree("Parameters");
service.Close();"
nevertheless
thanks alot.
|
|
|
|
 |
 | Génial  |  | Anonymous | 13:05 1 Dec '03 |
|
 |
Je viens de le tester. Ca marche complètement et en plus... j'ai tout compris.
Merci beaucoup pour cette aide précieuse.
|
|
|
|
 |
|
 |
I would like to default the service start parameters to some value when installing the service. Is this possible? In a serviced component I can set the default of the construction string using the following code…
<Transaction(TransactionOption.Required), _ ConstructionEnabledAttribute(Default:="someValue")> _ Public Class clsAppPoolManager Inherits ServicedComponent ... End class But I can’t figure out how to do this for a service. Once the service is installed you’ll notice via the service properties dialog box, there are accommodations that allow parameters to be passed in when the service is started. I would like to set that ‘start parameters’ text box to a default value. Are there attributes, similar to the code above, I may add to my class to get the desired effect? Thanks in Advance, Bill DeWeese bill@deweese.com
|
|
|
|
 |
|
 |
Hi All,
I have two exe's. Therefore, these are two different processes on the same machine. One of these process is Managed Code while the other is Unmanaged COM object. I need to be able to make these processes talk to each other.
In other words, I need cross-process communication. Is this possible? Whats the best way to achieve this?
Any help greatly appreciated!
Thanks.
|
|
|
|
 |
|
 |
Yes, cross process communication is possible. You have to use RCW (Runtime Callable Wrapper). Pls go through this article. You will get clear idea.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcomwrappers.asp
The below link provide you a good sample code.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callcomcomp.asp
|
|
|
|
 |
|
 |
The routine wouldn't write the key until i put the code into the afterinstall event handler of the serviceinstaller object...
|
|
|
|
 |