路径和CreateProcess [英] Paths and CreateProcess

查看:147
本文介绍了路径和CreateProcess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于我滥用CreateProcess的症状的问题。我使用lpcommandline参数来提供我的可执行文件和参数的路径。我的误用是,我没有用引号包围exe的路径。



我的问题是,为什么CreateProcess在大多数计算机上正常工作,而不是其他人?我知道路径将在大部分时间有一个空间,但在90%的XP机器上它的工作原理。我当然发现我的问题在那些10%,它没有。但我想知道什么是不同的机器上,它不工作?有没有一个设置或一个政策,你们任何人都知道。是的,我要解决的报价问题。只是好奇为什么这样的东西不会只是失败了蝙蝠。



所以代码看起来像下面的样子,szCommandLine参数将是下面的样子。注意到exe路径的引号。



C:\Program Files\ My Company\doit.exe parameter1 parameter2

  CreateProcess(
NULL,
szCommandLine,
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
& si,
& pi)


解决方案

作为文档Martin York链接到暗示,CreateProcess()有一些与pre-long-name程序的back-compat的行为。



c:\program files\sub dir \program name arg1 arg2将查找:



< blockquote>

 c:\program.exefiles\sub dir \program name arg1 arg2 
c:\program files\\ \\ sub.exedir \program name arg1 arg2
c:\program files\sub dir\program.exename arg1 arg2
c:\program files\sub dir \program name.exearg1 arg2


的这些文件存在,Windows会调用他们,而不是你的程序。此外,我假设如果你没有读访问任何文件夹这些可能的匹配是在,CreateProcess()可能会立即失败,而不是检查您是否已阅读到以后可能的匹配。 (默认情况下Windows检查只读访问权限的最终文件夹。)


I have a question regarding a symptom of my misuse of CreateProcess. I'm using the lpcommandline parameter to feed the path to my executable and parameters. My misuse is that I have not surrounded the path to the exe with quotes.

My question is, why does the CreateProcess work just fine on most computers and not others? I know that the path will have a space in most of the time, yet on 90% of XP machines it works. I of course found out my issue on those 10% where it did not. But I'm wondering what is different on the machines where it does not work? Is there a setting or a policy that any of you folks know about. And yes, I am going to fix the quote issue. Just curious about why something like this would not have just failed off the bat.

So the code would look something like below and the szCommandLine Parameter would be something like below. Notice no quotes around the path to the exe.

"C:\Program Files\My Company\doit.exe parameter1 parameter2"

CreateProcess(
	NULL,			
	szCommandLine,  
	NULL,			
	NULL,			
	FALSE,			
	NULL, 
	NULL,  
	NULL,			
	&si,			
	&pi )

解决方案

As the document Martin York linked to hinted, CreateProcess() has some behaviour for back-compat with pre-long-name programs.

"c:\program files\sub dir\program name arg1 arg2" will look for:

"c:\program.exe" files\sub dir\program name arg1 arg2
"c:\program files\sub.exe" dir\program name arg1 arg2
"c:\program files\sub dir\program.exe" name arg1 arg2
"c:\program files\sub dir\program name.exe" arg1 arg2

So if any of these files exist, Windows will to call them, not your program. Also, I would assume if you did not have read access to any of the folders these possible matches are in, CreateProcess() may fail out immediatly, instead of checking if you have read to the later possible matches. (Windows by default checks read access only the final folder.)

这篇关于路径和CreateProcess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆