I have been browsing the forums and have not found a better solution to my script so I am reaching out for some help. Working in a mobile environment on a hot spot and when I return to the campus I want to print to a printer on the corporate wireless. The corporate network is preferred, but still at times it seems reluctant to drop the mobile hot spot and move to the corporate wireless. I think it just doesn't see the corporate until you hit the wireless network list and then sometimes it starts to connect and other times it needs to be forced.
Based on what I have learned form the forums what I have done as once the script has been started it checks for the wireless network every 5 seconds. It uses NET STAT to pull the wireless connection name and compare. If it is not the corporate network the script attempts to connect to that network name. This doesn't seem to always work. Is there a better way to have the wireless search for available networks and then let Windows connect to the preferred network once is sees it? Or is the route I am going to manually attempt a connection to the corporate wireless by command the best way?
Code: Select all
;RUN WIFI CONNECT SCRIPT
Loop 60 { ;MAKE 60 ATTEMPTS TO CONNECT
Gosub, CONNECTSTATUS ;LOAD WIRELESS CONNECTION STATUS
IfInString, Var, data_corpnet ;IF CONNECTED TO data_corpnet, DONE
{
FormatTime, TimeString,, MM-dd-yy HH:mm:ss
FileAppend, %TimeString% Attempt: %A_Index% Connected to data_corpnet `n, greeterlog.txt
MsgBox, 64,SUCCESS!,Connected to data_corpnet. Pre-registration data in queue to print.
ExitApp
}
else ;IF NOT CONNECTED, ATTEMPT CONNECTION q30 x5 MINUTES
FormatTime, TimeString,, MM-dd-yy HH:mm:ss
FileAppend, %TimeString% Attempt: %A_Index% Attempting to connect to data_corpnet `n, greeterlog.txt
run netsh wlan connect name=data_corpnet,, hide
Sleep, 5000 ;5 seconds
}
;SUBPROCEDURES
CONNECTSTATUS: ;LOAD WIRELESS CONNECTION STATUS
RunWait %comspec% /c netsh wlan show interface > network.txt,, hide ;LOAD WIRELESS CONNECTION STATUS
FileRead, Var, network.txt
return
Code: Select all
;SET DEFAULT PRINTER
Run, C:\Windows\System32\RUNDLL32.exe PRINTUI.DLL`,PrintUIEntry /y /n "Greeter"
While OutputVar1 <> "Greeter"
{
RegRead, OutputVar, HKEY_CURRENT_USER, Software\Microsoft\Windows NT\CurrentVersion\Windows, Device
StringSplit, OutputVar, OutputVar, `,
}