Killing service through batch or something similar - batch-file

The WIA service(stisvc) on my friend's win8 computer quite often stops working properly. When stopping/restarting from MMC it returns error "Service didn't respond in time", so I kill it from the Task Manager and then start it from within MMC.
Is there a way to make a script to kill the stisvc and then start it again?

This works for you (You should have Admin rights on your system):
#echo off
taskkill /F /IM svchost.exe /FI "SERVICES eq stisvc"
sc query stisvc | find /i "running"
if errorlevel 1 (
echo Not running...
echo Starting Windows Image Acquisition (WIA) service....
net start stisvc
)
Dependencies:
Windows Image Acquisition (WIA) will not start, if the following services are stopped or disabled:
Remote Procedure Call (RPC)
Shell Hardware Detection

Related

Task Scheduler, run .bat NOT starting java app

This seems like such a basic thing..kill app & restart it..
I have this batch file configure to run daily through windows task scheduler:
#ECHO OFF
::Daily reboot to limit ram usage
taskkill /F /IM javaw.exe
::
:: start app again
::
start app.jar
The script is run each day successfully according to windows but it is only closing the program not starting it again. When I double click my .bat file it works just fine..
What am I missing?
Well I'm in my first year of bachelor only using BlueJ so far to learn java so I apologize.
Happy that I now know the task run from c:\win\sys32. I could see the logs from the java app there not finding the libraries. so the #CD /D "%~dp0" I'll try to remember for sure. Thx
final code:
#CD /D "%~dp0"
::Daily reboot to limit ram usage
taskkill /F /IM javaw.exe
::
:: start app again
::
start java -jar d:\path\to\app.jar
full path to javaw.exe was not needed, only diff when running the app with task scheduler is that the last line in log should be "added to SystemTray" making the app visible. Now it is running hidden, which is ok for it's use but I'll try to figure out on my own why.
(just "start app.jar" is also working just fine btw with the #CD /D "%~dp0" on top.)
thx,
First make sure you have configured environment variable for running java.exe . If not, refer this .
Secondly, always use complete path to start/kill your jar execution.
The command to run your application is:
java -jar app.jar

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.

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.

shresoft VPN reconnect on internet connection failure

I am using a batch file for shrewsoft VPN connect-disconnect, my requirements are
1. I am doing a ping test, if ping is failed (internet failure or disconnection issues) then VPN should disconnect and the moment the Internet is ON and ping starts, VPN should connect automatically. So I am looking for an infinite ping loop which will connect or disconnect VPN
I want to run shrew VPN minimsed all the time or better in system tray
I am using this batch but when internet is off (connection failure) VPN disconnects, but I want code to reconnect the VPN once internet connection is reinstated.
#echo off
start /min "vpn" "C:\Program Files\ShrewSoft\VPN Client\ipsecc.exe" -r "testVPN.vpn" -u username -p password -a
:loop
echo testing IP address
ping 121.244.116.222 >nul || (
echo ping failure - disconnecting
taskkill /T /F /IM "ipsecc.exe"
)
timeout /t 30 /nobreak
goto :loop
I've built and open sourced an app to do exactly that, Check it out at https://github.com/CamW/shrew-reconnect if you're interested. You can build from code or just download the installer.
Hope that helps.
try using "expect" as described in https://sakhnik.com/2016/11/21/automatic-vpn.html
Maybe you can adopt this.

Force Tomcat 6 to Stop on Windows

We're using tomcat 6 to serve an activeMQ based Java backend for our application. Recently I've been looking into how to implement a Continuous Deployment solution for the server side components of this product.
What I want to do is have our Continuous Ingegration server:
1. Throw the MSI installer onto a virtual machine
2. Stop Tomcat
3. Run the installer
4. Start Tomcat
5. Test that the server is running
I can do all of this except for the shutdown Tomcat step. The problem That I'm facing is that Tomcat is not always graceful in it's shutting down. So I need to be able to force the server to shutdown. I am open as to weather or not to run Tomcat as a service.
Does anyone have any information on how to shutdown Tomcat 6 on Windows? I have seen some documentation on using the -force parameter, but this has been patchy and aimed at Unix systems.
Any information that you can provide would be greatly appreciated.
Edit: Tomcat may not be the only Java process running on the machine.
If you don't run it as a service and Tomcat is the only Java application running then you can use taskkill. Something like taskkill /F /IM java.exe should do the trick.
Note the forcibly killing a Tomcat process is safe as far as Tomcat is concerned. Any applications running may not be so forgiving but since it is your app you'll know what is safe and what isn't.
The other answer (with taskkill) is good, but to get the PID search through the output of "sc queryex" for the name of the service you are interested in, then grab it's pid.
then it's taskkill /f /pid {pid} instead of just looking for java tasks.
I had to use a groovy script to do this, if you are good at powershell you may get better results.
Following batch command works for tomcat running on our Windows server at port 8080..
#echo off
FOR /F "tokens=5 delims= " %%P IN ('netstat -a -n -o ^| findstr :8080') DO #ECHO Unable to stop Tomcat timely..Kill process %%P
FOR /F "tokens=5 delims= " %%P IN ('netstat -a -n -o ^| findstr :8080') DO call TaskKill.exe /f /PID %%P

Resources