• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7708
  • Last Modified:

Start network connection properties for each adapter from command line - almost there but not quite

I am trying to be able to open the network connection properties from the command line / with a program (if it works on the command line I can use ShellExecute or CreateProcess, if it works in a program only, that is just as good!)

These are the typical property pages that show up when you double click on the network adapters in the Network Connections. Sometimes these are a bit odd (you get the list of available networks for a wireless network, preferable would be to jump straight to the advanced properties).

I have a partial solution. I got this working on Vista and almost on XP (having XP support is a must). To do this I run:

start ::{208D2C60-3AEA-1069-A2D7-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\::{GUID of network card}

The first GUID is of the Network Folder, second is of the Network Connections folder. This command also works with the first ::{...}\ dropped out. The GUID of each network card can be found in the registry at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards". There are also numerous ways to get them programatically. Running this command using "explorer.exe" or "explorer.exe /e," also works however about half the time it fails to actually open the window. Using "start" always works.

As I said before, on Vista this always works, even inside a program. However, I was just testing on XP, and only my Local Area Connection will open this way. The other ones almost seem to work because if you enter a GUID of a non-existent adapter it complains the path cannot be found, however running it with real ones makes the command prompt flash for a second but no window opens.

Any ideas on how to get this working in XP?

-----
Other things I have tried:
The NT method of using ncpa.cpl,@... which no longer works apparently, will only open the network connections folder
If I create a shortcut to a connection (which gets put on the desktop), I get a shortcut referencing the GUID {BA126ADB-2166-11D1-B1D0-00805FC1270E} no matter which adapter. Examining the link with a hex editor, I find this GUID in there, and immediately following it is the GUID of the adapter. The GUID used for these shortcuts (the {BA126....} one) doesn't seem to work on the command line and I always get failures from it.
0
thaimin
Asked:
thaimin
  • 2
  • 2
1 Solution
 
FOTCCommented:
can't you just have the program call the network connections window:

start %windir%\system32\ncpa.cpl

?

or am i misreading the question?
0
 
FOTCCommented:
sorry didn't see the "other things i've tried" part.
0
 
thaiminAuthor Commented:
I am trying to open specific network connection properties, not just the whole network connections. In NT you used to be able to use that to open properties by doing @0, @1, @2, .... for this first, second, third, ... adapter. Not so anymore.
0
 
thaiminAuthor Commented:
After working on this for an entire day, I found a solution! It is quite simple actually, but does not work from the standard command line but requires the use of "ShellExecute".

Basically, the GUIDs were all working perfectly fine, even on XP, the problem was that XP was not able to always retrieve the "verb" to use on them. I noticed this when the network adapter would change state (say if I disabled it), the start command would no longer work. If you set the "verb" of ShellExecute to "properties" then it always opens the property dialog (just like I actually wanted).

One behavior difference in Vista and XP is that in Vista, the new dialog properly sets the owner to whatever you pass (so that it is basic modal - you could pass NULL and it would not be modal). However in XP it is never modal. I found a few tricks around this, but they aren't very pretty.

Attach is a sample code script to open the dialog given the GUID as a string in the form {....}. The cat function is a custom function to concatenate strings.
void openProperties(char* guid, HWND window) {
	char* path = cat(2, 0, L"::{208D2C60-3AEA-1069-A2D7-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\\::", guid);
	BOOL retval = ShellExecute(window, "properties", path, "", path, SW_NORMAL);
	delete[] path;
}

Open in new window

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now