ShellExecute problem with .lnk to 'Wireless Network Connection' on Windows XP

*NOTE*
This issue is specific to Windows XP, which is where I am requesting assistance. Windows 7 has plenty of avenues for making this work successfully and I do not have a problem there.

I am currently working on a project to provide access to a 'Wireless Network Connection' from within a custom shell program on XP (think kiosk). I have managed to programmatically create the necessary shortcut. Calling that shortcut via 'ShellExecute', correctly displays the 'View Available Wireless Networks' dialog when the adapter is not connected to a network.

The problem I have occurs once a network has been selected/connected to. The expected result of calling the link at this point is that the 'Properties' dialog will be displayed. However, I would be ok if it even continued to pull up the available networks list. Instead, 'ShellExecute' returns successful, but nothing is displayed.

I assume this has something to do with the default operation changing from 'available networks' to 'status' but I can not figure out how to make the call work.

Here are the functions I have for the creation of the .lnk file. Again, this code works fine and the shortcut works as expected when clicked. The only problem is when I call 'ShellExecute' while the wireless adapter is connected to a network.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//------------------------------------------------------------------------------
//	CreateWirelessShortcut
//
//		Creates a .lnk file for access to the wireless connection properties.
//
//		Args:
//			strWifiLink		= path and unique name for Wifi link (using the adapter GUID)
//
//		Return:
//			BOOL				= TRUE if successful
//
BOOL CMainFrame::CreateWirelessShortcut(const CString& strWifiLink)
{
	HRESULT		hResult		= NULL;

	hResult = ::CoCreateInstance(CLSID_ShellLink,
										  NULL,
										  CLSCTX_INPROC_SERVER,
										  IID_IShellLink,
										  (PVOID*)&m_piShellLink);

	if (SUCCEEDED(hResult))
	{
		IPersistFile*	piPersistFile	= NULL;

		GetNetConnPIDL();

		hResult = m_piShellLink->QueryInterface(IID_IPersistFile, (PVOID*)&piPersistFile);

		if (SUCCEEDED(hResult))
		{
			WCHAR	pszPath[MAX_PATH] = {0};

			if (::MultiByteToWideChar(CP_ACP, 0, strWifiLink, -1, pszPath, MAX_PATH) != 0)
			{
				hResult = piPersistFile->Save(pszPath, TRUE);
			}
			else
			{
				hResult = -1;
			}

			piPersistFile->Release();
		}

		m_piShellLink->Release();
	}

	return (SUCCEEDED(hResult));
}

//------------------------------------------------------------------------------
// GetNetConnPIDL
// 
//		Gets the PIDL of the wireless adapter listed in 'Network Connections'.
// 
// 	Args:
//			None
// 
// 	Returns:
//			None
//
void CMainFrame::GetNetConnPIDL()
{
	// Bind to network connections folder. 
	ITEMIDLIST*		pIDList1		= NULL;
	LPSHELLFOLDER	lpDesktop	= NULL;
	LPSHELLFOLDER	lpNCFolder	= NULL;

	SHGetFolderLocation(NULL, CSIDL_CONNECTIONS, NULL, 0, &pIDList1);
	SHGetDesktopFolder(&lpDesktop);
	lpDesktop->BindToObject(pIDList1, NULL, IID_IShellFolder,(LPVOID*)&lpNCFolder);
	lpDesktop->Release();

	// Enumerate subitems.
	ITEMIDLIST*		pIDList2		= NULL;
	LPENUMIDLIST	lpItems		= NULL;

	lpNCFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &lpItems); 
	 
	while (S_OK == lpItems->Next(1, &pIDList2, NULL)) 
	{ 
		STRRET sr = {STRRET_WSTR}; 
		lpNCFolder->GetDisplayNameOf(pIDList2, SHGDN_NORMAL, &sr); 

		TCHAR chBuffer[MAX_PATH] = _T(""); 
		StrRetToBuf(&sr, pIDList2, chBuffer, MAX_PATH); 

		if (0 == _tcsicmp(chBuffer, WIRELESS_LINK_DESC)) 
		{ 
			ITEMIDLIST* pIDList3 = ILCombine(pIDList1, pIDList2); 
			m_piShellLink->SetIDList(pIDList3); 
			ILFree(pIDList3); 
			ILFree(pIDList2); 
			break; 
		} 

		ILFree(pIDList2); 
		pIDList2 = NULL; 
	} 

	ILFree(pIDList1);
}



Here is a code snippet with the 'ShellExecute' call...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
....

if (!cFinder.FindFile(strWifiLink, 0))
		{
			CreateWirelessShortcut(strWifiLink);
		}

nShellError = (int)ShellExecute(m_hWnd, NULL, strWifiLink, NULL, NULL, SW_SHOW);

		if (nShellError <= 32)
		{
			strShellErr.Format(IDS_WIFI_ADAPTER_NOT_FOUND, nShellError);
			ShellMessageBox(strShellErr, MB_OK | MB_ICONSTOP);
		}


Any help would be appreciated.
Topic archived. No new replies allowed.