Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

internet explorer - Is it possible to run the VBScript file(.vbs) from the browser?

I have 10 .vbs file and incorporated them into a single .vbs file namely Main.vbs.Now if I double click on the main.vbs,my script got started to run. But I am looking for anyway can I run the .vbs file from the web browser? So that no one need to go to the directory where the Main.vbs kept and double clicked on it.

My Main.VBS contents:

Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
oShell.CurrentDirectory = FSO.GetFile(Wscript.ScriptFullName).ParentFolder
oShell.run "A.VBS", 1, True
oShell.run "B.VBS", 1, True
oShell.run "C.VBS", 1, True
oShell.run "D.VBS", 1, True
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes you can if you use Internet Exlorer, but you will have to keep your IE security settings low to run it and even then you could have a prompt to confirm. All depends on which version and SP of Windows, which security updates , which version of IE and which settings in IE.

I suggest taking a second look at why you would start a local script this way. You can easily make and distribute a shortcut that starts your script without hassle of settings and prompts.

Ik you need a User Interface you can use Vbscript build-in or you could use a .HTA file instead of a .html or .asp file, security is less an issue with these files.

example: test.html

<script type="text/vbscript" src="c:empest.vbs"></script>

and test.vbs

Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set writefile = fso.OpenTextFile("c:empoutput.txt", ForWriting, True)
writefile.write "test"
writefile.close

When i load test.html i get two prompts and when i confirm i get the output.txt in c:emp

And last here an example with a .hta file, save it as eg test.hta, alwyas use IE when using ActiveX or Vbscript

<HTML>
<HEAD>
<SCRIPT language="VBScript">
<!--
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set writefile = fso.OpenTextFile("c:empoutput.txt", ForWriting, True)
writefile.write "test"
writefile.close
'-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

or

<HTML>
<HEAD>
<script type="text/vbscript">
  sub test
    const runminimized = 7
    const dont_wait_for_end = false
    Set wshShell = CreateObject("WScript.Shell")
    WshShell.Run "c:empest.vbs",runminimized, dont_wait_for_end
  end sub
</script>
</HEAD>
<BODY>
  these are the instructions
  <button onclick="vbscript:test" >Run the script</button>
</BODY>
</HTML>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...