Check if an executable exists in the Windows path

后端 未结 8 1723
栀梦
栀梦 2020-11-29 06:39

If I run a process with ShellExecute (or in .net with System.Diagnostics.Process.Start()) the filename process to start doesn\'t need to be a full

8条回答
  •  遥遥无期
    2020-11-29 07:01

    Much shorter and direct, which is what the poster wanted.

    FILE *fp
    char loc_of_notepad[80] = "Not Found";
    
    // Create a pipe to run the build-in where command
    // It will return the location of notepad
    fp = popen("cmd /C where notepad", "r");
    // Read a line from the pipe, if notepad is found 
    // this will be the location (followed by a '\n')
    fgets(loc_of_notepad, 80, fp);
    fclose(fp);
    
    printf("Notepad Location: %s", loc_of_notepad);
    

提交回复
热议问题