wm withdraw . proc writelog {data} { set timestamp [clock format [clock seconds] -format {%D %X}] set fileId [open c:\\batch\\winnetfix.log a+] puts $fileId "$timestamp - $data" close $fileId } catch {exec c:\\windows\\system32\\ping.exe -n 1 192.168.1.1} result switch -glob $result { *from* {set connection 1} *timed* (set connection 0; writelog "Timed Out"} default {set connection 0; writelog "Default Used"} } if {$connection == 0} { catch {exec c:\\batch\\devcon.exe disable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } disable catch {exec c:\\batch\\devcon.exe enable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } enable writelog "Fixed Connection!" exit } exit '''Revised Source''' - Feel free to correct wm withdraw . proc writelog {data} { set timestamp [clock format [clock seconds] -format {%D %X}] set fileId [open c:/batch/winnetfix.log a+] puts $fileId "$timestamp - $data" close $fileId } catch {exec c:/windows/system32/ping.exe -n 1 192.168.1.1} result switch -glob $result { *from* {set connection 1} *timed* (set connection 0; writelog "Timed Out"} default {set connection 0; writelog "Default Used"} } if {$connection == 0} { catch {exec c:/batch/devcon.exe disable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } disable catch {exec c:/batch/devcon.exe enable @USB\\VID_07B8&PID_6001\\6&3534C65&0&5 } enable writelog "Fixed Connection!" exit } exit
RT For one, you can replace all the escaped backslashes in the first argument to exec and in the open command with a single forward quote. Don't replace backslashes in latter arguments to exec - 15Mar07TJC Do you mean like in the Revised Source? - 15Mar07
Questions - If there are any questions or suggestions on how to make this better please feel free to add them here. I will be sure to keep an eye on this page to see what everyone comes up with. Tory Clement
One very minor thing. It is often important that the logged message describes EXACTLY what the program has done not the result that it expects ("Fixed Connection!") unless that result is thoroughly tested. May also be a good idea to include $enable in the log to record any errors raised.
writelog "USB wireless device restarted. Result: $enable"