-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutePowershellScript
35 lines (32 loc) · 975 Bytes
/
ExecutePowershellScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once
#include <fstream>
#include <vector>
#include <Windows.h>
#include <string>
namespace Mail
{
const std::string &PowerShellScript = "Get-Service >> C:\\test\\1.txt";
int SendMail ()
{
bool ok;
std::string param = PowerShellScript;
// Let me
SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof (SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "open"; //I made change here
ShExecInfo.lpFile = "powershell"; // I made change here
ShExecInfo.lpParameters = param.c_str ();
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ok = (bool)ShellExecuteEx (&ShExecInfo);
if (!ok)
return -3;
WaitForSingleObject (ShExecInfo.hProcess, 7000);
DWORD exit_code = 100;
GetExitCodeProcess (ShExecInfo.hProcess, &exit_code);
return (int)exit_code;
} //I tested it ,it works . without needing to create a script file .
}