相关疑难解决方法(0)

如何在Delphi中调用CreateProcess?

根据MSDN的文档CreateProcess示例,我正在尝试调用CreateProcess:

var
   commandLine: string;
   si: TStartupInfo;
   pi: TProcessInformation;
begin
   commandLine := 'C:\Windows\System32\cmd.exe';

   si := Default(TStartupInfo);
   si.cb := sizeof(si);

   CreateProcess(
        PChar(nil),         //no module name (use command line)
        PChar(commandLine), //Command Line
        nil,                //Process handle not inheritable
        nil,                //Thread handle not inheritable
        False,              //Don't inherit handles
        0,                  //No creation flags
        nil,                //Use parent's environment block
        PChar(nil),         //Use parent's starting directory
        si,                 //Startup Info
        pi                  //Process Info
   );
Run Code Online (Sandbox Code Playgroud)

呼叫因访问冲突而崩溃:

在0003B77B模块kernel32.dll中的EAccessViolation异常.
模块'kernel32.dll'中地址为7671B77B的访问冲突.写地址00B47EA6.

现在我理解为什么它会让我崩溃,但我不明白为什么它不会崩溃MSDN上的示例代码,我也不明白为什么它没有为你失败大卫. …

delphi winapi delphi-xe6

5
推荐指数
1
解决办法
1万
查看次数

路径和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 )       
Run Code Online (Sandbox Code Playgroud)

c++ winapi

2
推荐指数
1
解决办法
8922
查看次数

标签 统计

winapi ×2

c++ ×1

delphi ×1

delphi-xe6 ×1