Reputation: 976
My code is running elevated but nothing can see/execute c:\windows\system32\rstrui.exe (System Restore Point UI).
I double checked to make sure the code really was running elevated (it is), and I've tested with File.Exist() and Directory.GetFiles() and System.Diagnostics.Process.Start(); file not found is what is returned.
The program is really there, I can really run it, I can copy/paste the path to DOS and list it, execute it (no hidden spaces, etc.).
Any ideas?
THE SOLUTION:
Tim (below) gave me the solution, instead of referencing c:\windows\system32 reference c:\windows\sysnative. The "sysnative" gets redirected, or, well, doesn't. I'm still a bit confused about x64 redirection stuff. The point is, the following works:
Environment.GetEnvironmentVariable("windir") + @"\sysnative"
Thanks Tim!
Upvotes: 3
Views: 1402
Reputation: 15247
Let me guess... you're running as an x86 application on a 64 bit installation of Windows? I'm not sure of the reason, but this thread provides some information. If you compile it for native 64 bit (or Any CPU I suppose) instead of x86, it'll find the file properly.
The reason for this is the System Folder Redirection that's going on in 64bit OS's on applications that are running under WOW64. You can read more about it here. One particularly relevant chunk of that post is talking about how to get around it:
Applications can control the WOW64 file system redirector using the Wow64DisableWow64FsRedirection, Wow64EnableWow64FsRedirection, and Wow64RevertWow64FsRedirection functions. Disabling file system redirection affects all file operations performed by the calling thread, so it should be disabled only when necessary for a single CreateFile call and re-enabled again immediately after the function returns. Disabling file system redirection for longer periods can prevent 32-bit applications from loading system DLLs, causing the applications to fail.
32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.
I was unable to get the %windir%\Sysnative
idea working, but I'm hopeful that either that works for you or you can implement the enabling/disabling of redirection.
Upvotes: 8