简体   繁体   English

在 c++ 中运行 powershell 脚本时如何隐藏按任意键继续

[英]How to hide press any key to continue when running powershell script in c++

Below is the C++ code where I am running powershell script.下面是我正在运行 powershell 脚本的 C++ 代码。 The script is running fine but after the script is completed it is asking to press any key in command prompt.该脚本运行良好,但脚本完成后,它要求在命令提示符下按任意键。

c++ c++

    void main()
    {
        string strPath = "D:\Share\Mail.ps1";      
        system("powershell -ExecutionPolicy Bypass -F D:\\Share\\Mail.ps1"); 
        executeFile();              

    }

Powershell: Powershell:

    $SmtpServer = 'smtp.server.net'  
    $SmtpPort = '2525'
    $SmtpUser = 'test'  
    $smtpPassword = '**********'  
    $MailtTo = 'test@gmail.com'
    $MailFrom = 'test@test.com'  
    $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser,                                 
                   $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force)
    $MailSubject = 'Alert : Breach Notification'
    $Body = 'Test'
    $MailCount=0
    $file = 'Test_10242019_5.20.txt'

    Send-MailMessage -To $MailtTo -from $MailFrom -Subject $MailSubject -Body $Body -Attachment 
             $file -SmtpServer $SmtpServer -Port $SmtpPort  -UseSsl -Credential $Credentials

Command prompt giving Press any key to continue.命令提示符按任意键继续。

How can I hide this cmd.我怎样才能隐藏这个 cmd。

Add #include <Windows.h> at the begining of your main.cppmain.cpp的开头添加#include <Windows.h>

and at the end of your Main function, add:并在您的Main function 末尾添加:

HWND wnd = GetConsoleWindow(); ShowWindow(wnd, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM