Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using WScript.Shell object to run a bat file

Status
Not open for further replies.

obellix

Technical User
Jan 19, 2007
2
ZA
I am a javascript novice trying to execute a bat file from a web page using 'WScript.Shell'. When I test it I get an error saying cant locate file. the code is pasted below please help. Alternative suggestions are welcome



<html>
<head>
<title> *** Bat File Runner *** </title>

<script type="text/javascript">
<!--
function MyFunction()
{
var Shell = new ActiveXObject("WScript.Shell");
var ret = Shell.run("C:\Folder\test.bat")
Shell = null;
}
//-->
</script>

</head>
<body>

<form>
<input type="button"
onclick="MyFunction()"
value="Run Function">
</form>

<p>Press button to run Function.</p>

</body>
</html>

 
>var ret = Shell.run("C:\Folder\test.bat")
[tt]var ret = Shell.run("C:\[red]\[/red]Folder\[red]\[/red]test.bat")[/tt]
 
Thanks Tsuji, however I've tried that and the same error still comes up.
 
[1] It is ie only, not for moz or else. [2] Don't just try, it is _the_ syntax and it is not a negotiable item. [3] Depending on the os version, you may try this.
[tt] var ret = Shell.run("%comspec% /c C:\\Folder\\test.bat")[/tt]
 
Try this:
Code:
var ret = Shell.run("[COLOR=red]file://[/color]C:[COLOR=red]/[/color]Folder[COLOR=red]/[/color]test.bat")


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top