0

I have an app in VFP wich is in migrating process to .NET c#, as a aprt of this we have to desktops for the app

desktop one in vfp: It has all menus, those menus save the selected option in a SQLServer table if the option is implmented on .net.

desktop two in wpf: It has a timer that read the options clicked by the users on desktop one (vfp)

If an option is found by desktop two, and this option match with the user expected, it try to open the option and set it as topmost.

This work well but some times throw an win32 Exception Access denied

[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("MyClass")]
public class DesktopsAux
{
    public string[] Desktops;
    public string desktopname = "My App! .Net Desktop";
    public IntPtr hWnd; 

    public DesktopsAux()
    {
        try
        {
            var q = from d in Process.GetProcesses()
                         where d.MainWindowTitle.Contains(desktopname) 
                         select d.MainWindowTitle;

            Desktops = q.ToArray();
        }
        catch (NullReferenceException)
        {
        }
    }

    public bool DeskTopForUser(string userName)
    {
        //  The error happen here, performing this query
        var q = from d in Process.GetProcesses()
                where d.MainWindowTitle.Contains(desktopname)
                select new {d.MainWindowTitle , d.Handle};
        var list = q.ToList();
        var q2 = from a in list
                 where a.MainWindowTitle.Contains(userName)
                 select a;

        if (q2.Count() > 0)
        {
            hWnd = q2.First().Handle;
            return true;
        }
        return false;
    }
}

public class Desktop
{
    public string MainWindowTitle { get; set; }
    public IntPtr Handle { get; set; }
}

The error happen in DeskTopForUser Method just when perform the query.

Why this error happen? How can I do to prevent this error?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Juan Pablo Gomez
  • 5,203
  • 11
  • 55
  • 101
  • Maybe an elevated process that can't be enumerated? See [here](http://www.aboutmycode.com/net-framework/how-to-get-elevated-process-path-in-net/) and [here](http://stackoverflow.com/questions/8431298/process-mainmodule-access-is-denied). – Michael Todd Sep 25 '13 at 21:58
  • @MichaelTodd Tks for your help, really i don't know much about this. It mean? – Juan Pablo Gomez Sep 25 '13 at 22:20

0 Answers0