7 Replies - 760 Views - Last Post: 05 August 2011 - 03:31 PM Rate Topic: -----

#1 geewhiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 20-August 07

Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 08:38 AM

Hello all.

So I just got myself an upgrade to my development box. And now I'm in the world of Windows 7.
Ok, so a long story short... now whenever I spawn a seperate process to do some work with an external .exe, that processing .exe does not (or is not allowed) to create files like it used to.

I'm thinking this might have something to do with elevated user rights and the like associated with the UAC?

At any rate, I'm going to provide some stripped down code of what I'm doing and hopefully someone can help or just flat out tell me that it should be done another way now.

So basically inside of my GUI when the time is right I'll create a worker thread of sort(though as of right now I'm not actually using workerthreads). Simply...

// Create our file processing thread
Thread ProcessingThread = new Thread(new ThreadStart(FileProcessor));
ProcessingThread.Start();


From this thread I spawn processes using various tools, for example, ffmpeg.
So I'll create a process using ffmpeg to demux a videoclip into a video and audio file, like so:

// Video demux routine that calls ffmpeg for the magic
ProcessStartInfo ffmpegdemux = new ProcessStartInfo();
ffmpegdemux.CreateNoWindow = GlobalClass.CreateNoWindow;
ffmpegdemux.UseShellExecute = false;
ffmpegdemux.FileName = GlobalClass.ExecutionPaths[0] + "ffmpeg\\bin\\ffmpeg.exe";
ffmpegdemux.WindowStyle = ProcessWindowStyle.Normal;
ffmpegdemux.Verb = "runas";
ffmpegdemux.Arguments = "....bunch of junk";
// Start our demuxing process
using (Process DemuxProcess = Process.Start(ffmpegdemux))
{
  DemuxProcess.WaitForExit();
}



With the arguments that I'm using, after this process runs I should have 2 files left over. I should have 1 video.m2v file and 1 audio.mp2 file located in my "GlobalClass.ExecutionPaths[0] + "ffmpeg\\bin\\" folder.

In windows XP this code ran flawlessly, but now for some reason I'm not getting any created files.

So I came across a page that discussed using:

ffmpegdemux.Verb = "runas";


to run created processes at full rights. I wasn't using that line before. But it hasn't helped any.
Kinda at a loss for the moment.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating Processes in Windows 7 with UAC enabled.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 09:25 AM

To where are you attempting to write your files? The spawned process should take on the privileges of the spawner.
Was This Post Helpful? 0
  • +
  • -

#3 geewhiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 20-August 07

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 10:21 AM

To just a made up folder that I've created: c:\downloads\ffmpeg\bin\

The write-to location is the same as the ffmpeg.exe file that I'm using in my process.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 10:29 AM

Well I guess the first thing to do is to determine why exactly the files aren't getting created. Are exceptions thrown? Something logged? Can you run it in a debugger?
Was This Post Helpful? 0
  • +
  • -

#5 geewhiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 20-August 07

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 11:14 AM

Well this is what really has me scratching my head now.

I have exception and catch code everywhere before and after the creation of (many) files for clean-up purposes.
I have not been getting any exceptions or stops until after my FileProcessor thread is done.

When FileProcessor has finished, I write a little more information to the processed file from a separate thread that has been created by the program's main process. It is there that I get a file not found error, which I should because there is no final outputted file. But I should have at least 10 file not found errors before that...

I have put some stop interrupts through the FileProcessor routine after file creation events, I do not see the files being created but I'm not getting any errors or exceptions?
Was This Post Helpful? 0
  • +
  • -

#6 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 12:20 PM

Exception handling with threads can be an issue. What do you do when an exception is thrown in your file creation thread?
Was This Post Helpful? 0
  • +
  • -

#7 geewhiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 20-August 07

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 12:56 PM

I've pulled my demux routine and put it into the the main process along with another routine that uses files created from the demux. I'm not getting any exceptions on the second routine.

try
{
  ProcessStartInfo ffmpegmp2mp3 = new ProcessStartInfo();
  ffmpegmp2mp3.CreateNoWindow = GlobalClass.CreateNoWindow;
  ffmpegmp2mp3.UseShellExecute = false;
  ffmpegmp2mp3.FileName = GlobalClass.ExecutionPaths[0] + "ffmpeg\\bin\\ffmpeg.exe";
  ffmpegmp2mp3.WindowStyle = ProcessWindowStyle.Normal;
  ffmpegmp2mp3.Arguments = "-i " + GlobalClass.ExecutionPaths[0] + "ffmpeg\\bin\\Audio.mp2";
  using (Process MP2toMP3Process = Process.Start(ffmpegmp2mp3))
  {
    // Let's wait for our process to finish before returning
    MP2toMP3Process.WaitForExit();
  }
catch (Exception ex)
{
  MessageBox.Show(ex.ToString(), "Error while converting MP2 to MP3 audio", MessageBoxButtons.OK, MessageBoxIcon.Question);
}



If there is a problem executing the process, like it can't find the input argument file, I should get the exception.
Was This Post Helpful? 0
  • +
  • -

#8 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Creating Processes in Windows 7 with UAC enabled.

Posted 05 August 2011 - 03:31 PM

Exceptions thrown in threads can't be caught by code outside the thread. You need to catch the exception in the ffmpegmp2mp3 code. This is what I was talking about when I said exceptions and threads can cause issues.

Any try/catch/finally blocks in scope when a thread is created are of no relevance to the thread when it starts executing. Consider the following program:
public static void Main() {
    try {
        new Thread (Go).Start();
    } catch (Exception ex) {
        // We'll never get here!
        Console.WriteLine ("Exception!");
    }
}

static void Go() { throw null; } // Throws a NullReferenceException

This post has been edited by Momerath: 05 August 2011 - 03:34 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1