Sign in to follow this  
Followers 0
BlackHoleSun

Save / Restore Wireless profiles

7 posts in this topic

I'm trying to create a script that will save a users wireless profile settings (name, security, password) and restore them later. There will be 3 networks that are standard and won't need to be saved at all. The profiles can be saved to either an INI or XML file, I have experience with INIs, but if XML would be better that's fine.

All I've been able to find for the most part has been scripts dealing with the wireless adapters, nothing on the profile side of things. Thanks.

Share this post


Link to post
Share on other sites



A little Google goes a long way.

http://technet.microsoft.com/en-us/library/cc755301%28WS.10%29.aspx

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Willichan, that only applies to Server 2008, and maybe Vista/7, won't work if the user is on XP.

Check out this thread and see if you can use some of the UDF's functions to do what you need

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

NETSH works under XP as well. I have been using it for years.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/netsh.mspx?mfr=true

But if the UDF does what is needed, I'm all for not re-inventing the wheel.

Share this post


Link to post
Share on other sites

I didn't mean that Netsh didn't work in XP, what I meant was that the page you referenced only applies to Server 2008 and maybe Vista/7. Also, I'm not sure that Netsh under XP allows you to access the WLAN profiles the same way it does under Vista/7, I haven't been able to find any commands for XP that work to save profiles, probably just missed them as I was just browsing the subject.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewManNH: You are right. Wireless does get left out on the XP version.

I guess the XP scripts I did were more for RAS profiles (dating myself a bit?).

@BlackHoleSun: Go with the UDF link that BrewManNH gave you.

Share this post


Link to post
Share on other sites

It's been a busy week, but I have worked on implementing Wifi33B into my code. It looks like it can back the profiles up, but I noticed it's not the same when it comes to the password as it is in my Win7 exports. Also when I import I use the ConsoleWrite and it says it's an invalid schema. This goes for the original XP profiles as well as the Win7 profiles. In the XML outputs, Win7 has a longer password than XP and Win7 also shows it as a "passPhrase" whereas XP has it as "networkKey".

Below are the 2 functions relating to backing up and restoring. Maybe I'm doing something wrong.

;~ =============================================================
Func BackupProfiles($osVersion, $user)
    If ($osVersion = "Win_7") Then
        ;Win7 code goes here
        If DirGetSize($user) < 0 Then
            DirCreate($user)
        EndIf
        RunWait("netsh wlan export profile folder=" & $user)
        Return -1
    ElseIf ($osVersion = "Win_XP") Then
        ;XP code goes here
        If DirGetSize($user) < 0 Then
            DirCreate($user)
        EndIf
        
        _Wlan_StartSession()
        Local $sProfile
        Local $asProfileList = _Wlan_GetProfileList(-1, -1)
        For $i = 0 To UBound($asProfileList) - 1
            $sProfile = _Wlan_GetProfileXML(-1, -1, $asProfileList[$i])
            FileWrite($user & "\Wireless Network Connection-" & $asProfileList[$i] & ".xml", $sProfile)
        Next
        _Wlan_EndSession(-1)
        
        Return -1
    EndIf
EndFunc ;==>RestoreProfiles

;~ =============================================================
Func RestoreProfiles($osVersion)
    If ($osVersion = "Win_7") Then
        ;Win7 code goes here
        Local $search, $file, $netsh
        $search = FileFindFirstFile($userName & "\*.xml")
        For $i = 1 to 200
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            $netsh = 'netsh wlan add profile filename="' & $userName & '\' & $file & '"'
            RunWait($netsh)
        Next
        FileClose($search)
        Return -1
    ElseIf ($osVersion = "Win_XP") Then
        ;XP code goes here
        
        _Wlan_StartSession()
        Local $sProfile, $asProfileList, $nextFile
        Local $firstProfile = FileFindFirstFile($userName & "\*.xml")
        FileOpen($firstProfile)
        For $i = 0 To $firstProfile + 1
            $nextFile = FileFindNextFile($firstProfile)
            FileOpen($nextFile)
            $sProfile = _Wlan_SetProfileXML(-1, -1, $nextFile)
            FileClose($nextFile)
            ConsoleWrite($sProfile & @CRLF)
        Next
        FileClose($firstProfile)
        _Wlan_EndSession(-1)
        
        Return 0
    EndIf
EndFunc ;==>RestoreProfiles

This is the Win7 XML:

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>SSIDNAME</name>
    <SSIDConfig>
        <SSID>
            <hex>SSIDHEX</hex>
            <name>SSIDNAME</name>
        </SSID>
        <nonBroadcast>false</nonBroadcast>
    </SSIDConfig>
    <connectionType>ESS</connectionType>
    <connectionMode>auto</connectionMode>
    <MSM>
        <security>
            <authEncryption>
                <authentication>WPA2PSK</authentication>
                <encryption>AES</encryption>
                <useOneX>false</useOneX>
            </authEncryption>
            <sharedKey>
                <keyType>passPhrase</keyType>
                <protected>true</protected>
                <keyMaterial>LongPasswordCodeHere</keyMaterial>
            </sharedKey>
        </security>
    </MSM>
</WLANProfile>

This is the XP XML:

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
    <name>SSIDNAME</name>
    <SSIDConfig>
        <SSID>
            <hex>SSIDHEX</hex>
            <name>SSIDNAME</name>
        </SSID>
    </SSIDConfig>
    <connectionType>ESS</connectionType>
    <MSM>
        <security>
            <authEncryption>
                <authentication>WPA2PSK</authentication>
                <encryption>AES</encryption>
                <useOneX>false</useOneX>
            </authEncryption>
            <sharedKey>
                <keyType>networkKey</keyType>
                <protected>false</protected>
                <keyMaterial>ShortPasswordCodeHere</keyMaterial>
            </sharedKey>
        </security>
    </MSM>
</WLANProfile>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0