Skip to main content
Inspiring
December 22, 2014
解決済み

Run PowerShell script?

  • December 22, 2014
  • 返信数 2.
  • 4831 ビュー

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?

このトピックへの返信は締め切られました。
解決に役立った回答 itlancer

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.

返信数 2

itlancer
itlancer解決!
Inspiring
January 1, 2015

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.

dmennenoh作成者
Inspiring
January 1, 2015

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

dmennenoh作成者
Inspiring
December 26, 2014

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