Reputation: 103
Below is the C++ code where I am running powershell script. The script is running fine but after the script is completed it is asking to press any key in command prompt.
c++
void main()
{
string strPath = "D:\Share\Mail.ps1";
system("powershell -ExecutionPolicy Bypass -F D:\\Share\\Mail.ps1");
executeFile();
}
Powershell:
$SmtpServer = 'smtp.server.net'
$SmtpPort = '2525'
$SmtpUser = 'test'
$smtpPassword = '**********'
$MailtTo = '[email protected]'
$MailFrom = '[email protected]'
$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.
Upvotes: 1
Views: 290
Reputation: 69
Add #include <Windows.h>
at the begining of your main.cpp
and at the end of your Main
function, add:
HWND wnd = GetConsoleWindow();
ShowWindow(wnd, 0);
Upvotes: 1