昔はセキュリティがゆるかったので、ローカルの C:\ のパスで使えたのですが、今は http:// でないと使え無いので画面を http://winofsql.jp/password.htm として置いています。入力後、きちんと IE は閉じます。 また、IE11 環境で実行しているので、VBScript を利用可能にする為、以下の記述は必要です。
<meta http-equiv="X-UA-Compatible" content="IE=8">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<SCRIPT LANGUAGE="VBScript">
Sub RunScript
document.getElementById("OKClicked").Value = "OK"
End Sub
Sub CancelScript
document.getElementById("OKClicked").Value = "Cancelled"
End Sub
</SCRIPT>
<BODY>
<pre>
Password:
<input type="password" id="UserPassword" size="40">
<input type="hidden" id="OKClicked" size="20">
<input class="button" type="button" value=" OK " onClick="RunScript"
> <input class="button" type="button" value="Cancel" onClick="CancelScript">
</pre>
</body>
</html>
※ ローカルでは無いので必ず、Busy 対処は必要です。 ※ Sleep を使用して、入力されたかどうかを監視して待機しています。
' 管理者として実行を強制する
Set obj = Wscript.CreateObject("Shell.Application")
if Wscript.Arguments.Count = 0 then
obj.ShellExecute "wscript.exe", WScript.ScriptFullName & " runas", "", "runas", 1
Wscript.Quit
end if
' オブジェクト作成
Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
' オブジェクト設定
objExplorer.Navigate "http://winofsql.jp/password.htm"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 350
objExplorer.Left = 300
objExplorer.Top = 200
objExplorer.Visible = True
' ページのロードを待つ
Do While objExplorer.Busy
' 100 ミリ秒
Wscript.Sleep 100
Loop
' 入力状態を監視
Do While (objExplorer.document.getElementById("OKClicked").Value = "")
Wscript.Sleep 250
Loop
' パスワード取得
strPassword = objExplorer.document.getElementById("UserPassword").Value
' ボタンの判定用
strButton = objExplorer.document.getElementById("OKClicked").Value
' オブジェクト終了
objExplorer.Quit
' 少し待機
Wscript.Sleep 250
' 入力判定
If strButton = "Cancelled" Then
Wscript.Quit
Else
Wscript.Echo strPassword
End If
▼ Wscript.Echo strPassword関連する記事 IE11 で VBScript を使う場合の注意事項 ( 古い社内アプリ移行時必見 )
|
|
【VBScriptの最新記事】
- 指定した位置でレジストリエディタを開く為の VBScript をダウンロードします
- VBScript(WSH) と PHP(7.3) で氏名をランダムに作成
- VBScript : XCOPYで新しいファイルのみバックアップする為のスクリプトを作成するスクリプト
- VBScript + PowerShell : PowerShell がファイルを開くダイアログで取得したパスをテキストファイル経由で VBScript に戻して使用する
- VBScript : XMLファイルのテキストノードの値の更新
- HTA : 指定したキーでレジストリエディタを開く
- WSH(VBScript) : 指定したキーでレジストリエディタを開く
- VBS : 正規表現で、URL リストの中のドメイン部分のみを取り出す
- 文字列を指定してその名前の変数でオブジェクトを作成する : WEB に VBScript ライブラリ
- 実行中のスクリプトのタイプを知る : WEB に VBScript ライブラリ
- VBS : FileZilla用誰にでも使える拡張子ランチャー


入力後、きちんと IE は閉じます。
また、IE11 環境で実行しているので、VBScript を利用可能にする為、以下の記述は必要です。
関連する記事




