how to run batch file w taskscheduler in the background without stealing focus?


m18xr2

Well-known member
Member
Local time
4:14 PM
Posts
13
OS
win11 and 10
so I have this batch file below to turn off wifi and turn it back on, then using task scheduler to run it every 12 hours

start /B "" "C:\Users\(username)\Tools\WifiSchedule\WLANOFF.lnk"
ping 127.0.0.1 -n 4 > nul
start /B "" "C:\Users\(username)\Tools\WifiSchedule\WLANON.lnk"

the thign is, each time this runs a windows pops up and steal focus and it's quite annoying. blocks what im reading or if im doing work it interrupts and steals focus again when CMD disappearing. what line do I add in the CMD command line to have this in the background?
 

My Computer My Computer

At a glance

win11 and 103940xm16gb780m
OS
win11 and 10
Computer type
Laptop
Manufacturer/Model
dell/alienware
CPU
3940xm
Memory
16gb
Graphics Card(s)
780m
Monitor(s) Displays
18.4
Screen Resolution
1080p
With this Virtual Basic script (.vbs), you can execute batch script silently.

Change "C:\Registry_Backups\Scripts\RegBackup.bat" with folder path and batch script name.


Code:
Set WshShell = CreateObject("WScript.Shell")

cmds=WshShell.RUN("C:\Registry_Backups\Scripts\RegBackup.bat", 0, True)


Set WshShell = Nothing
 

My Computer My Computer

At a glance

Windows 11AMD Ryzen 7 5700GMicron Technology DDR4-3200 16GBNVIDIA GeForce RTX 3060
OS
Windows 11
Computer type
PC/Desktop
Manufacturer/Model
HP Pavilion
CPU
AMD Ryzen 7 5700G
Motherboard
Erica6
Memory
Micron Technology DDR4-3200 16GB
Graphics Card(s)
NVIDIA GeForce RTX 3060
Sound Card
Realtek ALC671
Monitor(s) Displays
Samsung SyncMaster U28E590
Screen Resolution
3840 x 2160
Hard Drives
SAMSUNG MZVLQ1T0HALB-000H1
With this Virtual Basic script (.vbs), you can execute batch script silently.

Change "C:\Registry_Backups\Scripts\RegBackup.bat" with folder path and batch script name.


Code:
Set WshShell = CreateObject("WScript.Shell")

cmds=WshShell.RUN("C:\Registry_Backups\Scripts\RegBackup.bat", 0, True)


Set WshShell = Nothing
sorry for the late reply, how do I run this? this is cmd or ps?
 

My Computer My Computer

At a glance

win11 and 103940xm16gb780m
OS
win11 and 10
Computer type
Laptop
Manufacturer/Model
dell/alienware
CPU
3940xm
Memory
16gb
Graphics Card(s)
780m
Monitor(s) Displays
18.4
Screen Resolution
1080p
how do I run this?
Create a blank text file, paste those contents inside it, rename the file extension to .vbs
You can then double-click on the .vbs file to run it.

this is cmd or ps?
Neither. It's a third scripting method. VBS has been a part of Windows for decades.
It's long been regarded as on its way out.
PS can do everything that VBS can do. But I also use VBS for small jobs like this because I'm used to it and I haven't learnt a simple way of using PS for this yet.

MS stopped including the VBS Help file years ago. I think XP was the last time they issued it.
You can download a copy if you want to. It's a great learning resource.
Windows Scripting 5.6 Documentation by Ryan Farley
But it's best to regard VBS as merely a potential helper for some things.
If you are going to put effort into learning anything then make it PS.
my ditty - Batch file and PowerShell guides [post #7] - ElevenForum


All the best,
Denis
 

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
Back
Top Bottom