Run openvpn.exe, FreeFileSync.exe, then close command prompt - batch-file

I am trying to write a batch file that connects to an OpenVPN profile, runs a FreeFileSync batch file, then exits.
cd "C:\Program Files\OpenVPN\config"
openvpn.exe --config synology.ovpn
"C:\Program Files\FreeFileSync\FreeFileSync.exe" "C:\Users\MrPeanut\Desktop\Sync.ffs_batch"
taskkill /f /im openvpn.exe
exit
It connects to my OpenVPN server. However, at this point, I'm still in the OpenVPN program, so the next command (FreeFileSync) can't run.
I know this is very basic, but I can't figure out how to run the next command while my OpenVPN program/connection is active.

You have to run it in the background, using START /B. This should work:
cd "C:\Program Files\OpenVPN\config"
START "" /B openvpn.exe --config synology.ovpn
"C:\Program Files\FreeFileSync\FreeFileSync.exe" "C:\Users\MrPeanut\Desktop\Sync.ffs_batch"
taskkill /f /im openvpn.exe
exit
I haven't tested it, but it should work fine.

Related

How do you make a simple batch file that will open multiple programs and uwp apps

First of all, I am not a coder or developer and I apologize for any ignorance from this moment forward.
I am trying to make a simple batch file that will open multiple programs and uwp apps. For example, at the start of my work day I need several programs and apps to get up and running such as edge, skype, outlook16, onenote (uwp app not program), etc.
I can get normal windows programs that use .exe to do this but I am having difficulty finding out how to do the same with windows UWP.
Any help would be appreciated.
It is a bit tricky with UWP apps, but you can definitely make it.
Put the live tiles of the UWP apps you want a shortcut to in the start menu. And then drag and drop the tile itself on the Desktop. This will create a shortcut to that app. Now you can manually launch the shortcut via the batch file, or even more easily - copy the created shortcuts into the Startup folder:
C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
You can open this folder even faster by hitting Windows + R and typing shell:startup.
Other option for launching the apps would be to use their associated URI protocol. OneNote has onenote-cmd: or onenote:, Edge has microsoft-edge: (or you can use any website URL if it is your default browser). There are more URI schemes, a short list is available here for example.
I do not know about UWP, but these may be.
I wrote this answer because it was high on my search and most answer I found had little examples.
And this provides a few more ideas for programs that run in the taskbar(in the background).
Here is my "Work Start.bat" batch file sitting on my desktop:
rem Work Start Batch Job from Desktop
rem Launchs All Work Apps
#echo off
rem start "Start VS Code" "C:\Users\yourname\AppData\Local\Programs\Microsoft VS Code\code.exe"
start "Start OneDrive" "C:\Users\yourname\AppData\Local\Microsoft\OneDrive\OneDrive.exe"
start "Start Google Sync" "C:\Program Files\Google\Drive\GoogleDriveSync.exe"
start "Start Clipboard" "C:\Program Files\Beyond Compare 4\BCClipboard.exe"
start "Start Cisco AnyConnect" "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
start outlook
start chrome
start firefox
start skype
start "Start Teams" "C:\Users\yourname\AppData\Local\Microsoft\Teams\current\Teams.exe" /MIN
start Slack
start Zoom
sleep 10
taskkill /IM "explorer.exe"
taskkill /IM "teams.exe"
taskkill /IM "skype.exe"
taskkill /IM "slack.exe"
taskkill /IM "zoom.exe"
taskkill /IM "cmd.exe"
#echo on
Some Apps would not start with a simple "start app" command, so I used the full path.
For some reason some were found in my user appdata folder and not in program files, I do not understand this behaviour of program storage, it makes no sense.
I used a time delay so that the apps could fully start before I sent them to the background using taskkill command
I killed explorer.exe because OneDrive opens explorer
I killed cmd.exe because it opened and stayed opened due to badly behaving apps.
The rest I killed so that they would just move to the background.
Here is my "Work End.bat" batch file to forceably close everything:
rem Work End Batch Job from Desktop
rem Forcibly Closes All Work Apps
#echo off
taskkill /f /IM outlook.exe
taskkill /f /IM OneDrive.exe
taskkill /f /IM GoogleDriveSync.exe
taskkill /f /IM BCClipboard.exe
taskkill /f /IM "vpnui.exe"
taskkill /f /IM "chrome.exe"
taskkill /f /IM "firefox.exe"
taskkill /IM "explorer.exe"
taskkill /f /IM "teams.exe"
taskkill /f /IM "skype.exe"
taskkill /f /IM "slack.exe"
taskkill /f /IM "zoom.exe"
#echo on
I do have to ensure I have saved all my work, and that files are no longer syncing.
Possibly I will need a batch file that kills everything except file sync.
The good thing about forceably killing Chrome and firefox is they ask to be restored on next start, so I can continue where I left off, assuming I saved everything.
If I don't forceably kill these they stay in the background, if I close using the Cross they do not offer me to start from where I left off.
I could then start my gaming files, in another batch file but this would be similar to the first file.
Now I can turn off the default "Start Up" Apps and use this "Work Start.bat" , because the Start Up Apps annoy me when I start my pc for gaming.

Using PSEXEC to invoke a batch script on a remote machine won't launch Firefox

I am having the following issue:
Using PSEXEC, I remote into a machine to execute a batch script that is saved there, but the last line doesn't execute (it wont open Firefox .. the Firefox process shows up but the GUI doesn't launch).
However, if I go to the remote machine and double-click the batch file it works just fine.
Here is the command that I run locally:
psexec -u USER -p PASSWORD \\REMOTE_SERVER -d cmd.exe /c "C:\Users\MY-REMOTE-MACHINE\Desktop\windows_setup.bat"
Here are the contents of that batch script:
taskkill /f /im "iexplore.exe" /t
taskkill /f /im "chrome.exe" /t
c:\Windows\SysWow64\TaskKill /f /im "iexplore.exe" /t
c:\Windows\SysWow64\TaskKill /f /im "chrome.exe" /t
start "" "C:\Users\MY-REMOTE-MACHINE\AppData\Local\Mozilla Firefox\firefox.exe"
Note: I have also tried replacing the last line with start firefox ... same exact issue. It only works if I open the batch script directly from the target machine.

Microsoft update msu silent mode batchfile

I have the MSU for Win7AndW2K8R2-KB3134760-x64, which includes updates for PowerShell 5.0
I have a batchfile with the following to run the MSU in silent mode, but when I run it, it brings up the CMD window, then closes fast.
#echo off
start /wait ".\Win7AndW2K8R2-KB3134760-x64.msu" /quiet /norestart
Try this
#echo off
start "" /wait "Win7AndW2K8R2-KB3134760-x64.msu" /quiet /norestart

Batch file start command launching process but not launching GUI window

So i'm trying to do a simple task restart on a box that needs a GUI app running on the desktop. I'm using the start command to call the application. For some reason when i run it from the task scheduler it does everything it's supposed to except launch the application's GUI window. I can see the process running in Task Manager, but no GUI launches. This is Windows 2008 R2.
Here's the script replacing the app with notepad (which has the same problem).
#echo off
:: Kill notepad.exe if running.
TaskKill /IM notepad.exe /F
:: Wait for app to close.
PING 1.1.1.1 -n 1 -w 8000 >NUL
:: Check to make sure app isn't running, then start it.
tasklist /FI "IMAGENAME eq notepad.exe" 2>NUL | find /I "notepad.exe">NUL
IF NOT "%ERRORLEVEL%"=="0" START "" "notepad.exe"
EXIT %ERRORLEVEL%
Is this a Windows 2008R2 Task Scheduler gotcha, or a batch file gotcha?
You must have the option to "Run only when user is logged in" selected. Otherwise the task will be launched as an invisible background process.

how to run cmd from batch file and go to folder within parent folder

I have to create a batch file as below
1) It will run cmd
2) then withing that command prompt goes back to parent folder may be with cd..
3) then go to folder jar may with cd jar
4) run command java -jar TASKApi.jar
and this command prompt should remain open
currently I am using below code
start cmd.exe /k cd..
cd jar
java -jar TASKApi.jar
But only first line works other two line does not
Please tell me how can I do this
Edited after a comment below:
:: two.bat
#echo off
cd /d "c:\folder\jar"
java -jar "TASKApi.jar"
To keep the console window open for further input, launch the batch file above from another batch file.
:: one.bat
#echo off
cmd /k call two.bat

Resources