Results 1 to 4 of 4

Thread: [RESOLVED] Process failing to open file

  1. #1

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    813

    Resolved [RESOLVED] Process failing to open file

    Hi I am makeing a program to start the programs in the start menu how ever I come accross a few programs that throw an error saying the file is not found when it is any idea what is wrong for example the code below will not open the on screen key board app, even if run as admin seems odd, I tryed the shellexecute api call and that fails to. but when I paste the file into the run dialog it opens fine what c#'s problum with executeing files right.

    example.

    Code:
     //Will return error file not found
                Process p = new Process();
                p.StartInfo.FileName = "C:\\WINDOWS\\system32\\osk.exe";
                p.Start();

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,457

    Re: Process failing to open file

    You didn't say what version of Windows you are running or the "bitness" of your compiled C# exe file. That being the case, the issue is almost certainly that you are running a 64 bit version of Windows, your C# program is 32 bit, and you are running into the issue of File System Redirection:

    https://learn.microsoft.com/en-us/wi...tem-redirector

    For your example above, if you change "system32" to "SysNative", does it then work? If so, then you will need to do that for all other paths where the target file is in "system32".

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,965

    Re: Process failing to open file

    Don't hardcode a path like that if you can possibly avoid it. You should be using Environment.GetFolderPath and specifying System or SystemX86 for the SpecialFolder value as required. I believe that should then direct you to the correct location. I'm not completely sure of that in this case though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    813

    Re: Process failing to open file

    Thanks Both for the answers I switched the project platform to 64bit and it now works thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width