C ShellexeCuteex不会通过未从该EXE产生输出来执行参数

C++ ShellExecuteEx does not execute exe with parameter by not generating output from that exe

本文关键字:EXE 输出 参数 执行 ShellexeCuteex      更新时间:2023-10-16

在过去的几天或几周中。在Visual Studio C 中,我很难使用ShellExecuteEx()试图在EXE内运行带有一个参数的EXE。发生的方式是我在Visual Studio(甚至在外面(运行调试程序。该程序将启动另一个程序,并且可以成功运行,但是它不会生成.txt文件输出。我不确定是否正确使用了该参数。这是我要实现的步骤:

  1. start navenest.exe (将打开ScreenCapture.exe的EXE(
  2. cmd屏幕-MAINTAREST.EXE启动并准备使用ShellexeCuteex启动ScreenCapture.exe
  3. uac弹出,作为管理员运行
  4. 新的CMD屏幕-ScreenCapture.exe从参数和目录开始
  5. screencapture.exe完成命令并关闭
  6. capturetext.txt由screencapture.exe生成的exe与screencapture.exe。

问题是我在目录中没有获得capturetext.txt或任何证明参数在此程序中工作的证据。

现在,如果我在不使用test.exe的情况下运行screenCapture.exe,则可以使用test.exe,它可以工作并生成.txt文件。

这是代码:

#include "stdafx.h"
#include <isostream>
#include <fstream>
#include <string>
#include <Windows.h>
int main()
{
    auto str = _T("C:\UsersEngrskyPicturesScreenshot.png ScreenCapture -l eng")
    SHELLEXECUTEINFO shExInfo = {0};
    shExInfo.cbSize = sizeof(shExInfo);
    shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    shExInfo.hwnd = 0;
    shExInfo.lpVerb = _T("runas");                
    shExInfo.lpFile = _T("C:/Program File (x86)/Test/ScreenCapture.exe");           
    shExInfo.lpParameters = str;                  
    shExInfo.lpDirectory = 0;
    shExInfo.nShow = SW_SHOW;
    shExInfo.hInstApp = 0;  
}

示例:使用Just Command提示符,ScreenCapture.exe与参数完美搭配。我这样输入了:

Adminstrator:命令提示

C:Program File (x86)Test> ScreenCapture "C:\UsersEngrskyPicturesScreenshot.png ScreenCapture -l eng"

然后,它将成功运行并编写一个名为ScreenCapture.txt

的输出文件

但是,当我尝试使用我制作的exe(此文件(进行运行时。我无法生成输出。

来自ShellExecuteEx函数的MSDN文档,您首先需要初始化com。该示例使用:

    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);