Sign in to follow this  
Followers 0
quoc77

Windows 7 Wireless Network Profile

6 posts in this topic

Hello All.  First off I'm very novice at writing scripts or program.  I have been trying to create an automated script that would automatically create a Windows 7 wireless network profile and then have it connected.  I created a simple batch file using netsh that would do this but then I found out, the script doesn't work on a different computer as it would ask for the security key.  In searching Google, I came across '?do=embed' frameborder='0' data-embedContent>> , but with my little experience, I can't make heads or tails on many of the syntax.  I have tried editing the existing code but none of my attempts has worked and I might be more confused than before.  Could anyone give me a headstart of what I need to begin my script with?  Any help would be much appreciated.

Share this post


Link to post
Share on other sites



If you post the code you have so far perhaps someone could give you a direction to go.

Share this post


Link to post
Share on other sites

Run ("cmd.exe")
WinWaitActive ("Administrator: C:\Windows\system32\cmd.exe")
Send ("netsh wlan add profile filename=C:\Source\Elevate-AB0F.xml{Enter}")
Send ("netsh wlan connect name=Elevate-AB0F{Enter}")
If WinWaitActive ("Connect to a Network", "$Security key:") Then
   Send ("86614480")
   Send ("!OK")
EndIf
WinClose ("Administrator: C:\Windows\system32\cmd.exe")

I'm embarrassed to even post my code but this is what I currently have.  It opens the command prompt, send the netsh commands (calling a xml profile with the SSID and Security key).  This works okay on the laptop that I created the xml file but if I run the autoit script on a different laptop, it doesn't connect cause it ask for a security key.  So the if statement, in theory is suppose to send the key and everything works fine.  Wrong.  I'm sure there's a simplier way to do this with autoit without having to use the xml file.  I created another script that opens up the Network and Sharing Center dialog box but I can't seem to know the exact code to click on the "Manage wireless network" link that to continue. 

 

Share this post


Link to post
Share on other sites

Search the Forum for @ComSpec and netsh for an easier approach. I know I posted something a couple of years ago.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Thanks for the suggestion.  The @Comspec & netsh did lessen my overall script but it's still popping up the task bar balloon to enter the security key, which I cannot activate or send the key to.

RunWait (@ComSpec & " /c " & "netsh wlan add profile filename=C:\Source\Elevate-AB0F.xml")
RunWait (@ComSpec & " /c " & "netsh wlan connect name=Elevate-AB0F")

Here's another script that I'm trying to write to perform the same function of creating a network wireless profile, but I can't seem to have autoit click on the link name "Manage wireless networks"

Run ("control /name Microsoft.NetworkAndSharingCenter")
;ControlClick ("Network and Sharing Center","Manage wireless networks", "[ID:left]")
WinWaitActive ("Network and Sharing Center")
ControlClick ("Network and Sharing Center","", "[Class:DirectUIHWND; Instance:4; Text:'Manage wireless networks'; Button:Left]")

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I found another approach that will automate the creating of a wireless network profile in Windows 7.  Posting it here for others that's looking to do the same as future reference. 

If WinActive ("Network and Sharing Center") Then
   WinClose ("Network and Sharing Center")
EndIf

;Open Network and Sharing Center
Run ("control /name Microsoft.NetworkAndSharingCenter")
Sleep ( 2000 )
;ControlClick ("Network and Sharing Center","Manage wireless networks", "[ID:left]")
;WinWait ("Network and Sharing Center")
WinWaitActive ("Network and Sharing Center")
AutoItSetOption("SendKeyDelay", 40)

;Tab selection over the Manage wireless network link and proceed to the next screen
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{ENTER}")
Sleep ( 2000 )
;Tab selection over the Add link and proceed to the next screen
WinWaitActive ("Manage Wireless Networks")
AutoItSetOption("SendKeyDelay", 40)
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{ENTER}")
Sleep ( 2000 )

;Press Enter to go to the Manually connect to a wireless network screen and enter network settings
WinWaitActive ("Manually connect to a wireless network")
AutoItSetOption("SendKeyDelay", 40)
Send("{ENTER}")
Sleep ( 2000 )

WinWaitActive ("Manually connect to a wireless network")
AutoItSetOption("SendKeyDelay", 40)
Send("<SSID>")
Send("{TAB}")
;Below will select WPA2-Personal
Send("{DOWN}")
Send("{DOWN}")
Send("{DOWN}")
Send("{TAB}")
;Below will select AES
Send("{DOWN}")
Send("{TAB}")
Sleep ( 2000 )
Send("<Security Key>")
Send("!N")
Send("{TAB}")
Send("{ENTER}")
Sleep ( 2000 )
WinClose("Manage Wireless Networks")

;Connect to new SSID
RunWait (@ComSpec & " /c " & "netsh wlan connect name=<SSID>")
Edited by quoc77

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