-
Apr 1st, 2024, 05:08 PM
#1
Thread Starter
Fanatic Member
[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();
-
Apr 1st, 2024, 06:55 PM
#2
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".
-
Apr 1st, 2024, 07:58 PM
#3
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.
-
Apr 2nd, 2024, 10:46 AM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|