Delphi 2009 Crashes on CreateServiceW (only in windows 2008 R2)
I have the following code which runs fine on all operating systems (32 & 64 bit) except for Windows 2008 R2 (SP0 & SP1)
fSvcMgr := OpenSCManagerW(PwideChar(FOptions.ComputerName), nil,
SC_MANAGER_ALL_ACCESS);
if fSvcMgr = 0 then
begin
iserror := true;
RaiseLastWin32Error;
end;
...
fSvc := OpenServiceW(fSvcMgr, pwidechar(Service_name),SERVICE_ALL_ACCESS);
if fSvc = 0 then
begin
fSvc := CreateServiceW(fSvcMgr,
pwidechar(Service_name),
pwidechar(Service_name),
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE,
pwidechar(fServiceName), nil, nil, nil, nil, nil);
if fSvc = 0 then
begin
iserror := true;
RaiseLastWin32Error;
end;
end;
This happens when connecting to a remote 32 bit machine:
While debugging delphi crashes on the CreateserviceW line with message 'Application-defined exce开发者_如何学运维ption (code 0x000006d1) at ... process stopped. try/except around the createserviceW doesn't make any difference.
When connecting to a remote 64 bit machine everything works fine!
The error is also apparent on Microsoft SBS Server 2011.
The problem your experiencing seems to be based on elevation, you are not running the application in the scope of a user with the correct elevation.
Have you tried adding a manifest to your application to ensure it is correctly elevated, in addition for the purpose of testing you may wish to compile the application (caller) and run with the credentials of an administrator.
Its important to note that Microsoft Windows 2008 and 2011 have a scope limitation, where as you can not interact with a process, or service at a lesser or greater level than yourself. This security feature has caused many headaches.
As such, if you have elevation, try without.
The call to CreateService generates an RPC call to either RCreateServiceW or RCreateServiceWOW64. The RPC Call returns you 0x000006d1 which stands for RPC_S_PROCNUM_OUT_OF_RANGE and it means that the underlying RPC layer fails (the requested opnum doesn't exist). It could be a bug...
精彩评论