简体   繁体   中英

How to run PS1(powerShell Script) files with C++

I am making a toast notification apear, but when the script runs it just closes the powershell like if it ran it but no noticfication apears. How could I make it work?

#include<iostream>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <cstdlib>
using namespace std;


void main()
{
       string strPath = "d:\\callPowerShell.ps1";
              system("start powershell.exe d:\\callPowerShell.ps1");
}

It would recall the file and run it on PowerShell

Some time ago I made an app in C++Builder and I did something like that for made a backup in MariaDB. The code I used was something like this:

    UnicodeString usMysqldump, usCmd;

usMysqldump = "In my case path to mysqldump.exe";
usCmd = "Script to be executed";

ShellExecuteW( Application->Handle, "open", usMysqldump, usCmd, NULL, SW_HIDE  );

PD: SW_HIDE is for keep the console hide, may be you want something diferent.

Try this code and I hope it be helpfull for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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