My.Computer.FileSystem.FileExists("C:\Windows\System32\explorer.exe") - wrong answer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: My.Computer.FileSystem.FileExists("C:\Windows\System32\explorer.exe") - wrong answer

  1. #1
    Join Date
    Jun 2013
    Posts
    1

    My.Computer.FileSystem.FileExists("C:\Windows\System32\explorer.exe") - wrong answer

    I have encountered a false positive from My.Computer.FileSystem.FileExists(filename) where there are no spaces in filename.
    I am coding my own routine to find the first occurrence of a file in the directories listed in the %PATH% environment variable. I thought there would be one available ... but it seems not.
    I take each directory in the PATH, and first check that the directory exists. If the directory exists I add the name of the file to the directory-name to get a full-path-name and check for FileExists(full-path-name).
    My.Computer.FileSystem.FileExists("C:\Windows\System32\explorer.exe") returns TRUE ... but it does not exist. It cannot be access permissions ... because, as per MS documentation, inadequate permissions may give a false negative, but not a false positive.

    However C:\Windows\explorer.exe does exist. Perhaps it is finding this. I cannot test this because I cannot rename it ..."Access is denied". But I did test by copying explorer.exe to a user directory and in this case I can look one folder either side of where I have copied explorer.exe and it correctly returns FALSE ... so it seems to be something related particularly to the C:\Windows\System32 folder structure.

    To summarize:
    The file C:\Windows\explorer.exe exists.
    The file C:\Windows\System32\explorer.exe does not exist.
    [I have folder options set to show hidden files, folders, drives and display protected operating system files ... so I would see it if it was there.]

    My.Computer.FileSystem.FileExists("C:\explorer.exe") returns FALSE ... this is correct.
    My.Computer.FileSystem.FileExists("C:\Windows\explorer.exe") returns TRUE ... this is correct.
    My.Computer.FileSystem.FileExists("C:\Windows\System32\explorer.exe") returns TRUE ... this is NOT correct.

    Hmmm. My system has a 64 bit processor.
    The file "C:\Windows\SysWOW64\explorer.exe does exist. Maybe FileExists() treats System32 as an alias for SysWOW64 finding explorer.exe and Process.Start does not.

    This is frustrating because having "found" ... file="C:\Windows\System32\explorer.exe" ... if you Process.start(file,etc.) ... you get "Can't find file" message. And I am not surprised because it does not exist.
    I am using Process.Start(startInfo) with startInfo.UseShellExecute = FALSE so I can set USERNAME etc. otherwise I cannot subsequently identify the Explorer process.
    If you use startInfo.UseShellExecute = TRUE, then you do not need to find the file because the shell execute uses the PATH to correctly to find the explorer app. How?
    But the process structure returned is then not for the explorer-open-on-the-folder but for the explorer-startup-process ... which you cannot subsequently switch to.

    So either I can start explorer but have no way to get a handle on the process.
    Or I supply startInfo with domain, username password etc. to allow the process to be subsequently picked out of the process list ... but I cannot reliably find the executable to run it.

    Even System.IO.FileInfo incorrectly reports that the file "C:\Windows\System32\explorer.exe" exists.
    Operating System: Windows 7 Enterprise SP1

    My initial problem was simple. A button to start Explorer in a particular folder.
    Easy enough ... but I don't want another Explorer for every button click.
    If I already have an Explorer window started ... then switch to it.
    Otherwise start one up and somehow keep tabs on the process that I start so I can switch to it later ... if it is still there.

    But I am unable to start Explorer in such a way that I can subsequently identify it. Stumped.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,781

    Re: My.Computer.FileSystem.FileExists("C:\Windows\System32\explorer.exe") - wrong ans

    hmm... I have not used the My.Computer method for checking files. I generally use System.Io.File.Exists() though I'm not sure that would make a difference in this case. May be worth a try.
    Always use [code][/code] tags when posting code.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center