LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PowerShell script not working with System Exec

Solved!
Go to solution

I have some PowerShell scripts that I need to call from LabVIEW, but I’m having trouble getting them to fully work. The scripts perform automation tasks using the user32.dll. Everything works properly when I run the scripts from PowerShell, PowerShell ISE, command prompt, and the Run command, but the scripts do not fully work when calling them from System Exec.vi. I have LabVIEW 17.0.1 32-bit on Windows 10 Enterprise 64-bit.

 

When I run the script from command prompt, the command is

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

That works fine, so in System Exec.vi I set the command line input to

 

 

cmd /k

and the standard input to

 

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

A command prompt window opens, and the script starts but does not fully work. The script calls a C# function to do a PostMessage simulating a keystroke. There are more PostMessages, but only the first one goes and then nothing after that. There are no error codes associated since the script finishes, but it doesn't fully work.

 

 

When I run the script with the Run command, the command is

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

That also works fine, so in System Exec.vi I set the command line input to

 

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

with no standard input. A PowerShell window opens, and script starts but again does not work.

 

 

I know the PowerShell and C# side of this is not supported here, but since everything works except for in LabVIEW, does anybody have an idea of why the scripts won’t complete? Would it have anything to do with LabVIEW being 32-bit on a 64-bit computer? Thank you for any input!

 

0 Kudos
Message 1 of 3
(10,079 Views)
Solution
Accepted by topic author mbless

Here are some things to try/check:


Check Powershell execution policy: “get-executionpolicy”. Probably needs to be either Unrestricted or RemoteSigned.

Check/set the execution policy settings on both 32-bit and 64-bit Powershell.
Run LabVIEW IDE as admin.

 

Try the following strings and set the command line input to (no standard input) and see what happens:

 

(1) 32-bit PS version:
cmd /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

 

(2) 64-bit PS version:
cmd /c C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

 

(3) Command line chooses version:
cmd /c %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -file “path to file.ps1”

 

Does the PS script require it to run out of a particular directory? If so, try setting the working directory path input on System Exec.

 

If this is a Windows 10 related thing, then I’m not sure. Group policy settings could also be interfering with script execution.

Message 2 of 3
(10,059 Views)

Thank you so much! (3) solved the problem. Reading up on %SystemRoot%\sysnative, it appears to be some 32/64-bit compatibility.

 

For other's reference, get-executionpolicy returned unrestricted for 32-bit and 64-bit PowerShell. Options (1) and (2) both returned “Arithmetic operation resulted in an overflow” errors, which don't actually make sense given the code that threw the error. I also don't have to run LabVIEW as admin.

0 Kudos
Message 3 of 3
(10,036 Views)