Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@itasnasal

とりあえずpowershellのスクリプトを実行する。

More than 3 years have passed since last update.

「スクリプトの実行がシステムで無効になっているため、ファイル C:... を読み込めません。」とかはもうどうでもいいから、前準備とかなしにとりあえず1ファイル一発で動くpowershell用スクリプトをでっちあげる仕組みを考えた。

WSH/Jscript内にコメントとしてpowershell用スクリプトを記述する。

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

を起動するようにすれば、MSScriptControl.ScriptControl も使えてお得かもしれない。試してないけど。

KickPs.js
fso = new ActiveXObject("Scripting.FileSystemObject");
WshShell = new ActiveXObject("WScript.Shell");
var temp = fso.GetSpecialFolder(2); // 2:%TEMP%

var myself = function(){return fso.OpenTextFile( WScript.ScriptFullName,1).ReadAll();}();
myself = myself.replace(/^[\s\S]*\/\* powershell code from here/m, "" );
// [\s\S]:「改行も含むすべての文字」にマッチするトリッキーなパターン
myself = myself.replace(/   powershell code to here \*\//, "" );

var tempps1 = fso.BuildPath( temp, "temptemp.ps1" );
var ouf = fso.CreateTextFile( tempps1,true );
ouf.Write( myself ); ouf.Close();

var cmd = "powershell -NoProfile -ExecutionPolicy Unrestricted " + tempps1;
WshShell.Run(cmd,10,true);
fso.DeleteFile(tempps1);

//////////////////////////////////////////////////////////////////////
// ↓のコメント部分は変更禁止。
/* powershell code from here

Write-Host "Hello world"
pause

   powershell code to here */

3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?