【问题标题】:Perform silent installation programmatically using C++使用 C++ 以编程方式执行静默安装
【发布时间】:2015-07-24 09:59:18
【问题描述】:

我有一个应用程序的安装程序,比如 app_installer.exe。我可以使用app_installer.exe /S 将它从cmd 静默安装到我的系统中。现在我需要从 Windows 服务中执行相同的操作,并在 MSVS 2013 中为此创建了一个服务应用程序。我尝试通过以下方式使用CreateProcess()

if (CreateProcess(NULL,"E:\\app_installer.exe \S",NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo, &ProcessInfo))
    {
        myfile << "Wait for object...\n";
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
    myfile << "Handles closed\n";

    }
    else
    {
        myfile << "The process could not be started...\n";
        myfile << GetLastError();
    }

虽然CreateProcess(我也尝试过 /SD,/silent,/q,/qn 而不是 /S)返回一个非零值,但我的应用程序没有安装。 然后我在我的代码中添加了以下行:

system("E:\\app_installer.exe \S \norestart);

在添加这一行时,启动service后,它询问我是否从服务中view the message,当我点击View message时,安装向导来了..但是,它不是无声的......

是不是我传递的参数有问题?如何在 C++ 中进行静默安装?

【问题讨论】:

  • 你需要用另一个反斜杠来转义你的反斜杠字符。
  • @Galik:在 CreateProcess 还是系统中?
  • 在所有字符串文字中,除非您使用 C++11 原始字符串文字。
  • 尝试:"E:\\app_installer.exe \\S \\norestart""E:/app_installer.exe /S /norestart"(Windows 也应该接受正斜杠)。
  • 另外,您是否尝试过交互式命令行中的/S /norestart?也就是说,您确定安装程序实际上接受/norestart 作为标志吗?

标签: c++ visual-studio windows-services exe silent-installer


【解决方案1】:

请检查下面的 STARTUPINFO 结构成员“StartupInfo.wShowWinodw”并重新尝试..

STARTUPINFO StartupInfo;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_HIDE; //Set this flag to hide windows while create process.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多