Windows win32: how find active network profile using c++? Private, Public or Domain - winapi

Windows provides network profiles Private, Public and Domain.
Just wanted to know
how to find which active network profile using c++ Windows win32
something like powershell output
get-netconnectionprofile
Name : Network
InterfaceAlias : Ethernet0
InterfaceIndex : 4
NetworkCategory : Public
DomainAuthenticationKind : None
IPv4Connectivity : Internet
IPv6Connectivity : NoTraffic

Related

Windows Embedded Handheld 6.5 Professional VPN Configuration

I am trying to connect the Windows Embedded Handheld 6.5 Professional to a L2TP/IPSec VPN server with given configuration:
Remote Gateway : xxx.xxx.xxx.xx
Authentication Method : Pre-shared key : xxxxxxxxxxxx
Mode : Aggressive
Phase-1 Proposal:  aes128-sha256
DH Group : 5
Phase-2 Proposal:  aes256-sha1
PFS:  enable
DH Group:   5
User-name: xxxxxxxxxx
Password: xxxxxxxxxx
Every time i try to connect, it gives error of wrong user-name and password. I have successfully used above mentioned details to connect from Desktop.
I have tried the following:
https://www.youtube.com/watch?v=dwW8Mx7SYjo
https://support.honeywellaidc.com/s/article/How-to-setup-a-VPN-connection-on-devices-with-Windows-Mobile
Does the device support SHA2? Windows Mobile devices (Windows Embedded Handheld) do not support SHA2 before a defined AKU (35) has been implemented within the firmware: https://support.microsoft.com/en-us/help/2986556/windows-embedded-handheld-6-5-does-not-support-sha2.
See also: https://support.honeywellaidc.com/s/article/Does-Windows-Embedded-HandHeld-support-SHA-256-certificates (as you linked a honeywell article).

Need to determine the Network Access Type of an Ethernet adapter

I am in need to trying to figure out the Network Access Type of an ethernet connection on various virtual machines.
In short i am trying to find an analogy for
(Get-NetConnectionProfile).IPv4Connectivity
which works great Windows 2012 onwards, i am looking to run this query against Windows 2008 R2 servers.
I got this working on a Windows 2008 server, using a .NET class, cast to an object in powershell, Sample code as follows:
$nlm = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$nlm.GetNetworkConnections() | ForEach-Object {
     [PSCustomObject]#{
         NetworkName = ($_.GetNetwork().GetName());
         isConnectedToInternet = $_.isConnectedToInternet;
     }
if ($nlm.IsConnectedToInternet)
{
$NLAState = 'Internet'
}
"Access type : $NLAState"

How to check that an internet connection is available from a Windows local service?

How to check that an internet connection is available from a Windows local service? the InternetGetConnectedState API can not be used from a service according MSDN.
Which OS ?
Windows 8 :
GetInternetConnectionProfile()
more informations on MSDN
Windows 7 :
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
more informations on MSDN
For all :
Why you don't use ping ?
Edit : I had not seen the comment about ping

Renaming the network interface name via command line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
I want to rename the network interface name to a default name, for example "Ethernet", via dos.
I know netsh interface set interface name=”Local Area Connection” newname=”Ethernet” is the way to do it.
I am running a script and it will not know the name of the interace, correct? So, I need it to rename it to a default before I set the IP address for the interface.
How can I do this without knowing the name of the interface?
Is there a way to get the name of the interface somehow and then change it?
netsh (a tool MS tried to wean us off and gave up)
To get the WLAN interface names: netsh wlan show interfaces
      help states: show interfaces - Shows a list of the wireless LAN interfaces on the system.
To get LAN interface names: netsh lan show interfaces
      help states: show interfaces - Shows a list of the current wired interfaces on the system.
To get names of all interfaces: netsh interface show interface
      help states: show interfaces - Displays interfaces.
The command for LAN does need Wired AutoConfig service, which is usually not started.
This Batch script would start the service, get (the last) LAN interfaces name, change it to a new name, stop the Wired AutoConfig service again.
sc.exe start dot3svc
for /f "tokens=1* delims=: " %%a in ('netsh lan show interfaces') do if %%a == Name set activeAdapter=%%b
echo %activeAdapter%
netsh interface set interface name="%activeAdapter%" newname="Ethernet"
sc.exe stop dot3svc
Limitations:
It assumes there is only one wired interface
It will stop Wired AutoConfig service whether it was running or not at the start
For Wifi interfaces, change in above script 'lan' to 'wlan' and remove both sc.exe service start/stop
PowerShell
To get better control of what interface is renamed PowerShell will be an easier choice.
This will probably work in most cases:
Get-NetAdapter | Where-Object { $_.HardwareInterface -eq $True -and $_.MediaType -eq "802.3" } | Rename-NetAdapter -NewName "Ethernet"
HardwareInterface will eliminate virtual interfaces, e.g. VMWare
MediaType 802.3 will only show "wired" interfaces and not Wifi, Broadband or others.
In a script file, use the above version of the command, shorthand version would be:
Get-NetAdapter | ? HardwareInterface | ? MediaType -eq "802.3" | Rename-NetAdapter "Ethernet"
There are more options how to select the desired interface. Check all parameters by which it can be selected:
(Get-NetAdapter)[0] | Format-List -Property * -Force
e.g.
List all made by Realtek (Realtek vendor 10ec, Intel: 8086):
Get-NetAdapter | ? ComponentID -like "PCI\VEN_10EC*"
Not virtual:
Get-NetAdapter | ? Virtual -eq $false
Connector Present:
Get-NetAdapter | ? ConnectorPresent
Then there is WMI object
Get-WmiObject -Class Win32_NetworkAdapterConfiguration
Registry
In a case that you changed a Network adapter card and a new one is using a name: Ethernet 2 or similar and you want to rename it back to "Ethernet",
there will be an error saying:
"You were not connected because a duplicate name exists on the network. If joining a domain, go to System in Control Panel to change the computer name and try again. If joining a workgroup, choose another workgroup name."
Which is of course erroneous error message about renaming a computer.
PowerShell would say correctly: An attempt was made to create an object and the object name already existed.
But going to Control Panel\Network and Internet\Network Connections and trying to rename the interface there would not help either.
It seems the only option for such case is to find corresponding key in these registry paths:
HKEY_LOCAL_MACHINE\SYSTEM\Setup\Upgrade\NetworkDriverBackup\Control\Network\{4d36e972-e325-11ce-bfc1-08002be10318}\
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\
HKEY_LOCAL_MACHINE\SYSTEM\Setup\Upgrade\NetworkDriverBackup\Control\NetworkSetup2\Interfaces\
and remove the key for the old interface (not the whole paths as written above!), then restart.
Renaming by cmd batch, PS or in Control Panel should now work.
You can do quite a lot with Powershell, which depending on how new your server is, may be installed. Google "Get-WmiObject -Class Win32_NetworkAdapterConfiguration" to see more info.

Windows Store App, VPN, RAS Api

Our windows store app allows user to manage (create or dial) VPN profiles.
For this functionality we use
RAS Api (create and dial VPN profile)
RAS Api
Wlan Api (listen to wifi networks) - will be changed to classes with Windows.Networking.Connectivity in windows8
Wlan Api
We face following troubles for Windows Store application:
RAS API functions don't work properly under windows store application template (as example RasEnumDevices return error code 5 - Access Denied).
However it works good from desktop application launched on windows 8.
Question: how we could get RAS API to work under window store applications? If that is absolutely impossible - is there any other way to create VPN connection in app developed for Windows Store?
All user's VPN profiles stored by Windows OS in "..\Microsoft\Network\Connections\Pbk\rasphone.pbk", file could be found on file system manually, but we don't have access to this file via API, either we can't access it directrly. Current workarround uses own created PBK file located in users profile folder.
Question: how we could get access to system VPN connections stored in OS.
Thanks.
Hotspot Shield VPN for Windows offers private browsing to ensure the privacy of your web session.
Check it out here: http://www.anchorfree.com/hotspot-shield-VPN-download-windows.php

Resources