Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Calling a batch file from web application

Calling a batch file from web application

Scheduled Pinned Locked Moved ASP.NET
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alchong
    wrote on last edited by
    #1

    Greetings... I'm currently working with IIS 5.1, developing a web app using C#, and testing on win xp pro. One of the functions of the web app is to map a drive letter to a network resource. The way I'm going about this is calling a batch file from the application: System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = @"C:\tmp\testBat.bat"; proc.Start(); The batch file contains the following: copy "C:\tmp\src\test.txt" "C:\tmp\dst\testcopy4.txt" net use X: I've setup impersonation in web.config, and am only using Integrated Windows Authentication in the web app. I also mapped the .bat extension to cmd.exe. When I click the button that's associated with calling the batch file, I can see that the file copy works, but nothing happens with the drive mapping command. (this is accomplished by checking whether the directory exists elsewhere in the code). Any ideas? I hope I posted this to the right place. I'm wondering if it has something to do the particular executable...

    Y 1 Reply Last reply
    0
    • A alchong

      Greetings... I'm currently working with IIS 5.1, developing a web app using C#, and testing on win xp pro. One of the functions of the web app is to map a drive letter to a network resource. The way I'm going about this is calling a batch file from the application: System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = @"C:\tmp\testBat.bat"; proc.Start(); The batch file contains the following: copy "C:\tmp\src\test.txt" "C:\tmp\dst\testcopy4.txt" net use X: I've setup impersonation in web.config, and am only using Integrated Windows Authentication in the web app. I also mapped the .bat extension to cmd.exe. When I click the button that's associated with calling the batch file, I can see that the file copy works, but nothing happens with the drive mapping command. (this is accomplished by checking whether the directory exists elsewhere in the code). Any ideas? I hope I posted this to the right place. I'm wondering if it has something to do the particular executable...

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      alchong wrote:

      net use X:

      Well do you have drive X mapped? what do get if run net use command

      Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

      A 1 Reply Last reply
      0
      • Y Yusuf

        alchong wrote:

        net use X:

        Well do you have drive X mapped? what do get if run net use command

        Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

        A Offline
        A Offline
        alchong
        wrote on last edited by
        #3

        Hi Yusuf, I didn't realize that the rest of the "net use X:" line got hidden because the editor thought it was html because I placed it between brackets. What I meant to say is: net use X: <some network resource path> I didn't review my post closely enough. Apologies! and update of my troubleshooting, when I look at the task manager on my computer, I see that when the batch file executes, cmd.exe and net.exe run under the ASPNET user name. I'm not sure why this is, since I set up impersonation, perhaps I'm missing something in my configuration?

        modified on Thursday, April 9, 2009 12:03 PM

        Y 1 Reply Last reply
        0
        • A alchong

          Hi Yusuf, I didn't realize that the rest of the "net use X:" line got hidden because the editor thought it was html because I placed it between brackets. What I meant to say is: net use X: <some network resource path> I didn't review my post closely enough. Apologies! and update of my troubleshooting, when I look at the task manager on my computer, I see that when the batch file executes, cmd.exe and net.exe run under the ASPNET user name. I'm not sure why this is, since I set up impersonation, perhaps I'm missing something in my configuration?

          modified on Thursday, April 9, 2009 12:03 PM

          Y Offline
          Y Offline
          Yusuf
          wrote on last edited by
          #4

          what do you get if you run your batch file manually on the server.

          Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

          A 1 Reply Last reply
          0
          • Y Yusuf

            what do you get if you run your batch file manually on the server.

            Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

            A Offline
            A Offline
            alchong
            wrote on last edited by
            #5

            When I run the batch file manually it works. Also I edited my last message, but if you didn't catch it, when the batch runs from the web application, I noted that cmd.exe and net.exe run under the ASPNET user name, and do not seem to terminate. Is this something to do with my configuration? I thought I setup impersonation properly.

            Y 1 Reply Last reply
            0
            • A alchong

              When I run the batch file manually it works. Also I edited my last message, but if you didn't catch it, when the batch runs from the web application, I noted that cmd.exe and net.exe run under the ASPNET user name, and do not seem to terminate. Is this something to do with my configuration? I thought I setup impersonation properly.

              Y Offline
              Y Offline
              Yusuf
              wrote on last edited by
              #6

              alchong wrote:

              I noted that cmd.exe and net.exe run under the ASPNET user name, and do not seem to terminate.

              You need to set the flag to terminate the command window. I don't remember since it has been very long time. run cmd /? and you will figure it out.

              alchong wrote:

              Is this something to do with my configuration? I thought I setup impersonation properly.

              I don't know. may be asp.net account can not perform network actions. again this is a guess, I have no proof for that.

              Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

              A 1 Reply Last reply
              0
              • Y Yusuf

                alchong wrote:

                I noted that cmd.exe and net.exe run under the ASPNET user name, and do not seem to terminate.

                You need to set the flag to terminate the command window. I don't remember since it has been very long time. run cmd /? and you will figure it out.

                alchong wrote:

                Is this something to do with my configuration? I thought I setup impersonation properly.

                I don't know. may be asp.net account can not perform network actions. again this is a guess, I have no proof for that.

                Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

                A Offline
                A Offline
                alchong
                wrote on last edited by
                #7

                Hi Yusuf, /C was the flag. I guess I'll need to figure out if I can configure impersonation properly to run net.exe & cmd.exe under the web application user credentials instead of the ASPNET account.

                Y 1 Reply Last reply
                0
                • A alchong

                  Hi Yusuf, /C was the flag. I guess I'll need to figure out if I can configure impersonation properly to run net.exe & cmd.exe under the web application user credentials instead of the ASPNET account.

                  Y Offline
                  Y Offline
                  Yusuf
                  wrote on last edited by
                  #8

                  Good luck. Let us know your finding. We can all learn from your work. Thanks

                  Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups