Run VBS file from ASP.NET

onepieceking

Well-known member
Joined
Sep 20, 2006
Messages
64
Programming Experience
1-3
Hi,

Is it possible to run VBS file from ASP.NET (VB.NET)? If so, what is the way to do it?

Anyway, the vbs file is supposed to check at the server-side if application A is running. If it is not running, it will run that application. I tried incorporating the vbscript into the html, but there is some error about ActiveX control.

Besides using vbscript, is there another better way to do this?

Thanks.
 
Scripting in Html page only runs client-side. You can start the Vbs as process from code-behind, you can also use the Process class directly with GetProcessesByName method to get the answer. Here is code sample that lists all server processes in the Listbox1 when user click Button1:
VB.NET:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
  ListBox1.DataSource = System.Diagnostics.Process.GetProcesses()
  ListBox1.DataTextField = "ProcessName"
  ListBox1.DataBind()
End Sub
And here similar to what you asked:
VB.NET:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
  If System.Diagnostics.Process.GetProcessesByName("calc").Length = 0 Then
    System.Diagnostics.Process.Start("calc.exe")
  End If
End Sub
You might have to modify some server configuration security settings, http://support.microsoft.com/default.aspx?scid=kb;en-us;555134
 
Hi John,

I have tried the second code that you have suggested, but I have this error that says "Access is denied".

I have already let the service to interact with desktop and also given ASPNET full control.

What could be the problem?
 
Don't know, except both resolutions in that link have to be applied - both for the (1) ASPNET account (a) interact or (b) through SYSTEM account as linked further and (2) IIS service.
 
Back
Top