 |
|
 |
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...
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
In .net 2.0 you can do that with the property Description of the ServiceInstaller.
...
this.serviceInstaller1.Description = "The description to display";
...
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
Perhaps a cleaner approach over the posted code is to simply exploit the ServiceInstaller.Committed event handler. As an example, public ProjectInstaller() { InitializeComponent(); serviceInstaller.Committed += new System.Configuration.Install.InstallEventHandler(serviceInstaller_Committed); }
private void serviceInstaller_Committed(object sender, System.Configuration.Install.InstallEventArgs e) { serviceInstaller_ServiceDescription("service description text"); }
private void serviceInstaller_ServiceDescription(string description) { RegistryKey registrykey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Services\\" + serviceInstaller.ServiceName,true); registrykey.SetValue("Description",description); }
This can still be optimized further by incorporating a try/catch on the registry operations, etc. But you get the general idea.
c.sharpener
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
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(); }
|
| Sign In·View Thread·PermaLink | 3.67/5 (2 votes) |
|
|
|
 |
|
 |
If your windows service used setup project to deploy, then you can optionally use Registry Editor to faclitate this code.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
LPSTR lpszDescription = "Service Description Here"; ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &lpszDescription);
Napalm
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
 |
Just what I was looking for. Thanks for sharing!
Cheers,
Caio Proiete  MCT, MCSD, MCDBA, MCAD .NET, MCSD .NET
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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 @)
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
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 { 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
|
| Sign In·View Thread·PermaLink | 4.80/5 (2 votes) |
|
|
|
 |
|
 |
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 MyBase.Install(v_IDstateserver)
rgkSystem = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System") rgkCurrentControlSet = rgkSystem.OpenSubKey("CurrentControlSet") rgkServices = rgkCurrentControlSet.OpenSubKey("Services") rgkService = rgkServices.OpenSubKey(Me.ServiceInstaller1.ServiceName, True) rgkService.SetValue("Description", "My service description") 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 rgkSystem = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System") rgkCurrentControlSet = rgkSystem.OpenSubKey("CurrentControlSet") rgkServices = rgkCurrentControlSet.OpenSubKey("Services") rgkService = rgkServices.OpenSubKey(Me.ServiceInstaller1.ServiceName, True) rgkService.DeleteSubKeyTree("Parameters") Catch ex As Exception Console.WriteLine("Exception encountered while uninstalling service:" & vbCrLf & ex.ToString()) Finally MyBase.Uninstall(v_IDstateserver) End Try End Sub
zz[
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
 | Génial  |  | Anonymous | 14: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.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | 4.00/5 (3 votes) |
|
|
|
 |
|
 |
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The routine wouldn't write the key until i put the code into the afterinstall event handler of the serviceinstaller object...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi everybody, I want to run a exe file from windows service which interacts with desktop. I can run a process ( e.g notepad.exe ) from a service but can not run an exe file which opens a console window when started from a command prompt. Here is the code sample below:-
protected override void OnStart(string[] args) { string sysFolder = @"C:\somepath\test.exe"; ProcessStartInfo pInfo = new ProcessStartInfo(); pInfo.FileName = sysFolder; pInfo.UseShellExecute = true; Process p = new Process(); p = Process.Start(pInfo); }
Can anybody suggests anything?? Thanks..
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
You will need to have the Service be able to interct with the desktop to view the console ouput while your program is running.
Right-Click on your Service, choose properties, and go the LogOn tab. Check the "Allow service to interact with Desktop" option. This should get you going.
..:: Keno ::..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |