Highlighted

Run PowerShell script?

Enthusiast ,
Dec 22, 2014

Copy link to clipboard

Copied

import flash.filesystem.*;

import flash.desktop.NativeProcess;

import flash.desktop.NativeProcessStartupInfo;

var file:File = new File("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

nativeProcessStartupInfo.executable = file;

var args:Vector.<String> = new Vector.<String>();

args.push("c:\\test\\sendTest.ps1");

nativeProcessStartupInfo.arguments = args;

var process:NativeProcess = new NativeProcess();

process.start(nativeProcessStartupInfo);

Trying to get Powershell to run sendTest.ps1 in the c:\test folder. I get no error, or anything for that matter.

If I issue this at the command prompt:

powershell c:\test\sendTest.ps1

It works fine. But I just can't get the syntax correct to run it from AIR.

Anyone tell me what I'm doing wrong?

You need to set ExecutionPolicy argument:

var args:Vector.<String> = new Vector.<String>();

args.push("-ExecutionPolicy");

args.push("Unrestricted");

args.push("c:\\test\\sendTest.ps1");

Without correct ExecutionPolicy you will get PowerShell PSSecurityException error. You can listen ProgressEvent.STANDARD_ERROR_DATA native process event to see it.

TOPICS
Development

Views

2.9K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Run PowerShell script?

Enthusiast ,
Dec 22, 2014

Copy link to clipboard

Copied

import flash.filesystem.*;

import flash.desktop.NativeProcess;

import flash.desktop.NativeProcessStartupInfo;

var file:File = new File("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();

nativeProcessStartupInfo.executable = file;

var args:Vector.<String> = new Vector.<String>();

args.push("c:\\test\\sendTest.ps1");

nativeProcessStartupInfo.arguments = args;

var process:NativeProcess = new NativeProcess();

process.start(nativeProcessStartupInfo);

Trying to get Powershell to run sendTest.ps1 in the c:\test folder. I get no error, or anything for that matter.

If I issue this at the command prompt:

powershell c:\test\sendTest.ps1

It works fine. But I just can't get the syntax correct to run it from AIR.

Anyone tell me what I'm doing wrong?

You need to set ExecutionPolicy argument:

var args:Vector.<String> = new Vector.<String>();

args.push("-ExecutionPolicy");

args.push("Unrestricted");

args.push("c:\\test\\sendTest.ps1");

Without correct ExecutionPolicy you will get PowerShell PSSecurityException error. You can listen ProgressEvent.STANDARD_ERROR_DATA native process event to see it.

TOPICS
Development

Views

2.9K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 22, 2014 0
Enthusiast ,
Dec 26, 2014

Copy link to clipboard

Copied

Anyone? Someone must've had to run a PowerShell script from AIR before?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 26, 2014 0
Engaged ,
Jan 01, 2015

Copy link to clipboard

Copied

You need to set ExecutionPolicy argument:

var args:Vector.<String> = new Vector.<String>();

args.push("-ExecutionPolicy");

args.push("Unrestricted");

args.push("c:\\test\\sendTest.ps1");

Without correct ExecutionPolicy you will get PowerShell PSSecurityException error. You can listen ProgressEvent.STANDARD_ERROR_DATA native process event to see it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 01, 2015 0
Enthusiast ,
Jan 01, 2015

Copy link to clipboard

Copied

Thanks much Alex. Will try this tomorrow morning and report back. I appreciate the help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 01, 2015 0
Enthusiast ,
Jan 07, 2015

Copy link to clipboard

Copied

Thanks Alex, that worked! I actually was doing nearly what you had there but I had:

args.push("-ExecutionPolicy Unrestricted");

Must not have liked it being on one line.

Problem now is that it takes 2-3 seconds for the powershell to load and run the script. I'd like it to be a lot faster if possible... I'm trying to 'press buttons' in another app, and the lag is a bit too noticeable.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 07, 2015 0
itlancer LATEST
Engaged ,
Jan 07, 2015

Copy link to clipboard

Copied

For faster operations I think you need to write ANE.

Or may be you can try to run PowerShell and initialize function via script before using it and only after call this function to "press buttons".

I don't try it but may be it works with:

process.standardInput.writeUTFBytes();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 07, 2015 0