いくつかの引数 (名前、電子メールなど) を受け取る VBScript があり、HTML フォームを作成しました。
ユーザーがデータを入力したら、VBScript を実行し、フォーム データをパラメーターとして渡します。
問題は、HTML フォームから VBScript を実行する方法です (サーバーがないため、クライアントは HTML を実行し、マシン上で VBscript を実行します)。
VBScript は外部ファイルです。それを myScript.vbs と呼びましょう
サーバーへの HTTP 接続なしで HTML フォームがデータを「送信」する方法を知りません。問題を解決できる可能性のあるいくつかのオプションを次に示します。
お役に立てれば!
偶然にも、昨日、Ruby でこれを行う方法についての質問を公開し、サンプルとして vbscript スクリプトを提供したので、ここにあります。しかし実際には、スクリプトからブラウザを起動するのが最善です。
Set web = CreateObject("InternetExplorer.Application")
If web Is Nothing Then
msgbox("Error while loading Internet Explorer")
Wscript.Quit
Else
with web
.Width = 300
.Height = 175
.Offline = True
.AddressBar = False
.MenuBar = False
.StatusBar = False
.Silent = True
.ToolBar = False
.Navigate "about:blank"
.Visible = True
end with
End If
'Wait for the browser to navigate to nowhere
Do While web.Busy
Wscript.Sleep 100
Loop
'Wait for a good reference to the browser document
Set doc = Nothing
Do Until Not doc Is Nothing
Wscript.Sleep 100
Set doc = web.Document
Loop
'Write the HTML form
doc.Write "Give me a name<br><form><input type=text name=name ><input type=button name=submit id=submit value='OK' onclick='javascript:submit.value=""Done""'></form>"
Set oDoc = web.Document
Do Until oDoc.Forms(0).elements("submit").Value <> "OK"
Wscript.Sleep 100
If web Is Nothing or Err.Number <> 0 Then
msgbox "Window closed"
Wscript.Quit
End If
Loop
name = oDoc.Forms(0).elements("name").value
oDoc.close
set oDoc = nothing
web.quit
set web = nothing
Wscript.echo "Hello " & name
ここに私のHTMLコードがあります
<form id="myform">
<input type="radio" name="formradio" id="yes" />
<input type="radio" name="formradio" id="no" />
<select name="formemail" size="1">
<option value="someone@example.com" selected="selected">someone@example.com</option>
</select>
<button type="submit" id="sendReport">Send Status Report</button>
HTMLページ内の私のVBscriptコードは次のとおりです
<script language="VBScript" type="text/vbscript">
<![CDATA[
Sub sendReport_onclick()
'Logic to process the form goes in here.
MsgBox myform.formradio.value
MsgBox myform.formemail.value
'Run: wscript "{path}externalVBScript.vbs" "{path}"
WSHShell.Run "wscript """ & Path & "externalVBScript.vbs"" """ & Path & """"
window.status = "Script has been run via WScript"
End Sub
]]>
</script>