Check on avaiable port using wmi win32 class? - winapi

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,

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?

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

Related

Is there any method to let Windows think I'm always connected to Internet?

According to this article, since Windows 10 2004 Update KB4535996, A lot of users get disconnected notice even if they connected and browsers works properly.
This blocks me from using a lot applications, Is there any method like:
Globally Hook Windows NCSI(Network Connection Service Indicator) related API
Change Registry to a always-connected site, like point some site to 127.0.0.1 and hijack msftconnecttest.com to this local IP
Others you might know
to let windows think I'm always connected to Internet unless I disconnected physically?
Thank you.
PS. Related Registry Configurations are here:
Someone invented this thing to bypass this, check it out here:
https://github.com/dantmnf/NCSIOverride

How to get and send files from an application to another machine or Windows Explorer but not another application?

Sorry if my question is confusing but what I am looking to do is this. I am creating an application that is supposed to send and receive files directly to another machine without having to connect to any other application but the windows explorer on another machine. I know you can write a client and server much like a FTP program, but that's not what I am looking for. An application simply connects to Windows or windows explorer on another machine for sending or receiving files.
I have looked or researched for information online, but not much to look at.
Is there a way to do this? If so, how.
MORE INFO:
I want to be able to start my application on a machine and send and receive files automatically from or to another local machine without establishing any direct connection very much like what Microsoft Window does. You open your windows explorer and drag and drop files from or to another machine. Only that I want to do that programmatically within my application. I start my application and simply request or send for specific file at a specific location. The way I have it written now you have to run two different copies of the same program on different machines - one as a server and the other as a client.
Maybe what I am looking for is a way to get access to the filesystem of another local machine without socket to socket connection.
Thanks in advance.
Windows Explorer is not an application that foreign programs can "connect" to. You need to connect to something that will actually be listening for connections. The most direct way would probably be to set up a network share on the server and then use WNetAddConnection2 to connect to that share on the client.

INTERNET_OPEN_TYPE_DIRECT vs INTERNET_OPEN_TYPE_PRECONFIG

In this documentation for InternetOpen, the MSDN says:
Use INTERNET_OPEN_TYPE_DIRECT if the system on which the application is running uses a direct connection to the Internet. ...
Use INTERNET_OPEN_TYPE_PROXY if the system on which the application is running uses one or more proxy servers to access the Internet.
INTERNET_OPEN_TYPE_PRECONFIG looks at the registry values ProxyEnable, ProxyServer, and ProxyOverride. ... If ProxyEnable is zero, the application uses INTERNET_OPEN_TYPE_DIRECT. Otherwise, the application uses INTERNET_OPEN_TYPE_PROXY and uses the ProxyServer and ProxyOverride information.
I interpreted this to mean that if you were writing an application where there's any possibility of the user being behind a proxy, you should use INTERNET_OPEN_TYPE_PRECONFIG, and Windows will automatically go for the "direct" option if the user isn't behind a proxy.
However, a number of users have run into problems with badly configured Windows installs, which have a bad proxy server configured for some reason. Because we use INTERNET_OPEN_TYPE_PRECONFIG, internet access doesn't work for those users. Some of them can resolve the bad configuration, but not all.
Is there any downside to just using INTERNET_OPEN_TYPE_DIRECT instead of _PRECONFIG? It sounds like we should use _PRECONFIG if we want to be a good citizen, but we can save ourselves and our users a lot of headaches if we just use _DIRECT instead.

How to programatically create a VPN connection on Mac OS X?

I have a config file that completely describes how to connect to a VPN. I'd like to write a tool (C or Objective-C) to read in the file and then create a new VPN interface on the system.
I'm guessing the answer will have something to do with SCNetworkServiceCreate and/or SCNetworkInterfaceCreateWithInterface. Both of these want to bind to another interface. What stumps me is that, in theory, the VPN connections should ride on top of any IP interface so I'm at a loss what to use for the base interface.
Any help or pointers would be greatly appreciated.
macosvpn is a command line tool written in Objective-C over on GitHub which allows you to "Create Mac OS VPNs programmatically". E.g. to add a L2TP over IPSec VPN service you would do this:
sudo macosvpn create --l2tp Atlantic --endpoint atlantic.example.com --username Alice --password p4ssw0rd --shared-secret s3same
It should be straightforward to read your config file params into the command's flag args.
As of today macosvpn is available via Homebrew: brew install macosvp. Xcode is a build requirement.
Answering this for completeness.
So, the answer is not well documented. However, there is a magical constant interface definition for any protocol that you want to ride on top of the currently connected IPv4 interface, kSCNetworkInterfaceIPv4.
Therefore the code to create a new VPN builds the VPN stack on top of that interface.

Internet Access Controller using .net ( vb or c# )

I want to develop a software which restricts users internet access using vb6 or vb.net.
This is not a baby sitter program but
1) whenever a client machine takes any browser it should ask for username and password.
2)There should be option for adding new users at the server side application.
can anyone suggest any name of such a software. or some sites where I can get some help
on the same..
You could implement a HTTP proxy using sockets. You would turn off internet connection sharing on your server and configure the other machines to connect to the web via your proxy.
I would recommend going for an off the self solution e.g. in a router rather than building something from scratch.
If you are dead set on using VB6 you could make use of the winsock control. Here is a project using winsock to serve files. You could modify it to become a multithreaded proxy server instead. It will be a tough challenge though.
http://www.codeproject.com/KB/IP/winsock.aspx

Resources