Forum > Windows

run command Powershell

<< < (2/3) > >>

TRon:

--- Quote from: badmintonfan on December 24, 2023, 02:40:46 pm ---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

--- End quote ---
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ChocoPS.Parameters.Add('Get-WmiObject'); ChocoPS.Parameters.Add('-Class Win32_BIOS'); ChocoPS.Parameters.Add('--ComputerName .'); or perhaps even:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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:
These commented which are have been tested and got result

Jurassic Pork:
Hello,

--- Quote from: badmintonfan on December 24, 2023, 02:40:46 pm ---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

--- End quote ---
With this code :

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Hello Jurassic
Could you please explain me IPwsh

--- Quote from: Jurassic Pork on December 25, 2023, 06:34:09 pm ---Hello,

--- Quote from: badmintonfan on December 24, 2023, 02:40:46 pm ---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

--- End quote ---
With this code :

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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

--- End quote ---

Jurassic Pork:
Hello,
IPwsh is an Interface with an external dll

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version