Reputation: 1203
I have referenced a few mentions of how to do this on stackoverflow.
I tried testing from the following reference code :
https://www.dotnetperls.com/process
How to run .exe file by my Webservice?
VERSION: Framework 3.5
VisualStudio2010
When i ran my code below in the browser, I see the bullet point to click on. When I click on it nothing happens. My exe simply locates an xml file and creates a new file from it. I want to use a webservice to run the exe. Is there something I am missing in my code? There are other versions I saw that had more code but I tried them and still had no luck [check my link]
This is my first webservice so I am learning as I go.
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://localhost/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Dim File As String
<WebMethod()> _
Public Sub runExe()
Dim exe = "C:\WindowsApplication1\bin\Debug\WindowsApplication1.exe"
'Dim file = "C:\Test\test.xml"
Dim startInfo As New ProcessStartInfo()
startInfo.FileName = exe
'startInfo.Arguments = file
Process.Start(startInfo)
'REFERENCE: https://www.dotnetperls.com/process
End Sub
I also tried calling .exe from another .exe to run a webservice by using
ThreadPool.QueueUserWorkItem(Sub() Process.Start("C:\WindowsApplication1\bin\Debug\WindowsApplication1.exe"))
but the exe didn't run aka I didn't see the new file created in the folder path the exe sends it to.
also tried:
Dim processInfo = New ProcessStartInfo(exe)
Dim process__1 = Process.Start(ProcessInfo)
process__1.WaitForExit(5000)
Dim exitCode = process__1.ExitCode
process__1.Close()
Return
nothing happened
UPDATE:
Didn't think to use a output test to find my issue. I used the following:
While Not process__1.StandardOutput.EndOfStream
Dim line As String = process__1.StandardOutput.ReadLine()
End While
Upvotes: 1
Views: 383
Reputation: 219057
In response to your comment...
well I'm planning to use my asp.net application to communicate with this service to run exe. so I would think client
That's an incorrect understanding of how web applications work. Your server-side ASP.NET code (the VB parts) are just that, server-side. All of that code executes on the web server. The browser/client/etc. has no knowledge of it.
(Imagine for a moment a world where any website you visit could arbitrarily execute any .NET code they want on your computer. Doesn't sound like fun.)
If you want the client to execute an application, you have to send the application to the client (such as a link to download it) and basically ask them to run it. Your server-side code can't automatically execute applications on the client's computer.
Upvotes: 1