Check on avaiable port using wmi win32 class?

2019-02-27 18:28发布

I am using inno setup to make an installation file. It required to pull local ip address (which I able to do by querying Win32_NetworkAdapterConfiguration) and check if a specific port is open for the software to run on (which I am currently looking for an answer).

I realize that WMI Win32 classes contain so many useful information. So I wonder which Win32 class should I use to check on this port given that if it is possible to do that?

Thank you,

2条回答
唯我独甜
2楼-- · 2019-02-27 19:17

AFAIK the only WMI class to check if a given port is open is the NetDiagnostics WMI class and the ConnectToPort method, but this class only is present in Windows XP. So if you want an option which works in another Windows versions you can try to import (or write your own application and invoke from inno) something like the Winsock connect function, like is show on this question How to check if a TCP port is available with Delphi?

查看更多
唯我独甜
3楼-- · 2019-02-27 19:31

Just try to bind a socket to it. If it succeeds, it's available.

查看更多
登录 后发表回答