Check on avaiable port using wmi win32 class?

人走茶凉 提交于 2019-12-02 08:04:45

问题


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,


回答1:


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?




回答2:


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



来源:https://stackoverflow.com/questions/13295277/check-on-avaiable-port-using-wmi-win32-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!