从 Windows 命令提示符运行可执行文件与从 Windows 资源管理器运行可执行文件有何区别?

发布于 2024-11-17 20:38:16 字数 587 浏览 3 评论 0原文

编辑:这是由于愚蠢。这是一个多显示器问题。只是从 cmd.exe 中我们总是在主监视器中打开,而从资源管理器中我们总是在辅助监视器中打开。感谢大家的帮助!

我们最近遇到了一个奇怪的错误。我们有一个 Qt + osg 应用程序,如果我们从资源管理器运行它,它的行为与从命令行运行它不同。从资源管理器运行是不可用的,而从命令行运行(或通过从资源管理器运行一个调用 .exe 的简单批处理文件)可以按预期工作。

我们怀疑环境变量,因为我们能想到的只有这些。但它在单行批处理文件中运行良好的事实似乎反驳了这一点。我对 Windows 不太熟悉,不知道它如何加载可执行文件的任何细微差别,也不知道在哪里可以找到答案。

还有其他差异可以解释这一点吗? Windows 是否在每种情况下加载不同的用户环境变量集?操作系统是 Windows XP Service Pack 3。

从资源管理器(双击 program.exe)运行时遇到的行为与驱动程序问题或不正确的 OSG 场景设置一致:图像伪影、闪烁和奇怪的颜色。

从 cmd.exe 运行相同的可执行文件(或双击仅包含一行的 .exe 旁边的 .bat 文件来运行 .exe)时所经历的行为是正确的、预期的行为:场景正确,没有闪烁, ETC。

EDIT: This is due to stupidity. It is a multiple monitor issue. It's just that from cmd.exe we always opened in the primary monitor, whilst from explorer, we always opened in the secondary. Thanks all for the help!

We hit a weird bug recently. We have a Qt + osg app that behaves differently if we run it from explorer than if we run it from a command line. Running from explorer is unusable, while running from command line (or by running from the explorer a simple batch file that calls the .exe) works as expected.

We suspect environment variables, because that's all we can think of. But the fact that it runs fine with a one line batch file seems to refute this. I'm not familiar enough with windows to know of any subtle differences in how it loads executables, nor where to look to find out.

Are there any other differences that could explain this? Does windows load different sets of user environment variables in each case? OS is Windows XP Service Pack 3.

The behavior experienced when running from explorer (double click program.exe) is consistent with a driver issue or improper OSG scene setup: image artifacts, flashing, and weird colors.

The behavior experienced when running the same executable from cmd.exe (or by double clicking a .bat file next to the .exe containing only a line to run the .exe) is the correct, expected behavior: the scene is correct, no flashing, etc.

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

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

发布评论

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

评论(4

神仙妹妹 2024-11-24 20:38:16

要排除潜在的库加载路径问题,请尝试使用点本地 DLL 重定向。

为此,在与可执行文件相同的目录中创建一个(空)文件,并为其指定与二进制文件相同的名称,但附加 .local 除外。即,如果您的二进制文件名为 yourbinary.exe,则将该文件命名为 yourbinary.exe.local。这将迫使 PE 加载程序首先在该目录中查找以解析 LoadLibrary 调用(其中包括通过系统 DLL 或通过 COM 间接加载的 DLL,无论涉及多少个间接级别。)放置尽可能多的支持 DLL(包括 Qt DLL)在该目录中。如果您使用 Qt 插件,还可以将 plugins 目录放在那里(或使用自定义 trolltech.conf。)

有关点本地重定向的更多详细信息 此处,例如

To rule out potential library load path issues, try using dot-local DLL redirection.

Towards that end, create an (empty) file in the same directory as your executable and give it the same name as your binary, except with .local appended. I.e., if your binary is named yourbinary.exe, name that file yourbinary.exe.local. That will force the PE loader to first look in that directory to resolve LoadLibrary calls (and that includes DLLs loaded indirectly via system DLLs or via COM, no matter how many indirection levels are involved.) Place as many supporting DLLs (including Qt DLLs) in that directory. If you're using Qt plugins, also place the plugins directory there (or use a custom trolltech.conf.)

More details on dot-local redirection here, for example.

哑剧 2024-11-24 20:38:16

该线程看起来可能可以回答您的问题:

http: //forum.soft32.com/windows/Start-Run-Command-Prompt-ftopict353085.html

简而言之,我认为它可能会在不同的地方寻找您的可执行文件,具体取决于您尝试使用哪种方法来运行它。也许您有 2 个不同的版本隐藏在资源管理器使用的某个地方,而不是您想要的版本?

This thread looks like it might have the answer to your question:

http://forum.soft32.com/windows/Start-Run-Command-Prompt-ftopict353085.html

In short, I think it might be looking for your executable in different places depending on which method you attempt to use to run it. Perhaps you have 2 different versions hiding somewhere that explorer uses instead of the one you want?

菊凝晚露 2024-11-24 20:38:16

你没有提供足够的细节,所以我只能给你一个笼统的答案。为了使用 QT 及其工具,您需要 2 个环境变量。 *QTDIR 和 PATH * 确保您已设置这些变量,说明如下。我从网站获取它们。另请参阅链接了解 Windows 上的部署。

设置 QTDIR 环境
变量。

1) 创建一个新的系统变量
称为:QTDIR
一个。右键单击我的电脑->属性->高级选项卡 ->
环境变量按钮
b.查找系统变量->新->输入“QTDIR” 2) 将值设置为:C:\your\Qt\directory(注意:否
尾随“\”字符!!!)

现在,将 QTDIR 添加到您的 PATH 中
变量。

1) 编辑你的 PATH 变量,添加到
它的结尾是“;”如果不是
已经到了最后。 2)现在添加:
%QTDIR%\bin;

示例:

之前
路径=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
后,
PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%QTDIR%\bin;

这将确保我们的 Qt
应用程序将能够找到
运行时的 Qt DLL 文件
它。

我希望这有帮助。

You have not given enough details so I will give you a general answer. In order to use QT and its tools you need 2 environment variables. *QTDIR, and PATH * Make sure you have these variables set instructions are below. I have taken them from this site. See also this link for deployment on windows.

Setup the QTDIR environmental
variable.

1) Create a new System variable
called: QTDIR
a. Right click on My Computer -> Properties -> Advanced Tab ->
Environment Variables button
b. Find System variables -> New -> Type in "QTDIR" 2) Set the value to: C:\your\Qt\directory (NOTICE: No
trailing '\' character!!!)

Now, add the QTDIR on to your PATH
variable.

1) Edit your PATH variable, add onto
the end of it a ';' if one isn't
already on the end. 2) Now add on:
%QTDIR%\bin;

Example:

Before
PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;
After,
PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%QTDIR%\bin;

That will make sure that our Qt
application(s) will be able to find
the Qt DLL files when you go to run
it.

I hope this helps.

灯角 2024-11-24 20:38:16

也许资源管理器启动可执行文件的方式与直接从控制台运行它的方式有所不同。我认为资源管理器使用 ShellExecuteShellExecuteEx 我怀疑从控制台或批处理文件执行应用程序会产生相同的效果。

我将创建一个测试应用程序,尝试一些 ShellExecute 变体并使用不同的参数来查看是否可以重现资源管理器行为,以便尝试诊断传递给 ShellExecute 的哪些参数可能会导致问题。

ShellExecuteEx 页面上有一个有趣的社区注释,可能适用,也可能不适用:
ShellExecuteEx 忽略当前输入桌面。它始终使用winsta0\default。相反,请使用 ShellExecute 或 CreateProcess。

我还会调查 AppCompatFlags 是否影响控制台执行应用程序(或查看是否已为您的应用程序设置了任何 AppCompatFlags)。

Perhaps there is a difference caused by the way Explorer launches an executable vs directly running it from the console. I think that Explorer uses ShellExecute or ShellExecuteEx and I doubt that executing an application from a console or batch file does the same.

I would create a test app that tries some of the ShellExecute variants and use different parameters to see if the Explorer behavior can be reproduced in order to try to diagnose what parameters passed to ShellExecute might be causing the problem.

There is an interesting community note on the ShellExecuteEx page that may or may not be applicable:
ShellExecuteEx ignores the current input desktop. It always uses winsta0\default. Instead use ShellExecute or CreateProcess.

I would also investigate whether or not AppCompatFlags affect console executed applications (or see if any AppCompatFlags have been set for your application).

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