This article is a mirror article of machine translation, please click here to jump to the original article.

View: 26945|Reply: 0

[Console Program] C# determines whether an executable is present in the Windows environment variable

[Copy link]
Posted on 2020-3-25 16:22:03 | | | |
We are able to open the command window normally by pressing the Windows key + R, typing cmd, because cmd.exe executable is in our environment variables.

Some commands entered through the cmd window are also the corresponding executable files under the call environment variable.

Windows can determine whether an executable file exists by using the where command to determine whether there is an environment variable through cmd, as follows:



C:\Users>where cmd
C:\Windows\System32\cmd.exe

C:\Users>where sqlcmd
c:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.EXE

C:\Users>where sqlcmd.exe
c:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.EXE

C:\Users>where itsvse
INFO: Could not find files for the given pattern(s).
If you use .net/c# code, the code looks like this:



Call:

ExistsOnPath("notepad.exe"); // should return true

GetFullPath("notepad.exe"); // c:\windows\system32\notepad.exe

Note: When calling with C# code,Must bring the extensionCase insensitive





Previous:SQL method to determine if a function stored procedure exists
Next:SQL Server connection string Application Name parameter is explained in detail
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com