CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2003
    Location
    Greece
    Posts
    533

    shell() strange problem

    Hi

    I have a very strange problem with the Shell function within a asp.net web application (vb.net pro 2003).

    In a web form's button click event, i am using Shell somewhere in the middle to run-and-wait an exe program (its a vb6 executable which handles some local files and returns an output file with some results in it).

    The problem is that the specific program wont run at all when i am calling it with Shell.

    If I run it from the windows explorer by double clicking it, it runs ok. Shell does nothing and skips to the next command (in that case shell returns 0). I've tried to use the Diagnostics.Process.Start and I am getting an exception saying something about win32...blah blah permission error.

    The project runs in a folder "webtools" inside the wwwroot main folder.
    The specific exe is located in the webtools folder itself, the root of the application that means.

    Do you have an idea? I've tried also to set even read/write/execute permissions for the webtools folder, but still the same. Its not something about that exe file, i even cant run the notepad.exe if i place it to the webtools folder.

    Try it yourself. The following is not working at all at least on my computer with the current vb.net pro 2003 installation. I never had any kind of problem making web applications but i think its the first time i am using shell().

    Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            Shell("C:\WINDOWS\NOTEPAD.exe", AppWinStyle.NormalFocus)
    
    End Sub
    Last edited by dtv; December 11th, 2008 at 07:07 PM.
    - Better live in the digital world -

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: shell() strange problem

    You cannot run an exe from a website like that. Imagine the consequences!

    You found the reason yourself.
    Code:
    win32...blah blah permission error
    Browsers don't have permission to execute programs directly.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: shell() strange problem

    Here's about as close as you can come. It impersonates the permissions to read the root folder on your computer, and return file info.

    http://siokonline.com/publix/publish.htm
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Feb 2003
    Location
    Greece
    Posts
    533

    Re: shell() strange problem

    oops, i realised the following. The EXEs are actually running like in "invisible mode", what ever the AppWinStyle parameter is. I can see the specific exe instance in the processes tab of the windows task manager. But it seems that it is sleeping or something (takes zero cpu usage!!!).

    By running the exe from the windows explorer as i said previously, it runs fine. The only difference between the two ways of running, is the user. From a web form, the user that runs the exe is the ASPNET user, and in the other hand from Windows Explorer the user is the local machine user.

    I am a bit confused.
    - Better live in the digital world -

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: shell() strange problem

    I added a link to my last post. Check it out, and run it on your system to see if it runs or not...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Feb 2003
    Location
    Greece
    Posts
    533

    Re: shell() strange problem

    I understand what you are saying, but i am talking for my personal server, not something untrusted. And not for the public.

    The exe is run from the SERVER, not the client. Lets say is an extension of the web form code, nothing more or less. Is just like i preferred to do some file handling from within a vb6 program, and then the result to handle it better from the rest vb.net program.

    sub button_click()
    'vb.net commands
    'shell and wait for the vb6 code (exe)
    'vb.net commands to get the result of that exe
    'continue executing the event, then return the page to the client
    end sub

    That is the scenario.
    What permissions and where to set them?



    Quote Originally Posted by dglienna View Post
    You cannot run an exe from a website like that. Imagine the consequences!

    You found the reason yourself.
    Code:
    win32...blah blah permission error
    Browsers don't have permission to execute programs directly.
    Last edited by dtv; December 11th, 2008 at 07:27 PM.
    - Better live in the digital world -

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: shell() strange problem

    You can't. The browser can't interact with the OS by shelling a command, or starting a process.

    You could rewrite your vb6 app as an aspx web app with code-behind that runs locally
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Feb 2003
    Location
    Greece
    Posts
    533

    Re: shell() strange problem

    djlienna, thanks for the answers but you didnt understand, maybe my mistake.

    The problem is solved.

    I was talking about SERVER-SIDE code, it has nothing to do with browser's facts. I can do what ever I want at server-side, to my server's files and folders and services.

    About the problem, the reason of the shell misbehavior was indeed some permissions. When I load the web from another computer on the local network, everything worked fine. Is just like the asp.net service not letting me debug the web form by running both server and client on the same computer.
    - Better live in the digital world -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured