Ajesh
27th August 2018, 16:22
Dear all,

I am trying to run certain Powershell commands using run.prog but i am getting -1 as the return value . Have tried lots of P&C.


retval = run.prog("Powershell $xlsSpreadsheet = 51","",RP_WAIT)
retval = run.prog("Powershell.exe $xlsSpreadsheet = 51","",RP_WAIT)
retval = run.prog("powershell.exe $xlsSpreadsheet = 51","",RP_WAIT)



Have tried running a .ps1 batch File and tried to run it using Powershell.exe but unable to do so. Any specific thing i am missing?

Regards
Ajesh

vinceco252
27th August 2018, 17:34
Do you need to add any paths?

NPRao
28th August 2018, 03:39
You have to provide the full path to the base Power-shell executable.

comd = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
args = "-File E:\Scripts\HelloWorld.ps1"

e = run.prog(comd, args, RP_WAIT, ifile, ofile, errfile)

You can look it up with the PS command -
(Get-Command powershell.exe).Definition

I read on some forum that - It is always C:\Windows\System32\WindowsPowershell\v1.0. It was left like that for backward compatibility.

Ajesh
28th August 2018, 14:03
Running with the full path worked as you suggested but now running specific commands i am getting error


$Excel = New-Object -Com Excel.Application




New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the
following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:2 char:10
+ $Excel = New-Object -Com Excel.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand


Have tried running on both 32 bit as well as 64 bit... Its Windows 2012 R2