Click here to Skip to main content
16,018,938 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
Objective: I need to run this executable program on this path "\\172.168.0.46\Inhouse Module\Michael Panaligan\AllUnit\RunCom.exe"
It's working on my local computer but not on IIS Server Side. I don't know why it's not working on IIS Server Side when it's completely fine on my local unit.
Thank you!

Here's my script.
VB.NET
Imports System.Diagnostics

Public Class CallLegacyApp
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim networkPath As String = _
   "\\172.168.0.46\Inhouse Module\Michael Panaligan\AllUnit" ' Rename folder without spaces
        Dim executablePath As String = "RunCom.exe"

        Try
            ' Map network drive using net use command
            Dim netUseStartInfo As New ProcessStartInfo("net.exe", _
            "use " & networkPath & " /USER:nkti\sdg programmers")
            Process.Start(netUseStartInfo).WaitForExit()

            ' Start the program
            Dim startInfo As New ProcessStartInfo()
            startInfo.FileName = networkPath & "\" & executablePath
            Process.Start(startInfo)
        Catch ex As Exception
            Response.Write("Error: " & ex.Message & "<br>" & ex.StackTrace)
        End Try

    End Sub


What I have tried:

Tried to understand Shell and Process.Start function. Did some research and ask AI.

I received this error:
Quote:
Server Error in '/ROS/CallLegacy' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: The compiler failed with error code 255.
Posted
Updated 14-Sep-23 9:37am
v4
Comments
Richard Deeming 15-Aug-23 5:40am    
First issue: You've not provided a password in your net use command, only a username.

Second issue: You're launching the application using the UNC path, so the net use command is irrelevant.

Third issue: you haven't explained what the problem is. At a guess, you're expecting the application to launch on the client, which will never work when you launch it from code running on the server. It might appear to work when you debug it locally, but that's just because, in that specific case, the client and server are the same machine.
rvjay supatan 15-Aug-23 6:20am    
Sir,
about the first issue you mentioned the password is programmers
Here: Dim netUseStartInfo As New ProcessStartInfo("net.exe", "use " & networkPath & " /USER:nkti\sdg programmers")

Second Issue: Thank you sir, I will take note of this.

Third issue:
You're right sir, I'm expecting to launch the application on the client.
All files are existing on the client computer.

The problem, when I try to run the webpage on the server I received error like this.
Error: The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at LegacyApp.CallLegacyApp.Page_Load(Object sender, EventArgs e) in D:\ROS MOD BKP Sept 9 2016\CALL_LEGACY_APP\LegacyApp\LegacyApp\CallLegacyApp.aspx.vb:line 18

rvjay supatan 15-Aug-23 6:21am    
Is there a way to lunch the application to client sir?
Dave Kreskowiak 25-Aug-23 9:54am    
No, not from a web app. What you are describing is a massive security risk and is not allowed by browsers.

Quote:
I'm expecting to launch the application on the client.
Well, there's you problem.

Code running on the server cannot launch an application on the client.

It might appear to work when you debug your code locally. But that's only because, in that specific situation, the client and server are the same machine.

As soon as you try to run your code on a real server, one of two things will happen. In the best case, your code will crash indicating that you can't launch an interactive application on the server. In the worst cast, it will launch the application on the server, where nobody will ever see it, and then hang waiting for someone to log in to the server and close the application.

And no, before you ask, you won't be able to launch the application from JavaScript running on the client either.

And linking to a UNC path from a web site won't work; most modern browsers will explicitly block such links.

The best you can do is to transmit the exe file in the Response with appropriate headers (content-type application/octet-stream, and possibly a content-disposition as well). The user should then be given the choice to save, run, or discard the file. (And no, you can't force them to pick the "correct" option here.)

But doing that from your Page_Load event handler is generally not a good idea. You can't return any other content along with the file download, so the rest of your page code will be irrelevant.
 
Share this answer
 
Comments
Dave Kreskowiak 15-Aug-23 9:26am    
IIRC, on top of that, even if you could launch the app on the client, .NET app running from a network source is, by default, not trusted, or is only partially trusted, and will not launch.

It's been a really long time since I've run into that and don't know if it's still true or not.
Richard Deeming 15-Aug-23 9:31am    
That was a long time ago! :)

"Not trusted on a network path" hasn't been a thing since CAS Policy was dropped with .NET Framework 4.0:
Code Access Security Policy Compatibility and Migration | Microsoft Learn[^]

You'd have to explicitly go out of your way to enable that PITA:
Enabling CAS Policy Compatibility Mode for a Project - .NET Blog[^]
wmic /node:172.168.0.46 process call create "full path to exe and parameters"


You may need to do some additional research around authenticating to the target. Based on my (brief) testing, the result process is running at a system level, not a user level.
 
Share this answer
 
Comments
Dave Kreskowiak 25-Aug-23 9:55am    
This will do nothing for the OP. He's trying to launch an executable on a client machine from code running on a web server. That is never going to work.
[no name] 25-Aug-23 11:08am    
my apologies. it wasn't clear to me that the OP was asking about a web server and client

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900