Delphi 2009 在 CreateServiceW 上崩溃(仅在 Windows 2008 R2 中)

发布于 2024-11-01 13:32:45 字数 966 浏览 14 评论 0原文

我有以下代码,它可以在除 Windows 2008 R2(SP0 和 SP1)之外的所有操作系统(32 和 64 位)上正常运行

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;

连接到远程 32 位计算机时会发生这种情况:

调试时delphi 在 CreateserviceW 行崩溃,并显示消息“应用程序定义的异常(代码 0x000006d1)在...进程停止”。 try/ except 周围的 createserviceW 没有任何区别。

当连接到远程 64 位计算机时,一切正常!

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 exception (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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌辣 2024-11-08 13:32:45

该错误在 Microsoft SBS Server 2011 上也很明显。

您遇到的问题似乎与海拔有关,您没有在具有正确海拔的用户范围内运行应用程序。

您是否尝试过向应用程序添加清单以确保其正确提升,此外,出于测试目的,您可能希望编译应用程序(调用者)并使用管理员的凭据运行。

需要注意的是,Microsoft Windows 2008 和 2011 存在范围限制,即您无法与比您级别更低或更高的进程或服务进行交互。这个安全功能引起了很多头痛。

因此,如果您海拔,请尝试没有海拔。

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.

感情洁癖 2024-11-08 13:32:45

对 CreateService 的调用会生成对 RCreateServiceW 或 RCreateServiceWOW64。 RPC 调用返回 0x000006d1,它代表 RPC_S_PROCNUM_OUT_OF_RANGE,这意味着底层 RPC 层失败(请求的 opnum 不存在)。这可能是一个错误...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文