bat script to restart onedrive. Does it work?

Asked

Viewed 390 times

0

The scenario is that I have some computers without user interaction where I use the Onedrive to back up at dawn

With some frequency the Onedrive lock, so I decided to make a bat, very simple, to check if it crashed and restart it.

Before testing I decided to post, suddenly I missed some nonsense and/ or in case someone has any suggestions for improvement, or come to have use for someone.

@echo off
:inicio
set fiscaliza=nul

tasklist /fi "status eq not responding" >c:\bat\fiscaliza.txt
find /i "certisignergui.exe" "c:\bat\fiscaliza.txt"

if  %errorlevel% equ 0 ( 

   set datadehoje=%date:~0,2%-%date:~3,2%-%date:~6,4%  %time:~0,2%:%time:~3,2%
   echo %datadehoje%>>c:\bat\travada_onedrive.txt

   taskkill /im certisignergui.exe /f

   echo finalizando processo travado
   del "fiscaliza.txt"

  ) else (

   echo processo nao travou ainda

  )

  timeout /t 10
  goto inicio

This is the first test I did, my goal was just to check if he found and closed the program locked, the first tests worked. I put the timeout like 10 seconds, but the idea is that it rotates every 900 seconds.

  • Speak up, mate. That’s not necessarily a question. The most interesting thing is you ask a question and afterward answer your own question. Everything you need to know about this is in this help center link. Another tip is about formatting. ;)

  • 2

    It’s not clear, thank you, I edited.

  • 1

    It seems that you "tried" to turn a "script you want to share" into a question. Reason for a moment: what is your question? If it is "Does it work?" does not follow the scope of the site. You should ask questions about "real problems"... If the goal is to search for "improvements to your script", explicitly define "how and/or what you want to improve".

1 answer

4

inserir a descrição da imagem aqui


• To loop during 10 seconds monitoring if there is crashing and rebooting whenever Onedrive appear in lockup:


@echo off && setlocal enabledelayedexpansion & cd /d c:\bat
set DataDeHoje=0<nul & echo/ & Title %~n0 & mode con cols=60 lines=03 & >nul chcp 1252 
set _key="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
for /f ^delims^=^"^ ^tokens^=2^,*  %%i in ('reg query !_key! ^| findstr /lic:"onedrive"') do set "_OneDrive="%%i" %%j"
:inicio
echo/ & color 9F & set "DataDeHoje=!DATE:~0,2!-!DATE:~3,2!-!DATE:~6,4!/!time:~0,5!"&&set "DataDeHoje=!DataDeHoje: =0!"
for /f "tokens=1,* delims= " %%i in ('tasklist /fi "status eq not responding" ^| findstr /v "# ="') do (
echo/%%i %%j | findstr /lic:"OneDrive.exe" >"c:\bat\fiscaliza.txt" && (
color F4 & echo/ & echo/ !DataDeHoje:/= ! Processo: OneDrive.exe travado^^!!.. & taskkill /f /im %%i /t >nul 2>nul
start "" !_OneDrive! && pathping 127.0.0.1 -n -q 1 -p 2500 1>nul & tasklist /fi "status eq running" | findstr /lic:"onedrive.exe" >nul
if "!errorlevel!" equ "0" color 9F & cls & echo/ !DataDeHoje:/= ! Processo: OneDrive.exe reiniciado^^!!..
   ) || (
    cls & echo/ & echo/ !DataDeHoje:/= ! Processo: OneDrive.exe sem travamento^^!!..
   )) & timeout /t 10 >nul & goto :inicio

• It is possible to bat/script take these actions. But, I suggest you use the argument /T, which results in finalize the possible third party proceedings startados/initiated by him also, since, the locking may occur on account of one of these same lawsuits for his sake initialized...


• Just monitor!! Does not assume any action!!

• To loop during 10 seconds monitoring if there is locking Onedrive.exe:

@echo off & setlocal enabledelayedexpansion & cd /d c:\bat
set DataDeHoje=0<nul & echo/ & Title %~n0 & mode con cols=60 lines=03 & >nul chcp 1252
:inicio
echo/ & color 9F & set "DataDeHoje=!DATE:~0,2!-!DATE:~3,2!-!DATE:~6,4!/!time:~0,5!"&&set "DataDeHoje=!DataDeHoje: =0!"
for /f "tokens=1,*delims= " %%i in ('tasklist /fi "status eq not responding" ^| findstr /v "# ="')do (
echo/%%i %%j | findstr /lic:"OneDrive.exe" >"c:\bat\fiscaliza.txt" && (
color F4 & echo/ & echo/ !DataDeHoje:/= ! Processo: OneDrive.exe travado^^!!.. & taskkill /f /im %%i >nul 2>nul 
   ) || (
   echo/ !DataDeHoje:/= ! Processo: OneDrive.exe sem travamento^^!!..
   )) & timeout /T 10 >nul & cls & goto :inicio

• Just monitor!! Does not assume any action!!

• To loop during 10 seconds monitoring if there is another locking Any other program.exe:


@echo off & setlocal enabledelayedexpansion & cd /d c:\bat
set DataDeHoje=0<nul & echo/ & Title %~n0 & mode con cols=60 lines=03 & >nul chcp 1252
:inicio
echo/ & color 9F & set "DataDeHoje=!DATE:~0,2!-!DATE:~3,2!-!DATE:~6,4!/!time:~0,5!"&&set "DataDeHoje=!DataDeHoje: =0!"
for /f "tokens=1,*delims= " %%i in ('tasklist /fi "status eq not responding" ^| findstr /v "# ="')do (
echo/%%i %%j | findstr /lic:".exe" >"c:\bat\fiscaliza.txt" && (
color F4 & echo/ & echo/ !DataDeHoje:/= ! Processo: %%i travado^^!!.. & taskkill /f /im %%i >nul 2>nul 
  ) || (
  echo/ !DataDeHoje:/= ! Todos os processos sem travamento^^!!..
  )) & timeout /T 10 >nul & cls & goto :inicio

Browser other questions tagged

You are not signed in. Login or sign up in order to post.