run command Powershell lazarus / 34-Windows ---------------------------------------------------------------------- Ecsa · 2022-02-10 17:07 Hello everyone, I'm trying to execute the entire command line that you will see below via powershell. QuoteSet-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.c hocolatey.org/install.ps1')) Using this code but I don't have any favorable results. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ChocoPS:= T Process.Create(Form2);ChocoPS.Options:=[poUsePipes,poWaitOnExit,poNoCo nsole,poStderrToOutPut];ChocoPS.Executable:='PowerShell.exe';ChocoPS.P arameters.Add('Set-ExecutionPolicy Bypass -Scope Process -Force;');Cho coPS.Parameters.Add('[System.Net.ServicePointManager]::SecurityProtoco l = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;');ChocoPS.Parameters.Add('iex ((New-Object System.Net.WebClient) .DownloadString("https://community.chocolatey.org/install.ps1"))');Cho coPS.Active:=True;Memo1.Lines.LoadFromStream(ChocoPS.Output);ChocoPS.F ree;          Is there a way to execute the commands in question? ---------------------------------------------------------------------- marcov · 2022-02-10 21:58 Find the syntax how this would execute on the commandline with explicite a powershell invocation. Then convert that to tprocess code with a parameters.add for each word (space separated), except for quoted parts, pass them as a single parameters.add without quotes. ---------------------------------------------------------------------- BobDog · 2022-02-11 00:37 Does this work? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   function  system(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';  var s:ansistring='PowerShell.exe'+#13#10+'Set- ExecutionPolicy Bypass -Scope Process -Force;'+#13#10+'[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;'+#13#10+'iex ((New-Object System.Net.WebClient).DownloadString(" https://community.chocolatey.org/install.ps1"))';  begin writeln(s); w riteln; system(pchar(s));writeln('Done'); readln; end. ---------------------------------------------------------------------- Jurassic Pork · 2022-02-11 02:14 Hello, Quote from: Ecsa on February 10, 2022, 06:07:31 pmHello everyone, I'm trying to execute the entire command line that you will see below via powershell. QuoteSet-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.c hocolatey.org/install.ps1')) Using this code but I don't have any favorable results. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ChocoPS:= T Process.Create(Form2);ChocoPS.Options:=[poUsePipes,poWaitOnExit,poNoCo nsole,poStderrToOutPut];ChocoPS.Executable:='PowerShell.exe';ChocoPS.P arameters.Add('Set-ExecutionPolicy Bypass -Scope Process -Force;');Cho coPS.Parameters.Add('[System.Net.ServicePointManager]::SecurityProtoco l = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;');ChocoPS.Parameters.Add('iex ((New-Object System.Net.WebClient) .DownloadString("https://community.chocolatey.org/install.ps1"))');Cho coPS.Active:=True;Memo1.Lines.LoadFromStream(ChocoPS.Output);ChocoPS.F ree;          Is there a way to execute the commands in question? in the DownloadString Method replace double quote with single quote like this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ChocoPS.Parameters.Add('iex ((New-Object System.Net.WebClient).Downloa dString(''https://community.chocolatey.org/install.ps1''))'); Friendly, J.P ---------------------------------------------------------------------- badmintonfan · 2023-12-24 13:40 I tested it within windows 10 and powershell 5.1,and found only few cmdlet can run,I have tested get-process also,but thers is no result procedure TForm1.Button1Click(Sender: TObject); var ChocoPS : TProcess;   oput: ansistring; begin     ChocoPS:= TProcess.Create(Form1);     ChocoPS.Options:=[poUsePipes,poWaitOnExit,poNoConsole,poStderrToOu tPut];     ChocoPS.Executable:='PowerShell.exe';     //ChocoPS.Parameters.Add('Get-WmiObject -Class Win32_BIOS -ComputerName .');     //ChocoPS.Parameters.Add('whoami /upn');     ChocoPS.Parameters.Add('Get-NetAdapter');     ChocoPS.Active:=True;     //oput:=ChocoPS.Output;     Memo1.Lines.LoadFromStream(ChocoPS.Output,Tencoding.ANSI);     //memo1.Append(oput);     ChocoPS.Free; ---------------------------------------------------------------------- TRon · 2023-12-24 14:03 Quote from: badmintonfan on December 24, 2023, 02:40:46 pmI tested it within windows 10 and powershell 5.1,and found only few cmdlet can run,I have tested get-process also,but thers is no result I don't know how powershell expects its parameters but it might be that you are requited to add each individual parameter to the process options (it might even depend on the subcommand being executed by powershell). e.g f.e.: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ChocoPS.Parameters.Add('Get- WmiObject'); ChocoPS.Parameters.Add('-Class Win32_BIOS'); ChocoPS.Parameters.Add('--ComputerName .'); or perhaps even: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ChocoPS.Parameters.Add('Get-WmiObject'); ChocoPS.Parameters.Add('- Class'); ChocoPS.Parameters.Add('Win32_BIOS'); ChocoPS.Parameters.Add( '--ComputerName'); ChocoPS.Parameters.Add('.'); I also wonder how powershell treats the dot in relation to expansion. Also your example seem to want to provide multiple commands at once (guessing there as you commented them) which would probably require other additional powershell separator characters to distinguish between commands. I would suggest to start experimenting with simple commands, adding some optons and work your way up until you figure out how the parameters are expected to be provided at tprocess for powershell. Sorry, no powershell here at my end in order to check/test. ---------------------------------------------------------------------- badmintonfan · 2023-12-25 06:51 These commented which are have been tested and got result ---------------------------------------------------------------------- Jurassic Pork · 2023-12-25 17:34 Hello, Quote from: badmintonfan on December 24, 2023, 02:40:46 pmI tested it within windows 10 and powershell 5.1,and found only few cmdlet can run,I have tested get-process also,but thers is no result With this code : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  Pwsh: IPwsh;  Resultat: WideString;begin  CreatePwshInstance(Pwsh);  Resultat := Pwsh.ExecuteCmd('(Get-Process *) | Out-String');  Memo1.Append(Resultat);end;    i get what you can see in attachment. Friendly, J.P ---------------------------------------------------------------------- badmintonfan · 2023-12-26 11:27 Hello Jurassic Could you please explain me IPwsh Quote from: Jurassic Pork on December 25, 2023, 06:34:09 pmHello, Quote from: badmintonfan on December 24, 2023, 02:40:46 pmI tested it within windows 10 and powershell 5.1,and found only few cmdlet can run,I have tested get-process also,but thers is no result With this code : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  Pwsh: IPwsh;  Resultat: WideString;begin  CreatePwshInstance(Pwsh);  Resultat := Pwsh.ExecuteCmd('(Get-Process *) | Out-String');  Memo1.Append(Resultat);end;    i get what you can see in attachment. Friendly, J.P ---------------------------------------------------------------------- Jurassic Pork · 2023-12-26 12:59 Hello, IPwsh is an Interface with an external dll Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  IPwsh = interface(IUnknown)   ['{8871C5E0-B296-4AB8-AEE7-F2553BACB735}']   function ExecuteCmd(const Cmd: WideString): WideString; safecall;   end;{$IFDEF WIN32}   procedure CreatePwshInstance(out Sample: IPwsh); stdcall; external 'LazPwshJP32.dll';{$ENDIF}{$IFDEF WIN64}   procedure CreatePwshInstance(out Sample: IPwsh); stdcall; external 'LazPwshJP64.dll';{$ENDIF}    The LazPwshJP dlls are unmanaged export Csharp dll using the PowerShell Csharp class. The dotnet framework used is the 4.0 (included in windows, sometimes must be actived). The dlls have MIT licenses. In Attachment a lazarus demo program with the dlls. tested on windows 11 with Lazarus 2.2.6  64 bits and PowerShell 5.1. Friendly, J.P ---------------------------------------------------------------------- badmintonfan · 2023-12-26 14:41 Hello Jurassic Pork That is what I wanted,thank you very much ---------------------------------------------------------------------- badmintonfan · 2024-01-10 07:38 Quote from: Jurassic Pork on December 26, 2023, 01:59:07 pmHello, IPwsh is an Interface with an external dll The LazPwshJP dlls are unmanaged export Csharp dll using the PowerShell Csharp class. The dotnet framework used is the 4.0 (included in windows, sometimes must be actived). The dlls have MIT licenses. In Attachment a lazarus demo program with the dlls. tested on windows 11 with Lazarus 2.2.6  64 bits and PowerShell 5.1. Friendly, J.P Hello How to process the prompt during execute a cmdlet