Windows 10 How check every x minutes if there is specific bat file in the folder, and execute if present

yugo23

New Member
Joined
Dec 7, 2017
Messages
3
I want to do the following - first deploy new version of software to multiple PCs, and then restart all PCs for changes to take effect.

First part is not a problem, for second part is it possible to check if there is restart.bat in Dropbox folder every x minutes, and if there is, execute it. Hoping everything works fine, I would just remove restart.bat from Dropbox after 10 minutes.

How can I achieve this bat check?
 

Solution
Powershell

Code:
$rebootScript = "PATHTODROPBOXDIRECTORY\reboot.bat"

WHILE($true)
{
    IF(Test-Path -Path $rebootScript)
    {
        Start-Process -Path $rebootScript
        break
    } ELSE
    {
        Start-Sleep -Seconds 300
    }
}

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,998
CMD/batch are going to be deprecated in the future you're better off using powershell.

If you're using a script to install the software you could do

Code:
install sofware....


:LOOP

IF EXIST PATHTODROPBOXDIRECTORY\reboot.bat (
shutdown /r /t 10 /c "Computer restarting to complete software install"
GOTO EXITLOOP
) ELSE (
TIMEOUT /T 300
GOTO :LOOP
)

:EXITLOOP
exit 0
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,998
Powershell

Code:
$rebootScript = "PATHTODROPBOXDIRECTORY\reboot.bat"

WHILE($true)
{
    IF(Test-Path -Path $rebootScript)
    {
        Start-Process -Path $rebootScript
        break
    } ELSE
    {
        Start-Sleep -Seconds 300
    }
}
 

Solution

yugo23

New Member
Joined
Dec 7, 2017
Messages
3
CMD/batch are going to be deprecated in the future you're better off using powershell.

If you're using a script to install the software you could do

Code:
install sofware....


:LOOP

IF EXIST PATHTODROPBOXDIRECTORY\reboot.bat (
shutdown /r /t 10 /c "Computer restarting to complete software install"
GOTO EXITLOOP
) ELSE (
TIMEOUT /T 300
GOTO :LOOP
)

:EXITLOOP
exit 0

This restarts PC if reboot.bat is already in dropbox folder. If I add reboot.bat during countdown nothing happens, window just closes after 300 seconds, it doesn't loop?
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,998
This script would look for that file and if found kick off a restart. If you would rather have it launch the reboot.bat then replace the shutdown line with START PATHTO\reboot.bat

You'd probably be better of just forcing a reboot after the install, if you have systems in use include the /c flag to notify users of system reboot
 

yugo23

New Member
Joined
Dec 7, 2017
Messages
3
I missed :loop when copying, works great now. The only problem is different path to Dropbox folder depending on usernames. Or I could install dropbox to C:\dropbox for example.
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,998
IF EXIST C:\Users\%username%\REST\OF\DROPBOX\PATH

%username% will expand to the logged in username
 

Back
Top