Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2002, 11:22 AM
Markv Markv is offline
Junior Member
 
Join Date: May 2002
Posts: 11
Default NT service startup - access is denied

This is not specifically a Delphi problem, just happens when I try to start up a Delphi service on NT 4. The service is a simple fax receiving service. It installs fine but it will not start up using the system account. I have to use the administrator account in order to start it. I suspect the server settings but do not know where to start.
Thanks.
Mark

Markv
Reply With Quote
  #2  
Old 07-16-2002, 02:25 PM
marathonfool marathonfool is offline
Junior Member
 
Join Date: Jul 2002
Posts: 1
Default RE: NT service startup - access is denied

Mark,

If you don't want to use the administrator account
the account that is being used to start the service needs
the following Local Security Policy Rights assignments.
The steps to open the user rights assignment in
Win2000/XP are:
- Open the control panel
- Open the Administrative tools
- Open the Local Security Policy
- Open the User Rights Assignment
I know in NT 4.x the Local Policies are in the Admin.
Tools off the Start Menu, but forget the details.
The account needs to be added to the following user
rights:
- Act as part of the operating system
- logon as batch job
- log on as service

I suggest using the Windows API ImpersonateLoggedOnUser
function with a local account with the rights described
above.

Here is a procedure to login and impersonate the local
account:

uses Windows;
.
.
.
procedure LocalLogonUser(fLogonHandle: THandle;
var fusername, fpassword,
fDomainName, fErrMessage: string);
var
Len: DWORD;
Token: THandle;
TokenPriv: TTokenPrivileges;
OldTokenPriv: array[0..999] of TTokenPrivileges;
mLuid : TLargeInteger;
begin
if (fLogonHandle <> 0) then begin
RevertToSelf;
CloseHandle(fLogonHandle);
fLogonHandle := 0;
end;
fErrMessage := '';

if not(LookupPrivilegeValue(Nil, 'SeTcbPrivilege',
mLuid)) then begin
fErrMessage := SysErrorMessage(GetLasterror);
exit;
end;

if not(OpenProcessToken(GetCurrentProcess,
TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY,
Token)) then begin
fErrMessage := SysErrorMessage(GetLasterror);
exit;
end;
TokenPriv.PrivilegeCount := 1;
TokenPriv.Privileges[0].Luid := mluid;
TokenPriv.Privileges[0].Attributes :=
SE_PRIVILEGE_ENABLED;

fillchar(OldTokenPriv, sizeof(OldTokenPriv), 0);
if not(GetTokenInformation(Token, TokenPrivileges,
@OldTokenPriv[0],
1000 * sizeof(TTokenPrivileges), Len)) then begin
fErrMessage := SysErrorMessage(GetLasterror);
exit;
end;
if not(AdjustTokenPrivileges(Token, False, TokenPriv,
1000 * sizeof(TTokenPrivileges), OldTokenPriv[0],
Len)) then begin
fErrMessage := SysErrorMessage(GetLasterror);
exit;
end;
if not (GetLasterror = ERROR_SUCCESS) then begin
fErrMessage := SysErrorMessage(GetLasterror);
exit;
end;
if not(LogonUser(pchar(fusername), pchar(fDomainName),
pchar(fpassword),
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
fLogonHandle)) then
fErrMessage := SysErrorMessage(GetLasterror)
else
if not(ImpersonateLoggedOnUser(fLogonHandle)) then
fErrMessage := SysErrorMessage(GetLasterror);
end; {procedure}

I recommend the SVCom package from Alexey Dynnikov
http://www.aldyn.ru/ to create NT service code.
He has made the steps very easy!

Note: A good source of delphi forum information is at
www.mers.com However, they have been down today.
(7/16/2002)

Best Regards,

Dave
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:27 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.