Tweaking Permissions to run an executable from my website

Last post 05-19-2008 2:12 AM by XiaoYong Dai – MSFT. 1 replies.

Sort Posts:

  • Tweaking Permissions to run an executable from my website

    05-16-2008, 10:48 AM
    • Member
      point Member
    • celia456
    • Member since 05-16-2008, 2:42 PM
    • Posts 2

    I want to run an executable from my webpage; I found a code a snipet to do it:

    1    Protected Sub btnRunScript_Click(...) Handles btnRunScript.Click
    2
    3    Dim ShellProcess As New System.Diagnostics.Process
    4    ShellProcess.StartInfo.FileName = "c:\temp\EmailSender.exe"
    5
    6    ShellProcess.StartInfo.UseShellExecute = False
    7    ShellProcess.StartInfo.RedirectStandardOutput = True
    8    ShellProcess.StartInfo.RedirectStandardInput = True
    9    ShellProcess.StartInfo.RedirectStandardError = True
    10    ShellProcess.Start()
    11    'ShellProcess.WaitForExit()
    12    'ShellProcess.Dispose()


    I can get it to work when I use Visual Studio's built-in web server, but not when I plug
    this code into my real site which uses IIS. IIS allows me to run Windows-made-applications
    such as cmd.exe and batch files. I first tried something simple like using cmd & a batch
    to echo to a text file - success for both IIS & VS' server (see code snipet 2). But when I
    try using cmd/batch to run my EmailSender.exe, VS's web server lets me but IIS does not
    (snipet 3).

    This seems like a permissions settings that I must just be missing (?).

    [I would not do this on the real server!!], but I gave Everyone 'Full Control' Permission on
    c:temp\. In IIS, I gave the default Web Site both 'Script and Executes' permission. This
    doesn't seem to be it. What else might I have to do to be able to run my executable?


    Code Snipet 2 [works for both VS' server and IIS]:

    4    ShellProcess.StartInfo.FileName = "C:\WINDOWS\system32\cmd.exe"
    5    ShellProcess.StartInfo.Arguments = String.Concat("/c echo foo > c:\temp\bar.txt")


    Code Snipet 3 [works only for both VS' server]:

    4    ShellProcess.StartInfo.FileName = "C:\WINDOWS\system32\cmd.exe"
    5    ShellProcess.StartInfo.Arguments = String.Concat("/c c:\temp\EmailSender.exe")

     

  • Re: Tweaking Permissions to run an executable from my website

    05-19-2008, 2:12 AM
    Answer

    Hi

    It seems that ASP.NET access the "cmd.exe" via anonymous user account (usually "Network Service"). This account may have problem to execute "cmd.exe" which locate in System root. Therefore, I'd suggest you to try the impersonate code from KB.

    (This is the origin of code http://support.microsoft.com/kb/306158#3 )

     

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (2 items)