Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-09-30
5
Medium Priority
?
7,703 Views
Last Modified: 2008-10-26
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
Comment
Question by:thaimin
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:FOTC
ID: 22604625
can't you just have the program call the network connections window:

start %windir%\system32\ncpa.cpl

?

or am i misreading the question?
0
 
LVL 8

Expert Comment

by:FOTC
ID: 22604634
sorry didn't see the "other things i've tried" part.
0
 
LVL 1

Author Comment

by:thaimin
ID: 22606111
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
 
LVL 1

Accepted Solution

by:
thaimin earned 0 total points
ID: 22610777
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question