Solved

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

Posted on 2008-09-30
5
7,624 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 7

Expert Comment

by:FOTC
Comment Utility
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 7

Expert Comment

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

Author Comment

by:thaimin
Comment Utility
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
Comment Utility
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Disclosure: Use this tutorial only when no other options helps to get Windows XP running without any problems and you don't want to format the drive. The back up of the data is the responsible of the user, however there is a description of how t…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now