このvbsのメリットは、Powershell上のターミナルからExecutionPolicyの設定変更をすることができること。諸事情でPowershellの設定変更ができないが、Powershellスクリプトをサクサク実行させデバッグとかさせたい方向けのアダプタスクリプト
vbs上に、パワーシェルのスクリプトファイルをドラッグすると実行することが可能
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Dim objFso | |
dim objShell | |
dim VbsFolderName | |
Dim PsFileName | |
'vbsファイルの場所へカレントディレクトリを移動する。 | |
Set objFso = CreateObject("Scripting.FileSystemObject") | |
VbsFolderName = objFso.getParentFolderName(WScript.ScriptFullName) | |
'Msgbox objFso.getParentFolderName(WScript.ScriptFullName) | |
'カレントディレクトリの異動 | |
Set objShell = Wscript.CreateObject("WScript.shell") | |
objShell.CurrentDirectory = VbsFolderName | |
'移動確認 | |
'WScript.Echo objShell.CurrentDirectory | |
'ドラッグされたファイル名確認 | |
'MsgBox WScript.Arguments.Item(0) | |
PsFileName = WScript.Arguments.Item(0) | |
' PowerShellコマンドの実行 | |
objShell.Run "powershell -ExecutionPolicy Unrestricted -file " & PsFileName, 0 | |
' WSHオブジェクトの破棄 | |
Set objShell = Nothing | |
Set objFso = Nothing | |
WScript.Quit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wsobj = new-object -comobject wscript.shell | |
$result = $wsobj.popup("Hello!HelloVbs") | |
$Location = (Get-Location).Path | |
#$result = $wsobj.popup($Location) | |
cd $Location | |
new-item HelloVbs.txt | |
コメント