【问题标题】:Execute an external exe with sw_hide使用 sw_hide 执行外部 exe
【发布时间】:2018-03-28 18:56:23
【问题描述】:

如何在没有 cmd.exe 控制台的情况下使用模式(系统)和参数 sh_hide 执行外部 exe?

#include <stdio.h> // C library to perform Input/Output operations 
#include <tchar.h>
#include <stddef.h> // C Standard definitions 
#include <iostream> // Input/Output
#include <fstream>
#include <cstdlib>
#include <windows.h>

int main()
{
    system("C:\\Users\\%USERNAME%\\AppData\\Roaming\\Microsoft\\mmd.exe"); 
}

【问题讨论】:

    标签: c++ execute dev-c++ shellexecute


    【解决方案1】:

    使用ShellExecuteExShellExecute Win32 API,而不是system()

    【讨论】:

    • 我不能使用 shellexecute 因为与 %username% 不兼容
    • 还有其他 API-s 像 ExpandEnvironmentStringsForUser 来扩展 %username%。除非您需要可移植代码,否则使用 system 不是一个好主意。但是像C:\Users\%USERNAME%\AppData 这样的路径离“便携”太远了。
    • Vabbovabboovavv
    猜你喜欢
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    相关资源
    最近更新 更多