topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 12, 2024, 2:50 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: How to create a shortcut for the "wireless network connection" in Windows XP?  (Read 60142 times)

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
The AutoIt stuff seemed to be based on this C/C++ code into the Native WiFi API

Hm... I'll have to explore that this evening as it just may be a better angle of attack than the one I'm currently using.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Stoic, the latest file works for me.  I just tried it.  Thanks!  I tried it at home on a Windows 7 pc with no wifi adapters, and it gave some kind of GUID error dialog.  But I just tried it at work on the laptop, and it worked fine.

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Below is the current build with working save to .ini, or registry options. The default action is to save nothing anywhere in the interest of portability.
 (see attachment in previous post)

this version works well on my netbook (WinXP SP3), nice work! :up:

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
I tried it at home on a Windows 7 pc with no wifi adapters, and it gave some kind of GUID error dialog.

Really? Weird, I just ran it here (Win7 desktop/no WiFi) and it just quietly exited. Might that have been an earlier build? I gotta remember to put build numbers in these things (bad habbit...).

If you let me know which GUID error (there's several...) it threw, I'll see if I can figure out how it got there. I still gotta work out a dead adapter check too.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
I tried it at home on a Windows 7 pc with no wifi adapters, and it gave some kind of GUID error dialog.

Really? Weird, I just ran it here (Win7 desktop/no WiFi) and it just quietly exited. Might that have been an earlier build? I gotta remember to put build numbers in these things (bad habbit...).

If you let me know which GUID error (there's several...) it threw, I'll see if I can figure out how it got there. I still gotta work out a dead adapter check too.
I'll make sure to do that once I get home.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
I tried it at home on a Windows 7 pc with no wifi adapters, and it gave some kind of GUID error dialog.

Really? Weird, I just ran it here (Win7 desktop/no WiFi) and it just quietly exited. Might that have been an earlier build? I gotta remember to put build numbers in these things (bad habbit...).

Quietly exited here on my x64 W7 PC when I selected an unplugged WiFi adapter.  Selecting the LAN connection does the same as clicking on the tray icon.

Selecting the WiFi adpater when it's plugged in resulted in the same as clicking on the tray icon, (the popup window that shows what you're currently connected to - same result as LAN connection).
« Last Edit: January 31, 2011, 05:36 PM by 4wd »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
I tried it at home on a Windows 7 pc with no wifi adapters, and it gave some kind of GUID error dialog.

Really? Weird, I just ran it here (Win7 desktop/no WiFi) and it just quietly exited. Might that have been an earlier build? I gotta remember to put build numbers in these things (bad habbit...).

Quietly exited here on my x64 W7 PC when I selected an unplugged WiFi adapter.  Selecting the LAN connection does the same as clicking on the tray icon.

Yeah, that's gonna need some polish.

Selecting the WiFi adpater when it's plugged in resulted in the same as clicking on the tray icon, (the popup window that shows what you're currently connected to - same result as LAN connection).

Am I miss-reading that? ...Or are you saying you got a connections window for a LAN adapter?

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
I tried it at home on a Windows 7 pc with no wifi adapters, and it gave some kind of GUID error dialog.

Really? Weird, I just ran it here (Win7 desktop/no WiFi) and it just quietly exited. Might that have been an earlier build? I gotta remember to put build numbers in these things (bad habbit...).

If you let me know which GUID error (there's several...) it threw, I'll see if I can figure out how it got there. I still gotta work out a dead adapter check too.
I'll make sure to do that once I get home.
I was wrong.  There's no error.  Maybe i was using the older version.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Am I miss-reading that? ...Or are you saying you got a connections window for a LAN adapter?

I get the popup window you get when clicking on the Network SysTray icon that shows what you're currently connected to.

This is when I select the LAN connection (no WiFi plugged in):
2011-02-01_12-01-50.jpg

This is when I select the WiFi adapter (when it's plugged in):
2011-02-01_12-05-20.jpg

If I select the LAN connection when the WiFi is plugged in then I will get the same result as attachment 2.

If I select the WiFi connection when it's not plugged in I get nothing - exits quietly.

Hope that's clearer ;)

Ahh, I see what happened - not your mis-reading but rather my mis-writing  :-[
« Last Edit: January 31, 2011, 07:24 PM by 4wd »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Well I'll be damned! (me too)

I've been doing most of the testing on my XP laptop(which just exits on LAN), so hadn't noticed this rather interesting behavior.

Strangely my 32-bit Win7 machine at the office didn't do this (or I didn't notice it)...But x64 here does.

The C# Native WiFi API thing didn't pan out as it's Vista/7 only (I'm not ready to give-up on XP just yet), so I'm polking around looking for options.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
The C# Native WiFi API thing didn't pan out as it's Vista/7 only (I'm not ready to give-up on XP just yet), so I'm polking around looking for options.

That's strange because they implemented it from XP SP2 onwards, well according to Microsoft....but then, what would they know :)

And it seems to work OK on XP-SP3 via my LANToggle program, (ie. it lists the interfaces and lets me (dis|en)able them), AutoIt of course so maybe there is a little more trickery going on.

However, I don't think it will work if the you don't use the Wireless Zero Config in Windows, (ie. the adapter uses whatever the manufacturer supplied by way of connection software).

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
I was wrong.  There's no error.  Maybe i was using the older version.

you're not imagining it. the error also appeared on my WinXP desktop. i'm using the version that Stoic Joker posted latest. (yup, version numbering might be a good idea). :)


WiFi_01_02_2011_001.pngWiFi_01_02_2011_002.png

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
That error message is (should only be) displayed when you hit the cancel button.

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
That error message is (should only be) displayed when you hit the cancel button.

yes, that's what i did. was just testing on a PC with non-wifi component to see what happens.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
That error message is (should only be) displayed when you hit the cancel button.

yes, that's what i did. was just testing on a PC with non-wifi component to see what happens.
Okay, my intention was to give the user feedback regarding the programs intentions. So they weren't waiting for it to do something else, and/or were not sure it had completely closed. If it is actually causing more confusion I can pull it out of the next build.

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
Okay, my intention was to give the user feedback regarding the programs intentions. So they weren't waiting for it to do something else, and/or were not sure it had completely closed. If it is actually causing more confusion I can pull it out of the next build.

actually i don't mind the feedback. it's good to have an exit notice for the reasons you stated.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Okay, nothing real exciting at this point. But I did figure out how to get the adapter status so we can weed out the inactive ones.

I started with some MSDN example code, and beat on it until it started doing what I wanted. Now I just gotta figure out how to combine it with the rest of the project.

While I plan on releasing the code with the finished program, here's is the adapter bit I've been working for the last few days (Which is a bit embarrassing when I thing about it); everything needed to compile & run is below:
Code: C++ [Select]
  1. // GetIfEntry.cpp : Defines the entry point for the console application.
  2. //=============== Created by Stoic Joker: Tuesday, 02/01/2011 @ 6:23:11pm
  3. #include "stdafx.h" //--------------------------------------------+++-->
  4.  
  5.  //================================================================================================
  6. //-------------+++--> Strip \DEVICE\TCPIP_ Off of wszName to Get the Adapter's GUID For Comparison:
  7. void StripOutGUID(WCHAR *szGUID, WCHAR *wszName) { //---------------------------------------+++-->
  8.         WCHAR *p; // Walk the string to find the GUID opening '{' character. Sure There
  9.         int i=0; // Are Easier Ways to do This ... But This Way I Avoid Language Issues.
  10.  
  11.   p = wszName;
  12.   while(*p != '{') {
  13.           *p++; i++;
  14.   }
  15.  
  16.   wsprintf(szGUID, L"%s", p);
  17. }
  18.  //================================================================================================
  19. //------------------------+++--> Get Lst of Network Interfaces Available on Machine for Comparison:
  20. BOOL GetAdapters(WCHAR *szTarg) { //-----------( Much of This is From the MSDN )------------+++-->
  21.         PMIB_IFTABLE ifTable; // Declare and initialize variables.
  22.         PMIB_IFROW pMibIfRow;
  23.         DWORD dwSize = 0;
  24.         DWORD dwRetVal = 0;
  25.  
  26.   // Allocate memory for our pointers.
  27.   ifTable = (MIB_IFTABLE*) malloc(sizeof(MIB_IFTABLE));
  28.   pMibIfRow = (MIB_IFROW*) malloc(sizeof(MIB_IFROW));
  29.  
  30.    // Before calling GetIfEntry, we call GetIfTable to make sure there are entries to get.
  31.   // So... First, make an initial call to GetIfTable to get the necessary size into dwSize
  32.   if(GetIfTable(ifTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
  33.           GlobalFree(ifTable);
  34.           ifTable = (MIB_IFTABLE *) malloc (dwSize);
  35.   }
  36.   // Then make a second call to GetIfTable to get the actual data we want.
  37.   if((dwRetVal = GetIfTable(ifTable, &dwSize, 0)) == NO_ERROR) {
  38.           if(ifTable->dwNumEntries > 0) {
  39.                   for(UINT i=1; i<= ifTable->dwNumEntries; i++) {
  40.                                 pMibIfRow->dwIndex = i;
  41.                           if((dwRetVal = GetIfEntry(pMibIfRow)) == NO_ERROR) {
  42.                                   if(pMibIfRow->dwType == MIB_IF_TYPE_ETHERNET &&
  43.                                           pMibIfRow->dwAdminStatus == MIB_IF_ADMIN_STATUS_UP) {
  44.                                                   WCHAR szGUID[GEN_BUFF] = {0};
  45.                                           printf("\tDescription: %s\n", pMibIfRow->bDescr);
  46.                                           printf("\twszName: %S\n", pMibIfRow->wszName);
  47.                                           StripOutGUID(szGUID, pMibIfRow->wszName);
  48.                                           if(wcscmp(szGUID, szTarg) == MATCH) {
  49.                                                   printf("\tGUID: %S <--+++--> MATCHES REQUESTED ACTIVE TARGET ADAPTER!!!\n", szGUID);
  50.                                           }else{
  51.                                                   printf("\tGUID: %S <-+-> Is Active, But Not the One We're After.\n", szGUID);
  52.                                           }
  53.                                           printf("\tReceived %d, Sent %d\n", pMibIfRow->dwInOctets, pMibIfRow->dwOutOctets);
  54.                                           printf("\t\tNext...\n\n");
  55.                                   }
  56.                           }
  57.                   }
  58.           }
  59.           GlobalFree(ifTable);
  60.           return TRUE;
  61.   }
  62.  return FALSE;
  63. }
  64.  //================================================================================================
  65. //--------------------------------------//---------------------------+++--> Console Program Main():
  66. int _tmain(int argc, _TCHAR* argv[]) { //---------------------------------------------------+++-->
  67.   if(argc < 2) {
  68.           printf("\n\n\tERROR: No GUID Specified, Exiting!\n\n");
  69.           return 0;
  70.   }else{
  71.           printf("\n\n\tSearching for GUID: %S\n\n", argv[1]);
  72.   }
  73.   if(!GetAdapters(argv[1])) printf("\tGetIfTable failed.\n");
  74.  return 0;
  75. }
  76.  
  77.  // ============================================= STDAFX.H <-> Header File Below This Line!
  78. // stdafx.h : include file for standard system include files,
  79. // or project specific include files that are used frequently, but
  80. // are changed infrequently
  81. //
  82.  
  83. #pragma once
  84.  
  85. #ifndef _WIN32_WINNT            // Allow use of features specific to Windows XP or later.                  
  86. #define _WIN32_WINNT 0x0501     // Change this to the appropriate value to target other versions of Windows.
  87. #endif
  88.  
  89. #define GEN_BUFF   128
  90. #define MATCH            0
  91.  
  92. #include <stdio.h>
  93. #include <tchar.h>
  94.  
  95. // TODO: reference additional headers your program requires here
  96. #include <Windows.h>   //--+++--> Also Required by GetIfEntry():
  97. #include <Iphlpapi.h> //---+++--> Required by GetIfEntry():
  98. #pragma comment(lib, "Iphlpapi.lib") //-++-> ^See Above^:

...Crap, I just realized that int i doesn't actually do a damn thing... *Sigh*
« Last Edit: February 02, 2011, 07:06 PM by Stoic Joker »

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Man, this doesn't make sense with how Windows usually works.  Do you think they have done this network adapter thing intentionally?  Or did they just forget to offer a way for programmers to access the network adapters?

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
It's really just different levels of the same thing. The original code used a registry key to enumerate the physical adapters on the machine (and was right on the edge of Quick-N-Dirty). On my dev machine it found 1 Physical Adapter.

The code above is the much more detailed Network Interface list, which is where the more detailed state & status info is kept. On my dev machine it found (roughly) 20 Network Interfaces.

 The nested if's around the for(...) loop are narrowing the list down to less than a dozen items that can/will then be compared (GUID-to-GUID) to the Physical Adapters list to eliminate the disabled adapters from the Drop-Down menu.

From a (Windows) programming standpoint, these kind of shenanigans are normal... ;)

Note: Granted using the WiFi API 4wd mentioned above would have been a more elegant solution (simpler code & faster to pound out), however it also doesn't run on (isn't available in) Windows XP ... Which is (after all) or target platform.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
From a (Windows) programming standpoint, these kind of shenanigans are normal... ;)

Hehehe...you sure said a mouthful with that statement.   :D

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Note: Granted using the WiFi API 4wd mentioned above would have been a more elegant solution (simpler code & faster to pound out), however it also doesn't run on (isn't available in) Windows XP ... Which is (after all) or target platform.

Sorry if I seem to be pushing a dead donkey but I'm still not clear here, everything I've read on the Native WiFi API says it's available from XP SP2, (SP2 via patch, incorporated into SP3), onwards, (when Wireless Zero Config was introduced - I would have thought most people would be running SP3 by now), the only function not available to XP seems to be WlanGetInterfaceCapability according to MSDN.

So I would have thought that their example code for WlanEnumInterfaces would be just what's needed, (bearing in mind their note about GUIDs at the bottom which seems to make any program more convoluted than it needs to be).

I'm just trying to understand why it wouldn't run for you on XP but feel free to call me an idiot - I've been called worse  :P
« Last Edit: February 03, 2011, 11:59 AM by 4wd »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
It's the distinction we're both tripping over from opposite ends. You're looking at it correctly as it is available after SP2. And I'm looking at it (a bit darkly) because it's available to XP only after SP2. I hate mid-year changes (side effect of being a mechanic).

So if somebody does a fresh install, the program isn't going to run until after they get SP2 installed - Which is why I (in a split hairs fashion) said it isn't available in XP. It's not that it didn't run, as I never tested it...It's just that as soon as I saw the conditional SP2 requirement I (started thinking NT4) decided not to open that can of worms.


<Short Answer> ...You ain't nutz, I am.  :D

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Aahh...I see.....

But, (you knew that was coming didn't you), prior to XP SP2 doesn't that mean that Wireless Connection Manager, (or the window you get after hitting View Wireless Networks, whatever it's called), wasn't available?

ie. Prior to XP SP2, didn't you have to use whatever software the manufacturer provided with the adapter and as such won't what you're trying to do not work anyway?

Sorry, it's been a while since I saw anything but XP SP3 around.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
The Wireless Connection Manager has always been in XP (from day one) ... It is only the WiFi API that gives programmers an easier way to futz with it that is new.

Windows 2000 ... Now that was a 3rd party nightmare PITA when it came time to Wirelessly connect.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Thanks for clarifying - I'll leave you to you nutz and futz now  :P