1

From C# VS2013, I would like to get the whole path of an application that has been indtalled on win 7.

The post with 7 methods at:

   http://stackoverflow.com/questions/6041332/best-way-to-get-application-folder-path

cannot help me because I do Not need the path of the current running application.

I need the path of an application that has been installed (but currently not running).

I have tried

  string [] allfiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories) 

at

  http://stackoverflow.com/questions/23736343/recursive-search-for-files-in-root-directory-and-subfolders

But got:

 Additional information: Access to the path 'C:\Program Files\MSSomeApp\DATA' is denied.

My C# code:

 FileInfo executableFileInfo = new FileInfo("MyApplication.exe"); // It has been installed on win 7.
 string executableDirectoryName = executableFileInfo.DirectoryName;

This just returned my current VS2013 working directory. But, actually, "MyApplication.exe" was installed at C:\MyPath.

I need to get the full file path C:\MyPath\, where all libs and exe files (of MyApplication) are there.

Any suggestions ? thanks

Lily
  • 295
  • 1
  • 4
  • 14

1 Answers1

0

Well You can use something like:

    string[] paths = 
    System.IO.Directory.GetFiles(System.Environment.SpecialFolder.ProgramFiles,
 "MyApplication.exe", System.IO.SearchOption.AllDirectories);

This will look the Program Files Folder and all its Sub Folders for the file named MyApplication.exe and will return the full path of all of matches

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
  • @Lily well your program needs to have Administrator privilege to access the files in the "Program Files" folder. then the "Access Denied" error should be resolved. – Ashkan Mobayen Khiabani Mar 30 '16 at 00:03
  • The program will be run by any users, who may not have adm right on a computer. – Lily Mar 30 '16 at 00:06
  • well that can be problem. that is exactly why the admin privilege is needed. because not everybody should access the files. without admin access I don't think this will be possible. – Ashkan Mobayen Khiabani Mar 30 '16 at 00:10