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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger VBScript from ASP webpage

Status
Not open for further replies.

tps14334

Technical User
Dec 8, 2008
21
US
I am trying to figure where I am going wrong here. I am looking to have a webpage trigger the code below which tunnels from my web server to my application to then kick off a batch file which calls up a program and begins automation of various functions.

Code:
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
RemoteFile = "e:\local_execute.bat"
Set oExec = WshShell.Exec("psexec -d -i 1 -u username -p password \\applicationserver " & RemoteFile & "")

The executable string works, has been used in many VBA coded excel macros or in other batch files. The above code also works when I save it as a .VBS file and double click on it from any computer on the network and tunnels to the application server like it should. Thinking that ASP shares the VBScript language, I thought this would work without much headache.

And it does work, sort of. I can see in the task manager of my web server that the application PSEXEC is running under the user "NETWORK SERVICE" but just hangs out until it is killed by the garbage collector. This code normally does its thing in less than a second, so there is no reason for the application to just be sitting there unless it is hung.

Any thoughts or other suggestions to accomplish my goal? Doesn't have to be ASP, just trigger the script from a webpage and successfully execute.
 
Alot of trial and error with hunting around for code snippites online lead to this solution:

Code:
<script>
function App_Launch() 
{
    if (!document.all) 
        {
            alert ("Available only with Internet Explorer.");
            return;
        }
    var ws = new ActiveXObject("WScript.Shell");
    ws.Run("\\\\ServerName\\SharedFoler\\DeeperFolderName\\Application.bat");
}
</script>

...

<a href="javascript:App_Launch()">Launch Application</a>

This solution uses and ActiveXControl to launch the batch file from a network share drive and execute it on the user's local machine. In my case the batch file calls up PSEXEC and initializes the tunnel to the remote server to launch the application there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top