|
-
September 27th, 2006, 03:15 AM
#1
NT Service wont stop / kill gives access denied
Hi,
I have written an NT service that works fine on most machines, but not on a particular Windows Server instance.
When I attempt to stop the service, i get an error saying the service wasn't stopped properly due to an error.
When I attempt to kill the service process manually, I get "access denied", despite beeing Administrator both during install and when trying to kill it (!) The service runs under the Local System account.
The service uses Sybase database client libs and use files and timer, but as I said - it works on "all" machines but one.
Ideas would be greatly appreciated.
Thanks,
sr
-
September 27th, 2006, 04:08 AM
#2
Re: NT Service wont stop / kill gives access denied
Did you try this under Admin user's context ?
Regards,
Ramkrishna Pawar
-
September 27th, 2006, 04:31 AM
#3
Re: NT Service wont stop / kill gives access denied
 Originally Posted by Krishnaa
Did you try this under Admin user's context ?
Yes, that's the reason I'm so puzzled - I would expect the admin user to be able to kill processes. This is all very strange.
-
September 27th, 2006, 04:37 AM
#4
Re: NT Service wont stop / kill gives access denied
You must up your kill app Privilege as a debugger.
Code:
EnableDebugPrivilege(BOOL bflag)
{
HANDLE hProcess;
HANDLE hToken;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
if(hProcess)
{
if(OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken))
{
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);
tp.Privileges[0].Attributes = bflag ? SE_PRIVILEGE_ENABLED : 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
CloseHandle(hToken);
}
CloseHandle(hProcess);
}
}
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 27th, 2006, 04:41 AM
#5
Re: NT Service wont stop / kill gives access denied
Not sure if I understand, pengch. This is production, release code. The problem has occured on one of many, many machines.
I try to stop/kill the service as an adminstrator user, not programmatically.
Do you think "upping" the priv level in the SERVICE STOP handler will help?
-
September 27th, 2006, 04:53 AM
#6
Re: NT Service wont stop / kill gives access denied
How did you to kill the service? Using taskmanag?
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 27th, 2006, 09:39 AM
#7
Re: NT Service wont stop / kill gives access denied
 Originally Posted by wincoder
I have written an NT service that works fine on most machines, but not on a particular Windows Server instance.
When I attempt to stop the service, i get an error saying the service wasn't stopped properly due to an error.
When I attempt to kill the service process manually, I get "access denied", despite beeing Administrator both during install and when trying to kill it (!) The service runs under the Local System account.
You definitely must concentrate on the prob in bold. Killing services is very, very, very bad idea.
Best regards,
Igor
-
September 28th, 2006, 12:35 AM
#8
Re: NT Service wont stop / kill gives access denied
I go with Igor. Killing is not the ultimate solution. You should be able to stop the service properly.
-
September 28th, 2006, 02:49 AM
#9
Re: NT Service wont stop / kill gives access denied
"You definitely must concentrate on the prob in bold. Killing services is very, very, very bad idea."
Look - the fact that I can't even kill the service was mentioned since it may well be a lead to the real problem. It is obvious that one shouldn't kill services, just like you shouldn't kill other apps unless absolutely necessary.
The question is still: Why on earth can't I kill the service - which is really just another process - when I'm on the administrator account (using the task manager).
-
September 28th, 2006, 03:08 AM
#10
Re: NT Service wont stop / kill gives access denied
May be the local security policy prevents to do that. Try killing other services that run on local system account.
-
September 28th, 2006, 05:34 AM
#11
Re: NT Service wont stop / kill gives access denied
 Originally Posted by wincoder
Look - the fact that I can't even kill the service was mentioned since it may well be a lead to the real problem.
Yes, the fact you don't understand why your attempt to kill service had failed indeed may lead to a real problem. 
It is obvious that one shouldn't kill services, just like you shouldn't kill other apps unless absolutely necessary.
Glad you understand this. It would be one more thing to understand - the service which is prone to be uncontrollable must be run on the problem machine only for developers' sake, and developers must do their best to eliminate the problem asap. And first thing they must to learn is how to actually kill a service process instead of been stuck on their admired Administrator account. 
The question is still: Why on earth can't I kill the service - which is really just another process - when I'm on the administrator account (using the task manager).
Sorry, but highlighted assertion is false. The service is not just another process - because it's the process running in special window station with restricted access permissions, unless it's not running in "interact with desktop" mode. 
Unfortunately pengch's message didn't helped in my tests - the debug privilege becomes held but PROCESS_TERMINATE access query is rejected.
I never messed with service murdering, so if I'll have some time to get a solution I'll let you know about the results.
PS. The most simple way I believe would be a special service process killing a required service process on behalf of user client process. Looks not so elegant, I admit this, but this must do work, I hope.
Best regards,
Igor
-
September 29th, 2006, 03:32 AM
#12
Re: NT Service wont stop / kill gives access denied
 Originally Posted by Igor Vartanov
Sorry, but highlighted assertion is false. The service is not just another process - because it's the process running in special window station with restricted access permissions, unless it's not running in "interact with desktop" mode.
I *am* running in "interact with desktop" mode.
-
September 29th, 2006, 03:47 AM
#13
Re: NT Service wont stop / kill gives access denied
 Originally Posted by Igor Vartanov
Unfortunately pengch's message didn't helped in my tests - the debug privilege becomes held but PROCESS_TERMINATE access query is rejected.
I didn't understand why Igor Vartanov so said. I maked a tool name killprocess which used debug privilege can kill service. you can download it form our website.
http://www.autodebug.com/download/processkill.zip
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 29th, 2006, 06:08 AM
#14
Re: NT Service wont stop / kill gives access denied
 Originally Posted by pengch
I didn't understand why Igor Vartanov so said. I maked a tool name killprocess which used debug privilege can kill service.
Bad news for you, man. Your tool fails to kill services on my Win2003 Server SP1.
Best regards,
Igor
-
September 29th, 2006, 06:10 AM
#15
Re: NT Service wont stop / kill gives access denied
 Originally Posted by wincoder
I *am* running in "interact with desktop" mode.
As I had found out "interact with desktop" helps in no way in service killing.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|