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
I am using batch Script for silent Installation to update the locked and in use files.Using silent installation reboots my system automatically after the update.But I wanna setup a custom reboot message box , So I used the REBOOT=ReallySuppress attribute. And I used a message box to popup the custom reboot message. This helps me avoid the auto-reboot of the system but it is not updating the files even after performing a manual reboot.
Here is the script that I am using.
#echo off
title Installing Updates
msiexec /i "C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi" /qn /REBOOT=ReallySuppress
echo updates installed
echo msgbox "Restart your system to complete the installation." > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"
pause >NUL
shutdown.exe /r /t 000
Can someone give me a solution to get the files updated with manual reboot.
did you try instead of /REBOOT=ReallySuppress the /norestart option?
Please also make a log file in the install cammand via /l option. Then read the log if really the installer reboots the computer.
I've an issue that seems a privilege issue but i really do not understand what is happening.
This is my installation script :
...some command...
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil C:\Programmi\ProgDir\ProgService.exe >> log.txt
ping 127.0.0.1 -n 5 > null
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /f
ping 127.0.0.1 -n 2 > null
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d C:\Programmi\ProgDir\ProgName.exe /f
I try this script using installation wizard (created by winrar) and manually , in both cases i give to the script admin privilege; to prove this the service is installed successfully (it require administration privilege, so the script has these privileges as expected) but the registry is not affected if the script is launched by the wizard.
Can anybody explain to me what is happening ?
Thanks in advance (and sorry for my poor english)
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
I am trying to use a windows batch script that uses PsExec to execute commands on a remote machine. Periodically it has "invalid handle" and the script then fails.
The script has not altered or indeed either machine.
Does anybody know why this happens as sometimes the scripts runs without a hitch.
Alternatively does anybody know how to run a script on a machine as the local user for that machine with a more reliable technology.
PS Sometimes the first PsExec works and the others fail.
EDIT
The script is just on line (apart from setting the appropriate variables)
PsExec %HOSTNAME% -I -u %USERNAME% -p %PASSWORD% CMD /C RMDIR /S /Q e:\SomeDir
This sometimes works but sometimes fails with "invalid handle"
You need to debug the situation.
You have a script, then something (what is Jenkins?) launch it on a remote PC, sometime it works, sometime it fail.
Is it deterministic?
When it fail does it always fail?
How does it fail?
You need to acquire better knowledge of how/when the script fail.
Here is what I would do to gather better understanding of these fails.
Can you run the script multiple time?
From the comments it seem that you run the script every hours, can you run it 3/4/5 time in a row, for each hours?
This will help you to determine how it fail: if you run it 5 time, does it works every time? it it fail, does it fail 5 times in a row?
Can you try to use different script?
You can create some more similar, but simpler, scripts.
So you can try your script with the RMDIR, then another script with a simple DIR command (just to se if the script launching/connection mechanism works) then another script with a simple ECHO command (so it doesent need to access any files/folder)
Run debug scripts on the local PC
Then, you can simultaneously run other scripts that run on the LOCAL PC (not the remote one where you need to execute the RMDIR) that try to access the remote PC, with a PING, or by copying a file from/to a network share...
Sniff the network
You can even set up a Wireshark instance that log all the packet sent between the 2 PC, this can be helpful to analyse/exclude networking issue.
You clearly need to track/log everything.
With this kind of information maybe you/we can have a better understanding of where the issue is.
=====================================
UPDATE 1 - Record some log
=====================================
Maybe you can try to use the following modified scripts to have some log files.
These script will create 2 log files, one on the remote PC (containing the message of the remotely executed command) and one on the local PC (containing any message from PsExec)
(you'll need to tweak the path where the log file are saved)
psexec %HOSTNAME% -I -u %USERNAME% -p %PASSWORD% CMD /C "RMDIR /S /Q e:\SomeDir >>c:\RemoteComputer.log 2>&1" >>c:\LocalComputer.log 2>&1
or the following one without the /I
Are you sure you need the /I parameters for CMD? On my Pc it doesn't works if I use the /I parameters...
psexec %HOSTNAME% -u %USERNAME% -p %PASSWORD% CMD /C "RMDIR /S /Q e:\SomeDir >>c:\RemoteComputer.log 2>&1" >>c:\LocalComputer.log 2>&1
After some testing on my PCs, I've seen that PsExec install a service on the remote PC to run the command remotely. (It's called PsExecSvc.exe, installed in c:\windows\ on the WinXP PC I'm using for this test)
The remote installation/uninstallation of this temporary service for the command execution can surely be one of the possible "failure point" that generate the error.
If this is the case, then you should be able to track this down by looking at the LocalComputer.log, that will contain the message/error from PsExec.
As stated in my previous advice, I would also try to schedule simpler script like
psexec %HOSTNAME% -u %USERNAME% -p %PASSWORD% CMD /C "dir c:\ >>c:\RemoteComputerDir.log 2>&1" >>c:\LocalComputerDir.log 2>&1
and
psexec %HOSTNAME% -u %USERNAME% -p %PASSWORD% CMD /C "echo SuperEchoTest >>c:\RemoteComputerEcho.log 2>&1" >>c:\LocalComputerEcho.log 2>&1
===================================
UPDATE 2 - Try to use WMI
===================================
You can try to run the remote command by using WMI
wmic /node:%HOSTNAME% /user:%USERNAME% /password:%PASSWORD% process call create "CMD /C RMDIR /S /Q e:\SomeDir"
When you use WMI you need to be sure that windows firewall is not blocking your command. (when I tried to run a remote command with WMIC the windows firewall notification popped up on my Win 7 PC)
(I've the instruction to use WMIC here)
Yes, there is a more reliable technology for executing commands on a remote machine and is called powershell. For example, you can run :
test-connection -computername server01, server02, server12
pings from local computer to several remote computers.
Another very useful command is:
invoke-command -filepath c:\scripts\test.ps1 -computerName Server01
runs the Test.ps1 script on the Server01 computer.
A tutorial gives several examples on how to Run PowerShell Commands on Remote Computers.
A different technology can be found mimicking the Linux world, and using ssh. It's very common with clusters and I have personally used it with Windows Server 2008 R2, so I don't expect any difference on windows 7.
This task is commonly performed with ssh and password-less public key authentication. With it, the only needed information is the IP of the remote server and the public key of the client, stored on the server: only the client with the corresponding private key can connect to it (the keys must be created with ssh-keygen, on the client. The public key is copied to the server)
The server must have the TCP port 22 accessible from outside, in case there are firewalls, NATs,...
In my case I used the ssh server included in Windows SUA, but I suggest you forget them (they are deprecated, and quite cumbersome actually) and give a try to the OpenSSH cygwin server, sshd - even if not officially Microsoft, there is a large community supporting it at least - and occasionally I have used it reliably.
The client ssh command is included in SUA, in cygwin, or you can use putty if you want a lightweight solution on the client (not that cygwin is heavy - just the burden of having a sort of linux emulation that's not needed)
Giving a search for example I have found this post, explaining well the needed steps.