Good day.
Are there any methods to find the location of the .ехе file in C #. You need to programmatically find out the location of sqlcmd.exe If you search through the registry, then on different computers it is located in different places. Thank.

  • one
    What are you going to do with him after finding something? - Spawn
  • You need to save the address to a variable. - Telsystems

1 answer 1

I can advise the following:

  • Search paths in Environment.GetEnvironmentVariables("path")

     Environment.GetEnvironmentVariable("path") .Split(';') .Select(dir => Path.Combine(dir, "sqlcmd.exe")) .FirstOrDefault(File.Exists); 
  • Search the registry.

  • Ask the user to specify the path.
  • Thanks, it helped. - Telsystems
  • Uh ... Process.Start ? And if you need to find the path to format.com ? - VladD
  • @VladD, well, I would not advise in this case) Although, of course, Process.Start should have been the last to use ... - Spawn
  • one
    Why not start with Environment.GetEnvironmentVariable ("path"). Split (';')? - VladD
  • As I understand it, further search for the file in question through the specified paths? Yes, an option ... The environment variables do not immediately come to my head for some reason ... And how, by the way, is this process cleverly handled? % TFSPowerToolDir% - Spawn