?
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,684 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
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

743 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