how could I execute a dll as a exe using batch

13,105

Solution 1

If i understand it, you have a myProgram.exe file renamed as myProgram.dll and want to run that executable.

If this is the case then all you need is to directly invoke the file. To test, from command line, from the same directory where the file is, type myProgram.dll and it will execute. The OS will identify the file as executable an run it.

If you want to execute the program from another directory, and you supply the full path to the executable, it will also work.

BUT if you want to call the executable from another directory without indicating the full path to the executable, using the PATH variable to locate the program, it will not work.

When a program is search over the folders indicated in PATH variable, the content of variable PATHEXT determine the extensions of files to search in PATH folders. And .dll is not in this list.

So, or you indicate the full path to the executable (absolute o relative) or include the .dll extension in the PATHEXT variable before calling your executable.

Solution 2

If the DLL is a .NET assembly it could be rather easy. For instance, a .NET dll may be accessed from batch file (via) powerhshell like this.

cmd /c start /b Powershell -command "[System.Net.Dns]::GetHostByAddress('8.8.8.8')" 

That would allow you to access the .NET system DLL that handles the DNS namespace and call it's methods directly.

Share:
13,105

Related videos on Youtube

09stephenb
Author by

09stephenb

hello.

Updated on October 14, 2022

Comments