How do you do....it? Thread, Adding wireless profiles via GPO in Technical; After a bunch of searching around, I finally decided to write a script to add wireless profiles and run it ...
-
19th March 2012, 10:28 AM #1
- Rep Power
- 5
Adding wireless profiles via GPO
After a bunch of searching around, I finally decided to write a script to add wireless profiles and run it as a computer startup script.
Sharing it here in case it's useful to anybody else;
First of all, you need to export your profiles into an xml file and then hardcode the key into that xml, you can follow the guidance for that here;
Kreslavsky IT blog » Deploy wireless settings with Key using netsh script and GPO
Once you have your files prepped, rename them to match the name of the wireless profile (important if you want my script to work), pop them into a network share (could store it in the GPO itself) and then change the NTFS or sharing permissions to remove everybody and add domain computers as read.
Now you can leave it there with the info in hand but I wanted a wee bit more. I wanted to add a bunch of profiles and then set a preferred order of profiles. Couldn't find it so I ended up writing the script below
To run it use it as so <scriptname> "Profile1" "Profile2"
Note make sure you read the notes and change the path to xml constant
If you're using GPO, add it to the computers startup script and add the profiles in the arguments field with each profile separated by quotes
'Name :WLAN Profile Configurator
'Description :A Script to Create Wireless LAN Profiles on a PC and Set a preferred Order
'Author :Himji
'Date Created :01/03/2012 (British Date Format)
'Revision History :
'01/03/2012 :Script Created Ready for Testing
'Notes :
'1. :You will need to export the wireless config xml files and store them securely (as they contain the network key).
'2. :Ensure the name of the XML file is the same as the wireless network profile name.
'3. :Enter the network path the the XML files in the section marked with stars ("***") below
'4. :Usage. To use this script, invoke the script with the profilesw you want added in quotes seperated by a space
'5. :Usage cont. For example WLAN_Profile_Configurator "Profile1" "Profile2" "Profile3"
Option Explicit
'*************************Change the following settings here to cusomise the script*************************
'Define Location of Profile XML Files Here
CONST PathtoXML = "\\server\sharename\path"
'************************************************* ***End******************************************** ********
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer
Dim StrWLANName
Dim CmdSetProfileOrder
Dim IntPriority
Dim WSHNetwork
Dim WShell
Dim oReg
Dim strKeyPath
Dim strValueName
Dim dwValue
Dim strValue
Dim arrSubKeys
Dim Subkey
Dim Profile
Dim Return
Dim CmdAddWLAN
Dim ArrProfileOrder
'sets the focus of the script to run against the local system
Set WSHNetwork = WScript.CreateObject("WScript.Network")
strComputer = WSHNetwork.Computername
'CONNECTION OBJECTS
'create a connection object to the windows Shell commands
Set WShell = Wscript.CreateObject("Wscript.Shell")
'create a connection object to connect to the winmgmts ojbect
Set oReg=GetObject("winmgmts:{impersonationLevel=imper sonate}!\\" & strComputer & "\root\default:StdRegProv")
'DEFINED VARIABIES
'this is the registry entry to look for wireless NICs on the system
strKeyPath = "SYSTEM\CurrentControlSet\Control\Network\{4D36E97 2-E325-11CE-BFC1-08002BE10318}"
'Adds the WLAN Profile to the client
Set ArrProfileOrder = WScript.Arguments
For Each Profile in ArrProfileOrder
CmdAddWLAN = "netsh wlan add profile filename=" & CHR(34) & PathtoXML & Profile & ".xml" & CHR(34)
Return = WShell.run (CmdAddWLAN,1, true)
Next
'enumerates all the sub keys underneath strkeypath and puts them in an array so the data can be used to find values that match for a wireless card
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
'This will look for the subkey that
For Each subkey In arrSubKeys
If subkey <> "Descriptions" Then
'Wscript.Echo strKeyPath & "\" & subkey & "\" & "Connection" 'Error Checking
'this sets the variable to the name of the registry key MediaSubType
strValueName = "MediaSubType"
'this will get the value of the registry key 1 = built in NIC 2 = Wireless
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\" & "Connection" ,strValueName,dwvalue
'this will get the value of the registry key name which tells us the name of the network card (Wireless Naetowrk Connection)
strValueName = "Name"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey & "\" & "Connection" ,strValueName,strValue
'If the media sub type = 2 then it is wireless so this will be the focus of the IF statement
If dwvalue = 2 Then
IntPriority = 0
'Sets the profile Order as defined at the start of the script
For Each Profile in ArrProfileOrder
IntPriority = IntPriority + 1
CmdSetProfileOrder = "netsh wlan set profileorder name=" & CHR(34) & Profile & CHR(34) & " interface=" & CHR(34) & strValue & CHR(34) & " Priority=" & IntPriority
Return = WShell.run (CmdSetProfileOrder,1, true)
Next
End If
End If
Next
Probably not the best of scripts but it seems to do the job well and I hope it helps somebody looking for the same
-
-
IDG Tech News
-
19th March 2012, 09:25 PM #2
- Rep Power
- 6
Wow. Thats an elaborate way to do a simple job.
When we change our key, we set a startup script.
netsh wlan add profile "XML FILE" user=all
-
SHARE: 
Similar Threads
-
By joe90bass in forum Thin Client and Virtual Machines
Replies: 1
Last Post: 17th September 2009, 12:18 PM
-
By james14100 in forum Windows
Replies: 8
Last Post: 15th September 2009, 06:27 PM
-
Replies: 3
Last Post: 16th May 2008, 04:04 PM
-
By ICTNUT in forum How do you do....it?
Replies: 16
Last Post: 4th July 2006, 04:09 PM
-
By windy in forum Wireless Networks
Replies: 14
Last Post: 7th April 2006, 11:17 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules