调试 Windows 服务并尝试查看它所看到的内容

发布于 2024-09-27 08:49:23 字数 2169 浏览 0 评论 0原文

我们目前有一个自动化系统,作为处理卫星图像的服务运行。该服务维护一个配置文件,在配置文件中我们应用某些脚本(python)将输入卫星图像转换为更可用的格式。脚本调用所需的应用程序来进行转换过程。脚本本身由服务通过系统(“命令”)(用 c/c++ 编写)调用。 (该服务使用与用户相同的帐户)。

我们目前正在尝试添加对另一种卫星图像格式的支持,转换器是来自 ERDAS Imagine(importavhrr) 的商业 .exe,(我们在脚本中执行了几个自己的步骤来更改投影)。

该脚本工作正常,直到遇到以下

argslist = ['importavhrr.exe', '-in', '%s' % infn, '-out', '%s' % tmpimg1, '-gui', 'FALSE', '-correct', '-flyingheight', '833', '-rect', 'gcp', gcpfn]
print "".join(argslist)
p = subprocess.Popen(argslist, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
print str(p.communicate())

情况: 现在最终发生的是,importavhrr.exe 只是坐在那里,什么也不做(根据任务管理器,它坐在那里,使用 0 cpu 使用率,并且内存使用量永远不会改变)。就好像它在等待某种用户输入一样。 (尝试 os.system、os.spawnv 都会产生相同的结果)我猜测某种 gui 元素是以太弹出的,带有某种 gui 窗口。从任务管理器关闭进程,将控制权返回给 python。

注意:-gui FALSE/false/0 参数应该防止 gui 弹出。但是,如果数据不好(我通过损坏数据并通过脚本调用来手动测试这一点),则会弹出一个错误窗口,显示结果。

当我手动运行脚本(相同的文件,相同的工作目录)时,它工作得很好......当我使用相同的系统函数(其内部库的一部分)作为服务手动调用它时,该脚本甚至可以工作。

此外,使服务仅使用 importavhrr.exe 和环境变量调用批处理文件也会导致 importavhrr.exe 挂起。

侧面服务: - 使用与我登录时相同的用户帐户 - python脚本为ERDAS设置了大约30-40个环境变量 - 所有环境变量均已正确设置(首次运行脚本时转储环境变量,并将它们与打印消息时得到的内容进行比较) - 将环境变量传递到 subprocess.Popen() 会产生相同的结果 - 该公司拒绝帮助我们,因为他们不支持从命令行运行程序(但是当用户这样做时它工作正常,只是不是服务) - 在调试模式下运行服务工作正常。 - 我已经重新启动了机器。

我在这里不知所措,我认为(并且担心)ERDAS 可执行文件正在弹出某种错误消息窗口,但是我已经看了又看,但找不到任何方式来查看服务所看到的内容。我已经尝试解决这个问题近一周了,所以是的。

编辑

我抓住了推荐的 Process Explorer,然后查看堆栈线程,我看到了:

<snip ntoskrnl calls>
ntdll.dll!KiFastSystemCallRet
ntdll.dll!RtlSetLastWin32ErrorAndNtStatusFromNtStatus+0x301
kernel32.dll!GetModuleHandleA+0xdf

等待几分钟后,它变成了这样:

<snip ntoskrnl calls>
ntdll.dll!KiFastSystemCallRet
USER32.dll!ScrollWindowEx+0x121d
USER32.dll!SoftModalMessageBox+0x6f8
USER32.dll!MessageBoxTimeoutW+0x1d9
USER32.dll!MessageBoxTimeoutW+0x5b
USER32.dll!MessageBoxTimeoutA+0x9c
USER32.dll!MessageBoxExA+0x1b
USER32.dll!MessageBoxA+0x45
elib.dll!esmg_GetLocalTapesDB+0x23b
elib.dll!esmg_LogMessageFunc+0x13a

嗯,我想它正在尝试显示一个窗口。我对他们的行为一无所知,无法了解是什么导致 esmg_LogMessageFunc 崩溃。该功能是他们的开发工具的一部分,我对其的访问权限为 0。此外,我从未真正见过 erdas 记录任何内容。

We currently have an automated system that runs as a service for processing satellite images. This service maintains a configuration file, in the configuration file we apply certain scripts(python) to covnert the input satellite imagery into a more usable format. The scripts call the required applications, for the conversion proces. The scripts themselves are invoked by the service via the system("command") (its written in c/c++). (the service uses the same account as the user).

We currently are trying to add support for another satelitte imagery format, the converter is a commerical .exe from ERDAS Imagine(importavhrr), (we do several of our own steps after in the script to change the projection).

The script works fine, up until it hits this:

argslist = ['importavhrr.exe', '-in', '%s' % infn, '-out', '%s' % tmpimg1, '-gui', 'FALSE', '-correct', '-flyingheight', '833', '-rect', 'gcp', gcpfn]
print "".join(argslist)
p = subprocess.Popen(argslist, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
print str(p.communicate())

What ends up happening now is, importavhrr.exe just sits there, and does nothing(according to taskmanager it sits there using 0 cpu usage, and the memory usage never changes). As if its waiting for some sort of user input. (Trying os.system, os.spawnv both yield same results) I am guessing some sort of gui element is ether popping up with a gui window of sorts. Closing the process from task manager, returns control to python.

Note: The -gui FALSE/false/0 argument is supposed to prevent a gui from poping up. However if the data is bad (i tested this manually by corrupting the data, and invoking via a script) an error window will popup showing the results.

When i run the script manually (same file, same working directory), it works fine.... the script even works when i invoke it manually using the same system function (its part of an inhouse library) as the service.

Also making the service invoke a batch file with just the importavhrr.exe and the enviroment variables also results in the importavhrr.exe hanging.

Service Sidewise:
- Uses the same user account as the one i logged in with
- The python script sets around 30-40 envrioment variables for ERDAS
- All the enviroment variables are properly set(dumping the enviroment variables when the script is first run, and comparing them to what i get when i print the messages)
- Passing the enviroment variables into the subprocess.Popen() yields the same results
- The company refuses to help us because they don't support running programs from command line (however it works fine when a user does it, just not a service)
- Running the service in debug mode works fine.
- I HAVE rebooted the machine.

I am at a loss here, i think (and fear) that the ERDAS executable is making some sort of error message window popup, however i have looked, and looked and can't find any sort of way to see what the service sees. I have been trying to figure this out for almost a week now so yeah.

EDIT

I grabbed the recommended Process Explorer, and looking at the stack thread i have this:

<snip ntoskrnl calls>
ntdll.dll!KiFastSystemCallRet
ntdll.dll!RtlSetLastWin32ErrorAndNtStatusFromNtStatus+0x301
kernel32.dll!GetModuleHandleA+0xdf

After waiting a few minutes, it changes to this:

<snip ntoskrnl calls>
ntdll.dll!KiFastSystemCallRet
USER32.dll!ScrollWindowEx+0x121d
USER32.dll!SoftModalMessageBox+0x6f8
USER32.dll!MessageBoxTimeoutW+0x1d9
USER32.dll!MessageBoxTimeoutW+0x5b
USER32.dll!MessageBoxTimeoutA+0x9c
USER32.dll!MessageBoxExA+0x1b
USER32.dll!MessageBoxA+0x45
elib.dll!esmg_GetLocalTapesDB+0x23b
elib.dll!esmg_LogMessageFunc+0x13a

Well it is trying to show a window, i presume. I don't know anything about their behaviour to see what could be causing esmg_LogMessageFunc to crash. That function is part of their dev tools, which i have 0 access to. Furthermore i have never actually seen erdas log anything.

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

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

发布评论

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

评论(3

奈何桥上唱咆哮 2024-10-04 08:49:23

尝试使用任何假定访问窗口站的 Windows API 调用都会导致服务的安全上下文出现问题。

您可以使用 Sysinternals 中的多个工具来诊断此类问题。具体来说,请考虑使用 Process Explorer 代替任务管理器,并且进程监视器,用于跟踪特定进程的活动。

编辑:他们的新ProcDump工具可以是用于通过真正强大的触发来获取任何进程的核心转储。 Mark Russinovich 的博客 上的一些最新战争故事利用 ProcDump发现到底发生了什么。

为了完整起见,此知识库文章对用于调试服务的“官方”工具进行了很好的概述。

Trying to use any Windows API calls that assume access to the windowstation will cause problems in the security context of a service.

You can use several of the tools from Sysinternals to diagnose this kind of thing. Specifically, consider using Process Explorer in place of Task Manager, and Process Monitor for tracing the activity of a specific process.

Edit: Their new ProcDump tool can be used to get a core dump of any process with really powerful triggering. Several of the latest war stories on Mark Russinovich's Blog take advantage of ProcDump to discover what really happened.

For completeness, a good overview of "official" tools for debugging a service is at this KB article.

满天都是小星星 2024-10-04 08:49:23

您是否尝试允许该服务与桌面交互,登录计算机并检查是否确实弹出错误框?

Did you try to allow the service to interact with the desktop, log into the machine and check if an error box is actually popping up?

南七夏 2024-10-04 08:49:23

您可能需要从 Process Explorer 开始。您可以看到线程和这些线程的堆栈。如果您确实认为有一个打开的窗口,您可能会在堆栈底部看到它。

kernel32.dll!RegisterWaitForInputIdle+0x49

如果这不起作用,我会获取该进程的完整内存转储,然后使用 WinDBG 来查看它在做什么。

You might want to start with Process Explorer. You can see the threads and the stacks for those thread. If you really think there's an open window you'll likely see this at the bottom of the stack

kernel32.dll!RegisterWaitForInputIdle+0x49

If that doesn't work out I'd then get a Full Memory Dump of the process and then use WinDBG to see what its doing.

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