Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Powershell via Visual C++ (API)

I'd like to write a program that effectively "pipes" Powershell, so that I can send commands and parse the responses in C++, without actually opening the prompt on the screen.

Any tips?

like image 526
Disco Avatar asked Jan 06 '11 03:01

Disco


People also ask

Does Visual Studio support PowerShell?

Visual Studio Code with the PowerShell extension is the recommended editor for writing PowerShell scripts. It supports the following PowerShell versions: PowerShell 7.0 and higher (Windows, macOS, and Linux)

How do I go to C directory in PowerShell?

The Windows PowerShell prompt opens by default at the root of your user folder. Change to the root of C:\ by entering cd c:\ inside the Windows PowerShell prompt.


1 Answers

You can certainly do this but you'll need to use managed code as PowerShell's architecture is based entirely on the CLR object model.

I'm not sure of the C++ syntax but you can start with the PowerShell class in System.Management.Automation.dll and use its static Create method to create an instance to which you can pipe data and run commands.

like image 169
Josh Avatar answered Oct 20 '22 01:10

Josh