New
#31
batch file so cmd interpreted. But hey what would i know right
If you'd like to post your existing batch file then I could integrate that into my first one as well to give you a comparison to look at.
Denis
yea I was having trouble getting it going but I dont think its the code. I think windows PS is lacking some libraries or some kind cause each time I execute command that works for other, it just says it doesn't recognize it.
but my batch is simple, its just a line in .PS1 file.
Restart-NetAdapter -Name "Wi-Fi 13"
Actually, I thought yours was a batch script not a PowerShell script but here's how I can integrate it within my suggested framework [post #28 above].
The script needs to be run by TS on Idle and as Admin and TS needs to run it only if a network connection is detected.
Then the script will achieve what you want.
You can call the script whatever you want as long as you leave its file extension as .bat
I've left in my explanatory comments but you can remove them to simplify the picture if you want.
I assume the WiFi adapter name you are using is correct [Wi-Fi 13] as shown in the Network & sharing centre dialogs
Code:ncpa.cpl
Code::: Initialisation Prompt $g Set WWWConnection=Off Set OutputFolder=%Temp% Set OutputFile=%Random%-WWWConnection-TestResults Set /a TestCounter=0 :DoTheTest :: Run test 3 times if connection appears to be off in case it was a duff result [seen at least once] Set /a TestCounter=%TestCounter%+1 powershell -Command "Invoke-WebRequest http://www.msftconnecttest.com/connecttest.txt -OutFile %OutputFolder%\%OutputFile%" dir "%OutputFolder%\%OutputFile%" If %ErrorLevel% GTR 0 (Set WWWConnection=Off) & (If %TestCounter% LSS 3 GoTo DoTheTest) If %ErrorLevel% EQU 0 (Set WWWConnection=On) & (del "%OutputFolder%\%OutputFile%") ::Detect the result If "%WWWConnection%"=="On" GoTo EndWWWConnectionTest :: Restart the WiFi network adapter if the internet network connection exists but does not function i.e. no web addresses are working ::::: This is your existing PS code for resetting your network adapter powershell.exe restart-netadapter -Name 'Wi-Fi 13' :EndWWWConnectionTest Pause at the end during testing - WWWConnection is %WWWConnection% :: The batch file now closes of its own accord :: Notes :: If there is an internet connection, the output file is created :: If there is no internet connection, the output file is initially created but is deleted by powershell when it generates its failure response. :: If you were to run this non-minimised, you would see some red text as it failed to find the www.msftconnecttest.com/connecttest.txt file
If you have only a single WiFi adapter then the script could be improved by detecting the WiFi adapter's name then using it. This will be handy if you continue to experiment with drivers and any of them cause its name to change.
Best of luck,
Denis
question, about %OutputFolder%\%OutputFile% do I manually enter an output directory myself?
also, if I double click the PS file, brief window comes and exit and I have no idea if it works or not. but when I try to run the powershell script in PS window via cli, such as newwifires.ps1 (name of the file I saved it as) it won't run. it just show the below:
%OutputFolder%\%OutputFile%
Those variables are set within the script - see lines 4 & 5.
There is no PS1 file to run. It's a batch script. "You can call the script whatever you want as long as you leave its file extension as .bat"
It calls a powershell command on one line but it remains a batch script.
You can run it manually but, as with running it through TS, it must be run as Admin.
Denis