As PC Transplant is not able to capture WLAN profiles, how can this goal still be achieved?
The following method can be used on Windows XP Service Pack 2 and Service Pack 3.
Installing this set of application programming interfaces (APIs) will enable you to create applications that can manage wireless LAN profiles and connectivity on Microsoft Windows XP Service Pack 2 (SP2) using the native wireless functionality in Windows, called Wireless Zero Configuration (WZC) service.
Even though the Wireless Zero Configuration service is set to Automatic, you may find that it is not running, so you will need to start it.
The tool that will allow you to obtain the WLAN profiles as well as deploy them to other machines is called WLAN.exe and is attached to this article.
Here is a basic example of how you can use this tool, once the Wireless Zero Configuration service has been started.
There are 1 interfaces in the system.
Interface 0: GUID: 89762a5d-bc6b-4ac6-8cf3-b0462b2bafef Intel(R) PRO/Wireless 3945ABG Network Connection - Teefer2 Miniport State: "disconnected" Command "ei" completed successfully.
There are 1 profiles on the interface.
"Profile1" Command "gpl" completed successfully.
The return profile xml is:
<?xml version="1.0"?> <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"> <name>Profile1</name> <SSIDConfig> <SSID> <hex>574C414E2D445341444B</hex> <name>Profile1</name> </SSID> </SSIDConfig> <connectionType>ESS</connectionType> <MSM> <security> <authEncryption> <authentication>open</authentication> <encryption>WEP</encryption> <useOneX>false</useOneX> </authEncryption> <sharedKey> <keyType>networkKey</keyType> <protected>false</protected> <keyMaterial>76A3DEC BA383180E8A18E4E522</keyMaterial> </sharedKey> <keyIndex>0</keyIndex> </security> </MSM> </WLANProfile> Command "gp" completed successfully.
wlan.exe sp 89762a5d-bc6b-4ac6-8cf3-b0462b2bafef C:\Profile1.xml
As you can see, this tool has many functions, and all of them can be scripted in order to allow you to develop an automated method of capturing and deploying WLAN profiles.
I came up with the following script for myself and those who are in the "Organizations who STILL need to upgrade from Windows XP" boat
Usage:
cscript.exe "ConfigureWirelessSettings.vbs" /Retrieve
Or
cscript.exe "ConfigureWirelessSettings.vbs" /Restore
Ultimately, this script will make use of the "WLAN.exe" tool on Windows XP and make use of the "netsh.exe" tool in Windows Vista and later in order to export all wireless profiles to a flash drive in a folder called "Backup\NameOfComputer\WirelessProfiles". Each Profile will be named as the "SSID.xml" You may then use the restore functionality to import all retrieved profiles back into the system.
Modify the "WirelessProfileDestinationFolder" variable in order to change the backup location to whatever your needs are. Example: (Network Location, Local Disk, etc...)
Hope this helps somebody!
'Define Target Computer strComputer = "." 'Set object values Set oArguments = WScript.Arguments.Named Set oFSO = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject("WScript.Shell") Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2") 'Define ASCII Characters chrSpace = Chr(32) chrSingleQuote = Chr(39) chrDoubleQuote = Chr(34) 'Define Folder Locations WorkingDir = oFSO.GetParentFolderName(WScript.ScriptFullName) 'Gather information from WMI 'Query # 1 - Gather information about the device from the "Win32_ComputerSystem" class Set oComputerSystem = oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem") For Each oItem In oComputerSystem strUserName = oItem.UserName strComputerName = oItem.Name Next '"oItem.UserName" places the computer name and a "\" before the username, so time to manipulate the string 'Remove all text before the "\" so just the username of the currently logged in user is left If InStr(strUserName, "\") > 0 Then strUserName = Mid(strUserName, InStr(strUserName, "\") +1) End If 'Query # 2 - Determine Operating System Version Set oOperatingSystem = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem") For Each oItem in oOperatingSystem strOSVersion = oItem.Version Next 'Gather the GUID of the Wireless Network Connection If (strOSVersion >= "5") And (strOSVersion < "6") Then 'Execute "Wireless Local Area Network Tool" "ei" (Enumerate Interfaces) command > Provided free by Symantec Set GetWirelessGUID = oShell.Exec(chrDoubleQuote & WorkingDir & "\Tools" & "\WLAN.exe" & chrDoubleQuote & chrSpace & "ei") 'Read the output from the command Do Until GetWirelessGUID.StdOut.AtEndOfStream InterfaceGUIDs = Split(GetWirelessGUID.StdOut.ReadAll, vbCrLf) Loop 'Parse and modify the command output so that only the GUID remains 'Begin a "For Loop" For Each GUID In InterfaceGUIDs 'Determine if the string "GUID: " is inside of one of the returned lines If InStr(GUID, "GUID: ") > 0 Then 'Remove any tabs from the returned string strGUID = Replace(GUID, vbTab, "") 'Remove the first 7 characters from the returned string (" GUID: ") strGUID = Right(GUID, Len(GUID) - 7) 'Uppercase the returned string strGUID = UCase(strGUID) End If If Not (strGUID = "") Then WirelessInterfaceExists = "True" Else WirelessInterfaceExists = "False" End If Next 'Query # 3 - Gather information about the device from the "Win32_NetworkAdapter" class ElseIf (strOSVersion >= "6") Then Set oNetworkAdapter = oWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID Like '%Wireless%'") If oNetworkAdapter.Count > 0 Then WirelessInterfaceExists = "True" For Each oItem In oNetworkAdapter strGUID = oItem.GUID strGUID = Replace(strGUID, "{", "") strGUID = Replace(strGUID, "}", "") Next Else WirelessInterfaceExists = "False" End If End If 'Determine information about various disks Set oDrives = oFSO.Drives For Each oDrive In oDrives 'Determine atrributes of the first detected removable drive If (oDrive.DriveType = "1") Then DestinationDriveLetter = oDrive.DriveLetter & ":" DestinationVolumeLabel = oDrive.VolumeName DestinationFreeSpace = Int(oDrive.FreeSpace / 1048576) Exit For End If Next 'Define destination folder location WirelessProfileDestinationFolder = DestinationDriveLetter & "\Backup\" & strComputerName & "\WirelessProfiles" 'Gather the wireless profiles on the device and export them If oArguments.Exists("Retrieve") And (strOSVersion >= "5") And (strOSVersion < "6") And (WirelessInterfaceExists = "True") Then 'Execute "Wireless Local Area Network Tool" "gpl" (Get Profile List) command > Provided free by Symantec Set EnumerateWirelessProfiles = oShell.Exec(chrDoubleQuote & WorkingDir & "\Tools" & "\WLAN.exe" & chrDoubleQuote & chrSpace & "gpl" & chrSpace & strGUID) 'Read the output from the command Do Until EnumerateWirelessProfiles.StdOut.AtEndOfStream 'Split the output into lines so it can be sorted easier WirelessProfiles = Split(EnumerateWirelessProfiles.StdOut.ReadAll, vbCrLf) Loop 'Create a counter that will be incremented with each iteration of the loop ArrWirelessProfilesCounter = 0 'Begin the "For Loop" For Each WirelessProfileName In WirelessProfiles 'Remove double quotes from any WirelessProfile WirelessProfileName = Replace(WirelessProfileName, chrDoubleQuote, "") 'Remove indentation/tabs from any WirelessProfile WirelessProfileName = Replace(WirelessProfileName, vbTab, "") 'Remove the first line from the command output that reports the amount of profiles on the system If InStr(WirelessProfileName, "There are ") > 0 Then WirelessProfileName = "" End If 'Remove the last line from the command output that reports that the command was completed successfully If InStr(WirelessProfileName, "Command ") > 0 Then WirelessProfileName = "" End If 'Create a self building array with each result from the "For Loop" ReDim Preserve arrWirelessProfiles(ArrWirelessProfilesCounter) arrWirelessProfiles(ArrWirelessProfilesCounter) = WirelessProfileName 'Only increment the counter if the result from the "For Loop" is not blank or Null If Not (WirelessProfileName = "") Or IsNull (WirelessProfileName) Then 'Create the folders that are needed to export the profiles If Not oFSO.FolderExists(WirelessProfileDestinationFolder) Then MakeWirelessProfileFolder = oShell.Run("cmd.exe /c mkdir" & chrSpace & chrDoubleQuote & WirelessProfileDestinationFolder & chrDoubleQuote, 0, True) End If 'Execute "Wireless Local Area Network Tool" "gp" (Get Profile) command > Provided free by Symantec Set GetWirelessProfiles = oShell.Exec(chrDoubleQuote & WorkingDir & "\Tools" & "\WLAN.exe" & chrDoubleQuote & chrSpace & "gp" & chrSpace & strGUID & chrSpace & chrDoubleQuote & WirelessProfileName & chrDoubleQuote) 'Read the output from the command Do Until GetWirelessProfiles.StdOut.AtEndOfStream WirelessProfileSettings = GetWirelessProfiles.StdOut.ReadAll Loop 'Export each profile to a ".xml" file with the SSID as the filename Set ExportWirelessProfiles = oFSO.CreateTextFile(WirelessProfileDestinationFolder & "\" & WirelessProfileName & ".xml") ExportWirelessProfiles.Close Set ExportWirelessProfiles = Nothing Set ExportWirelessProfiles = oFSO.OpenTextFile(WirelessProfileDestinationFolder & "\" & WirelessProfileName & ".xml", 2) ExportWirelessProfiles.Write(WirelessProfileSettings) ExportWirelessProfiles.Close Set ExportWirelessProfiles = Nothing 'Increment the counter for the next iteration of the loop ArrWirelessProfilesCounter = ArrWirelessProfilesCounter + 1 End If Next ElseIf oArguments.Exists("Retrieve") And (strOSVersion >= "6") And (WirelessInterfaceExists = "True") Then 'Create the folders that are needed to export the profiles If Not oFSO.FolderExists(WirelessProfileDestinationFolder) Then MakeWirelessProfileFolder = oShell.Run("cmd.exe /c mkdir" & chrSpace & chrDoubleQuote & WirelessProfileDestinationFolder & chrDoubleQuote, 0, True) End If 'Use "netsh" in order to automatically export all wireless profiles strExportWirelessProfiles = "netsh.exe wlan export profile folder=" & chrDoubleQuote & WirelessProfileDestinationFolder & chrDoubleQuote & chrSpace & "key=clear" comExportWirelessProfiles = oShell.Run(strExportWirelessProfiles, 0, True) 'Replace the backslashes in the destination path string with two backslashes so it can be used properly in the following WMI query WirelessProfileDestinationFolder = Replace(WirelessProfileDestinationFolder, "\", "\\") 'Remove the drive letter from the string so it can be used properly for the following WMI query WirelessProfileDestinationFolder = Right(WirelessProfileDestinationFolder, Len(WirelessProfileDestinationFolder) - 2) 'Query to find out how many profiles were exported to the destination folder Set oWirelessProfiles = oWMI.ExecQuery("SELECT * FROM CIM_DataFile WHERE Path = " & chrSingleQuote & WirelessProfileDestinationFolder & "\\" & chrSingleQuote & " And Drive = " & chrSingleQuote & DestinationDriveLetter & chrSingleQuote & " And Extension Like '%xml%'") 'Only take action if there were results If oWirelessProfiles.Count > 0 Then 'Begin "For Loop" to go through each result and remove the "Wireless Network Conntection-" prefix from each file name, thus only leaving the wireless SSID as the filename For Each oWirelessProfile In oWirelessProfiles NewWirelessProfileName = Replace(oWirelessProfile.FileName & "." & oWirelessProfile.Extension, "Wireless Network Connection-", "") RenameWirelessProfile = oShell.Run("cmd.exe /c rename" & chrSpace & chrDoubleQuote & oWirelessProfile.Name & chrDoubleQuote & chrSpace & chrDoubleQuote & NewWirelessProfileName & chrDoubleQuote, 0, True) Next End If End If 'Restore the wireless profiles that have been retrieved If oArguments.Exists("Restore") And (strOSVersion >= "5") And (strOSVersion < "6") And (WirelessInterfaceExists = "True") Then 'Replace the backslashes in the destination path string with two backslashes so it can be used properly in the following WMI query WirelessProfileDestinationFolder = Replace(WirelessProfileDestinationFolder, "\", "\\") 'Remove the drive letter from the string so it can be used properly for the following WMI query WirelessProfileDestinationFolder = Right(WirelessProfileDestinationFolder, Len(WirelessProfileDestinationFolder) - 2) 'Query to find out how many profiles were exported to the destination folder Set oWirelessProfiles = oWMI.ExecQuery("SELECT * FROM CIM_DataFile WHERE Path = " & chrSingleQuote & WirelessProfileDestinationFolder & "\\" & chrSingleQuote & " And Drive = " & chrSingleQuote & DestinationDriveLetter & chrSingleQuote & " And Extension Like '%xml%'") 'Only take action if there were results If oWirelessProfiles.Count > 0 Then 'Begin "For Loop" to go through each result and use "netsh" in order to import each wireless profile For Each oWirelessProfile In oWirelessProfiles strImportWirelessProfile = chrDoubleQuote & WorkingDir & "\Tools" & "\WLAN.exe" & chrDoubleQuote & chrSpace & "sp" & chrSpace & strGUID & chrSpace & chrDoubleQuote & oWirelessProfile.Name & chrDoubleQuote comImportWirelessProfile = oShell.Run(strImportWirelessProfiles, 0, True) Next End If ElseIf oArguments.Exists("Restore") And (strOSVersion >= "6") And (WirelessInterfaceExists = "True") Then 'Replace the backslashes in the destination path string with two backslashes so it can be used properly in the following WMI query WirelessProfileDestinationFolder = Replace(WirelessProfileDestinationFolder, "\", "\\") 'Remove the drive letter from the string so it can be used properly for the following WMI query WirelessProfileDestinationFolder = Right(WirelessProfileDestinationFolder, Len(WirelessProfileDestinationFolder) - 2) 'Query to find out how many profiles were exported to the destination folder Set oWirelessProfiles = oWMI.ExecQuery("SELECT * FROM CIM_DataFile WHERE Path = " & chrSingleQuote & WirelessProfileDestinationFolder & "\\" & chrSingleQuote & " And Drive = " & chrSingleQuote & DestinationDriveLetter & chrSingleQuote & " And Extension Like '%xml%'") 'Only take action if there were results If oWirelessProfiles.Count > 0 Then 'Begin "For Loop" to go through each result and use "netsh" in order to import each wireless profile For Each oWirelessProfile In oWirelessProfiles strImportWirelessProfile = "netsh wlan add profile filename=" & chrDoubleQuote & oWirelessProfile.Name & chrDoubleQuote & chrSpace & "user=all" comImportWirelessProfile = oShell.Run(strImportWirelessProfile, 0, True) Next End If End If
I run into a problem with this method.
After you import the profile with WLAN.exe, it creates a wireless REG_BINARY entry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces.
So now when you import the reg file, it doesn't replace the registry entry, it adds yet another REG_BINARY for the same wireless network. So you still have to delete the generated REG_BINARY item that came after the WLAN import, and then your EAP type settings will take effect immediately.
How would one even automate that?
i have the complete and working batch file for using XML and it works to export as well as import.
But
I have yet to test on cross/system. This is tested only on my own laptop. Export/ Delete/ check to make sure not there/ import from XML
Works fine. But. This, as you say, is not worth anythign it it wont cross/system deploy.
Plus XML files (as well as rthe WFC file created when you use the windows 7 built in export for import to new system) are both plaintext. Not good.
Has anyone looked at doing a registry export? I ran acroos (by accident) the location of these keys one day when I was trying to totally TOTALLY remove some mapped network drives. Windows 7 refuses to "forget" the path even when disconnected for weeks. The drives will even remap to a new IP but the IP shown in the COMPUTER display more than not shows the OLD IP even thougfh it is connected to a NEW IP.
This is a compltely different problem I am working on as well but this deployment of WIFI profiles I need to get done ASAP.
Thanks for any input
I tried to allow replies to my posts if it doesnt work I will send my email address to you
Looking through this article because I now need to start getting a method for Windows 7. I have always used AutoIT in xp to deploy my wireless setup but this does not work in Windows 7.
First I would like to suggest everyone please vote up this idea:
https://www-secure.symantec.com/connect/ideas/create-wifi-network-connection-job-or-task
I've got a profile xml file from Win7
It's normal if I use netsh wlan in Win7.
How can I use it in WinXP for wireless setup?
It looks to use command wlan conn <interface GUID> <SSID> <infrastructure(i)|adhoc(a)> <profile name>
However I am not sure what's the infrastructure|adhoc mean.
Anyone could teach me??
Thanks a lot.
(Tested under Windows XP)
If you try to export a profile that uses PEAP (or other kind of EAPs) authentification, it displays the following error message : The parameter for "gp" is not correct. Please use "help gp" to check the usage of the command.
Here's a trick I've found :
1) open regedit and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\{your_interface_GUID}\ : Here you'll find different entries, numbered sequencially from 1 to XXX. Double click on each of these entries in order to display their content in a readable form. Locate the entry where your profile name is mentioned somewhere in the beginning of the binary date (there should be only one entry in this case). Export this entry in a .REG file. Note : the entry name (which is a number between 1 and 99) has no importance at all : you can safely give it any number from 1 to 99. So, in order not to overwrite another existing profile on another computer, let's rename it 99.
2) modify your profile before exporting it : go to profile properties, tab "authentification", and as EAP type, choose "Smartcard or other certificate" (sorry if translation is bad... I'm on a French version of Windows) then OK.
3) export your modified profile. Since it no longer uses a PEAP, you can export it without error message.
4) import the modified .REG file in order to restore your wifi profile to its original EAP type settings.
5) optionnal : You can reopen Wifi Profile settings in order to check that the EAP type settings has been correctly restored by the importation of the .REG. If it's not the case, don't panic: it may require some reboot or service start / stop or importing a profile with WLAN so that the "new" parameters are taken into account.
To import the profile on another computer :
1) import the modified profile using WLAN.exe
2) then, import the modified .REG in order to restore the EAP type settings
3) Maybe some reboot or service start / stop or importing another profile using WLAN is required in order to "update" and so that new parameters are taken into account by Windows (though I'm not sure if this is actually required)
Nah SP2 does require that KB article referenced and the required patch installed. Runs fine after that. Next test, Win7! We've got em all you see....:)
jaylweb - awesome stuff, great script. I've tested the xp one, works fine. Just about to test on SP2 also...hoping that we don't have to insall anything but i take your earlier comment on that.
Will be testing the Win7 one at some point as well but it looks like you've cracked that one also.
Really good stuff for the community well done - BOOKMARKED!
Symantec don't you dare lose this page....
The download link for the tool is a Microsoft link so anyone who uses this tool will know that it belongs to Microsoft.
SK
NoJacket31,
Another user had posted that same error and I had suggested it might have been a syntax error, but they never responded. Can you copy/paste your syntax for us to see? That would be helpful. Also, is the key all numbers? Curious since the prior person mentioned thier key was all numbers. I'm not sure what the smoking gun is yet, but we can help you figure it out. :)
jaylweb
Am getting errors when i try to capture a profile with WPA2 security but it okay when i capture WEP security profile. Can capture successfully on Windows 7 without a problem but my problems are on Windows XP with SP3. Has anyone come across this error in the subject line....
Finally! After much blood, sweat and tears... here is a viable way to export from Win7, and reimport into Win7. Took me some time to find, but here is the official documentation from Microsoft about their whole programming library for WLAN profiles: http://msdn.microsoft.com/en-us/library/ms706965(v=VS.85).aspx What I basically found out from that site, is that the only way for you to import a wireless profile from one PC to another PC (possibly of a different make and model), is to have the passkey unencrypted in the XML file. You can read it at the bottom of this page: http://msdn.microsoft.com/en-us/library/aa370032(v=VS.85).aspx So... the way to export is this way: netsh wlan export profile name="my first wireless" folder="c:\wireless" key=clear That string, produces an XML file, where the sharedkey section should say keytype=passPhrase , protected=false and keyMaterial= your unencrypted wireless key This XML file, is good for being imported to whichever Win7 machine you want to use it on. Just remember that the wireless key is stored unencrypted, and take appropriate measures towards not sharing this XML file with all your users (if you want to keep it secret). Next, the way to import the same profile again is this: netsh wlan add profile filename="c:\wireless\myfirstwireless.xml" Just remember, if you want to export the profile without needing to change anything in it, use my above export string. If you don’t type in key=clear at the end, the key will be encrypted, and you won't be able to import it again on another PC other than the one you currently exported it from.
I'm looking for a solution like this for Windows 7 as I'm trying to find a way to deploy or automate the process of adding pre-configured wireless profile. Although I successfully exported the profile from a previously configured machine via netsh wlan export profile name="company-network" folder="H:\wireless-profile"
When I import the profile using netsh, it does not include the WPA2PSK TKIP key. netsh wlan add profile filename="H:\wireless-profile\weth0-company-network.xml" user=all
So I decided to try my hand at creating a GPO (Computer Configuration > Windows Settings > Security Settings > Wireless) by importing the XML file created above, but when I import the XML above, I receive a "The Network Key has been removed from this profile" message. This happens even when I set <protected>false</protected> and include the key unencrypted (<keyMaterial>UNENCRYPTED</keyMaterial>)
Lastly, I'm aware that Windows allows one to copy an already configured wireless profile to a USB flash drive, but its my understanding that the `setupSNK.exe` that gets created doesn't accept any of the standard silent/quiet switches. Furthermore, the file won't even launch when its not run from a flash; it simply doesn't launch or it launches and immediately quits.
How can I silently deploy a pre-configured wireless profile? Can this be done via VBScript or PowerShell? Or am I forced to use something like zwlancfg?
I've got an HP 4415s laptop that fails on the gp export step. I was able to get it to list the profiles so I know I have the GUID typed in correctly. If I ask for the settings from the ssid (it's all numbers so there is no case sensitivity problem) it throws the error in the subject line. If I ask for an SSID that doesn't exist, it gives a different error code 1168. This is a broadcom 4322AG card a/b/g
Good job on this tool. This is going to help me out a lot! One note though, your syntax for obtaining the XML is just a little off. You have to include the GUID in order to get the profile information.
Get Profile (profile name is case sensitive) - wlan.exe gp Profile1
Should be:
Get Profile (profile name is case sensitive) - wlan.exe gp <Interface GUID> <Profile Name>
Thanks again!!
Dewayne