|
|
Comments and Discussions
|
|
 |
|

|
Any clues, why I cannot execute the test.bat file (access denied) in the example code?
Running a compiled C-program instead of the test.bat file runs just fine.
protected override void Start() {
this.Log("Service started");
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "c:\\test.bat";
startInfo.Arguments = " 12345";
startInfo.WorkingDirectory = @"C:\Temp";
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.ErrorDialog = true;
Process process;
process = Process.Start(startInfo);
if (process.WaitForExit(30000))
{
this.Log("Process terminated.");
}
else
{
this.Log("Timed out waiting for process to end.");
}
}
|
|
|
|

|
As far as I understand from the CPL license the code examples can be used freely in any environment, commercial and whatever. I would like to change all occurences of Hoytsoft to another "brand".
Of course I honor the effort of the original author and I also would not change any copyright mentionings (although I would like to see on the other hand, whether modifying the source code to the extent of totally changing everything, even the copyright entries, is possible from the CPL).
While I was changing every HoytSoft naming to another name I came to a point where suddenly ServiceAPI was unknown in the context. So maybe I overlooked something in the renaming of variables, methods and classes.
--
Christoph
|
|
|
|

|
The Microsoft ServiceBase class has a RequestAdditionalTime method to delay the Service Control Manager from timing out if it is taking a longer time to Stop (if finishing up some data processing before stop for example). Is there anything like that here? Thanks.
|
|
|
|

|
I'd LOVE to use this in my project but the latest version isn't available the website ip is there but there isn't a server dishing up the goodness!
|
|
|
|

|
Hello all,
Thanks for everyone's support. I just released a NEW version on codeplex (http://aspnetsuite.codeplex.com/[^]) as part of my larger asp.net suite that includes proper UAC elevation prompts and compatibility with XP/Vista/Server 2003/Server 2008 and 32-bit and 64-bit editions.
It's released under a very liberal BSD-style license.
I pretty much gutted and re-did most of the library. I included some suggestions from the community (e.g. CustomMessage(...)). The install problem noted below should be solved. You can now literally create a service in 1 line of code (it probably wouldn't be very useful, though). So those who had Vista-compatibility problems, please try this version out. I also included a UAC library that I don't mind anyone using. It's backwards compatible with XP - but I haven't tested it on Windows 2000. I don't provide much documentation, unfortunately, but I hope it'll be mostly self-explanatory.
At any rate, check out the notes on that link[^], download it, and give 'er a go!
modified on Thursday, March 5, 2009 12:26 AM
|
|
|
|
|

|
Is it possible to catch the INT-Commands sent to this service with your class? (Implement OnCustomCommand?)
cheers kim
|
|
|
|

|
Hi
The service base class really does everything I want.
I only get a problem, when I try to run the service with a user account which is not the System account that is normaly used for services. We I try to start the service, I get the following error message:
Error 1053: The service did not respond to the start or control request in a
timely fashion
My service has to run with a specific account and password, so it can access files which are stored on a Linux box (with a Samba share).
Many thanks for all hints
Regards
Tom
|
|
|
|

|
What a great code! Runs w/o problems, even if an error msg is displayed if you are trying to stop the service from the control panel in Vista.
But, when creating a service from the VStudio GUI, there are several attributes that can be set for ther service at "design time". CanShutdown and CanStop among them. Is there a way to set CanStop=false to avoid users to abort my service, when using the HoytSoft code?
Kind regards
/Magnus in Sweden
|
|
|
|

|
BTW, this code works great under XP. Under Vista, an error occurs whenever the service is stopped: Error 1061: The service cannot accept control message at this time. Any advice on fixing this error?
thanks again for the good work
jgates
|
|
|
|

|
Just wondering, is there a OnCustomCommand(int) Method exposed ? and if not can it be implemented
i have many services which use it for custome control of the services (like starting and stoping diffrent components of the service)
|
|
|
|

|
Your code uses registry APIs to set the description, but it's probably better to use the ChangeServiceConfig2 API instead. This snippet of code should be enough to make it work:
At around line 617 in ServiceBase.cs in baseInstall():
ServicesAPI.CloseServiceHandle(sc_handle);
return false;
}
+ + ServicesAPI.SERVICE_DESCRIPTION info = new ServicesAPI.SERVICE_DESCRIPTION();
+
+ info.lpDescription = Description;
+ if (Description == null)
+ info.lpDescription = "";
+ ServicesAPI.ChangeServiceConfig2A(sv_handle, ServicesAPI.InfoLevel.SERVICE_CONFIG_DESCRIPTION, ref info);
ServicesAPI.CloseServiceHandle(sv_handle);
ServicesAPI.CloseServiceHandle(sc_handle);
- - - - - - - - - -
return true;
} catch {
And in ServiceAPI.cs near line 48:
int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup,
int lpdwTagId, string lpDependencies, string lpServiceStartName,
string lpPassword, string lpDisplayName);
! [DllImport("advapi32.dll", CharSet = CharSet.Ansi, PreserveSig = true)]
public static extern bool ChangeServiceConfig2A(
! IntPtr hService, InfoLevel dwInfoLevel,
[MarshalAs(UnmanagedType.Struct)] ref SERVICE_DESCRIPTION lpInfo);
! [DllImport("advapi32.dll", CharSet = CharSet.Ansi, PreserveSig = true)]
public static extern bool ChangeServiceConfig2A(
! IntPtr hService, InfoLevel dwInfoLevel,
[MarshalAs(UnmanagedType.Struct)] ref SERVICE_FAILURE_ACTIONS lpInfo);
[DllImport("advapi32.dll")]
public static extern int OpenServiceA(
int hSCManager, string lpServiceName, ACCESS_TYPE dwDesiredAccess);
Not sure if specifying the charset specifically matters much, but the first parameter needs to be changed from int to IntPtr in the ChargeServiceConfig2 functions.
These changes appeared to work on my machine, but I have not tested it anywhere else.
-- modified at 19:18 Saturday 22nd July, 2006
|
|
|
|

|
I'm using SharpDevelop Beta 3 to run the project and I'm not sure if it's the HotySoft code or SharpDevelop not setting the command line arguments correctly, but there's a better way to get the full file path of a running process.
In ServiceBase.cs on lines 76-78 and 91-93 you may want to replace those lines with the following:
string processPath = Process.GetCurrentProcess().MainModule.FileName;
if (processPath != null && processPath.Length > 0) {
System.IO.FileInfo fi = new System.IO.FileInfo(processPath);
|
|
|
|

|
This looks like a very nice system to use. Debugging services is difficult when you have to reinstall the service everytime.
However I dont understand the debugmode used in you ServiceProcess. How can I run the application as a real service? The debug property is readonly and always returns true if I build and run the app using debug or release mode.
It will log the start and initialise events, but I cannot run the service (Error 1053: The service did not respond to the start or control request in a timely fashion.).
So how do I switch to a real service from a 'fake' console app?
|
|
|
|

|
First of all after reading the article and looking at the source files : thanks for sharing this great code !
I downloaded the latest version (Rev3) from the hoytsoft.org website and compiled it in Release version on XP Pro with VS2003. I then ran the HoytSoft.Example.exe from the command line with the i argument to install it as a service. Using the Service Control Panel, I was able to start, pause, resume and stop the service.
However, the service did not write any entry at all in the Windows Event Log (I used the Windows Event Viewer to check it). Looking at the source code of the example service, I was expecting to see a lot of entries ...
What could I have done wrong ? Thanks for helping me out here !
|
|
|
|

|
Hi
First of all, 5 out of 5!!! The service base is awesome! To bad about my debug attribute not working, as I thought that is quite nice to have, atleast still works when you build in VS.
Whenever I try to pause or stop the service I get the following error.
Could not pasuse the service on your local computer. The service did not return an error. This could be an internal Windows error or an internal service error.
There's not much code in my servicer so far only logging to even viewer which is working.
When I click stop a second time it finally stops the service, only after it times out while stopping, but does stop.
Could you please lead me in the correct direction to resolve this issue.
Thanks
Quinton
|
|
|
|

|
Hi there!
First: Seems to be a great piece of code!
My problem is: I tried to use it (Windows XP Home SP2) and got nothing but an error.
When I first ran the service from within SharpDevelop, I got an error after some seconds (cause the service was running in the console-window). The service was installed anyway and I could also manipulate it from within the appropriate Manager (I have no idea how this one is called in English).
I then looked around in the source a bit...when I tried to run the .exe file in (bin/Debug) I get the following error:
"Application has genetated an exception that could not be handled.
Process id=0xe88, Thread id=0xedc (3804)"
and the app terminates.
What's the problem? (I do not have any idea about services in .NET at all...)
Greets - Soykaf
|
|
|
|

|
Nice article. Sure seems to be a lot simpler than trying to use the Visual Studio service installer that Microsoft discusses. Thanks for sharing.
I noticed that the code posted here has a copyright notice in ServiceBase.cs, but the same code posted on your website doesn't. I was considering using your code to make it easier to install an IP address monitoring service that I had written, but now I'm unsure.
What are the terms of your copyright ?
Is the code posted here a derivative work of the code on your website ? Does it remain un-copyrighted ?
Is only this one file in the project protected by your copyright ?
Steven J. Ackerman, Consultant
ACS, Sarasota, FL
http://www.acscontrol.com
http://spaces.msn.com/members/sjackerman
steve@acscontrol.com
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Sometimes the service classes provided by Visual Studio don't give you the control you need, so why not build your own? And while you're at it, why not make it self-installing? The base class provided gives you full control of the Win32 Services API from a convenient base class and attribute.
| Type | Article |
| Licence | CPOL |
| First Posted | 5 Oct 2005 |
| Views | 99,919 |
| Bookmarked | 86 times |
|
|