SQLの窓

2014年03月11日


VBScript : WEB上のHTMLを使用して、InternetExplorer.Application でパスワード入力を実装する

昔はセキュリティがゆるかったので、ローカルの 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 を使う場合の注意事項 ( 古い社内アプリ移行時必見 )



posted by lightbox at 2014-03-11 20:27 | VBScript | このブログの読者になる | 更新情報をチェックする
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり