Вопрос

I'm building a project that will allow a user to upload a video to the server and the server will encode the video in certain formats. Once the upload is done, a vbs script should execute to do the things I need it to do.

I'm having a really difficult time with getting the script to run on the server, though. When debugging in VS2012 on the server itself, I can get this to work fine. However, when I deploy it and run the same code, it doesn't work.

I tried taking a step back and I'm attempting to get ANY program to execute, but it's not working. Here is my code that I'm running to try and open notepad after a file is uploaded:

//file is saved
                try
                {
                    ProcessStartInfo psi = new ProcessStartInfo(@"C:\Windows\System32\notepad.exe");
                    Process proc = new Process();
                    proc.StartInfo = psi;
                    proc.StartInfo.FileName = @"C:\Windows\System32\notepad.exe";
                    bool didItStart = proc.Start();                    
                }
                catch(Exception ex)
                {                   
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\test\log.txt"))
                    {
                        file.WriteLine(ex.InnerException + " " + ex);
                    }
                }

This doesn't throw any errors, nothing is written to the log file. Nothing happens. I've been googling for a while and have found and tried a bunch of things which haven't worked, including impersonation, changing the permissions on the folder that the script was in and changing the permission of the folder the scripts are in to include the IIS user and nothing has worked.

Why isn't this working?

Это было полезно?

Решение

When I run your code, Task Manager shows that there is a new Notepad.exe process running as the "ASP.NET v4.0" user. I can't see this instance of Notepad, as it is running in a non-interactive session separate from my own. Not all applications will successfully run in a session like this; the user profile isn't loaded and that can cause problems for an application that isn't expecting it.

Even if you get this to work, spawning an arbitrary number of processes is a questionable strategy. If your task is compute-bound (like this one might be), your performance will suffer once you have more tasks than cores. Think about reworking your solution to use a work queue.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top