How to RUN a PowerShell script

Hallo,

Maybe it’s simple but… how can I run a PowerShell script from Clarion?

RUN('test.ps1') - doesn't work
RUN('test.ps1',0,0) - doesn't work
RUN(LONGPATH()&'\test.ps1') - doesn't work
RUN('powershell.exe '&LONGPATH()&'\test.ps1') - doesn't work

Thank you for any help.
Robert

Have you tried
Run('PowerShell -noexit test1.ps1')

1 Like

A Batch file can call Powershell so could run a PS script. From Clarion RUN your BAT file.

I use the below to Zip up a folder with PowerShell Compress:

ROBOcopy %SrcFld% %BakFld% ^
 *.clw *.inc  *.app *.dct  *.cwproj *.sln *.manifest *.red *.lib ^
 *.cur *.ico *.png *.gif *.bat *.ini *.msbuild *.txt *.h  ^
  /MT /R:2 /W:5  /PURGE /TEE /LOG+:%BakFld%\_RoboCopy.LOG

    echo Zip up folder %BakFld%
    echo --------------------------------
    powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
    IF ERRORLEVEL == 1 PAUSE
3 Likes

For WMI I suggest to use an ActiveScripting classes instead (I’m an author of both products):

2 Likes

I do like Mike’s ActiveScripting stuff very much, but you might also try Capesoft Oddjob (if you have it) to run your script if you really just want to run a .ps1 and capture output, etc.

Why to update the site?

3 Likes

I have OddJob but for this what I need it’s not good… it’s the same like NT ping class. From docs (Note this is a blocking, syncronous call.) so it will block the entire app until you got the response and I don’t think anyone wants that to happen.
The only workaround is with external tools like Powershell.

Thank you, now it’s working fine.
I had to Set-ExecutionPolicy to Unrestricted :man_facepalming:t2: (it’s a new pc in a very restrictive network)

Greetings,
Slightly off the topic but Carl inspired me to finish a very important task-Easily Backup to the Cloud.

Thank you Carl.

Batch File Attached.
Just place it in your APP folder and rename the extension to BAT.
Edit where needed.
_ZipMe.TXT (1.7 KB)

1 Like

Just to chip into this thread
Run(loc:command)

where

Loc:command = 'powershell -executionpolicy remotesigned -windowstyle hidden -command "$psversiontable.psversion | out-file -filepath 'c:\folder name\file name.txt' "

works nicely if you want to run PS commands direct instead of a ps1 script and optionally output to file for parsing in clarion.

Executionpolicy options that also work is ‘bypass’ but if thats not set back to the previous, is a security risk, so remotesigned is safer, but still a risk.

Example 3 in the below link is a good example of risk!

Interestingly I can do the above from an unmanifested c6 app on win11 which is surprising.

This is a ps script to interact with websites which can be called from clarion and altered by clarion. Its like Selenium the browser automation tool.

And if you want to control machines over the internet using ps controlled by clarion, this will do it.

Robert,

Maybe have a look at Capesoft’s OddJob?

It looks like OddJob is using shell execute because of the fmask attribute options in the shellexecuteinfo option.

Eg.

SEE_MASK_NOCLOSEPROCESS
SEE_MASK_NOASYNC
SEE_MASK_FLAG_NO_UI

Etc etc.

Considering shell execute is used with COM, I’m surprised they havent done a COM addon, but maybe there isnt the demand.