Solved

simple batch file to kill broswer and restart again.

Posted on 2011-09-07
73
1,631 Views
Last Modified: 2012-05-12
Need to get this to kill any opera process running, then restart both these instances, and exit.


taskkill /im opera.exe
"C:\Program Files (x86)\Opera\opera.exe"
"C:\Program Files (x86)\Opera2\opera.exe"
exit


I'm sure im missing something simple here.


(dont worry about both being chrome, play like they are calls to what ever they are installed as services and start fine)
0
Comment
Question by:theotherkitty
  • 26
  • 24
  • 14
  • +2
73 Comments
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
The taskkill process will only kill one instance of the program so it needs to be repeated for each running instance of the opera.exe program. This simplest way would be to include multiple taskkill lines in the script.
0
 

Author Comment

by:theotherkitty
Comment Utility
Hi there, ive tested it and it does kill both instances since they are both named opera.exe, i just cant get the instances to start back up......
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
If you just do this at a command line, does it start:

"C:\Program Files (x86)\Opera\opera.exe"

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
sure does, but only one of them will start. from batch file. On boot up, both start from registry entriees.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Just for testing, you might try adding in some pauses to see which instance isn't starting, or if they are trying to start too fast after the kill.

taskkill /im opera.exe
pause
"C:\Program Files (x86)\Opera\opera.exe"
pause
"C:\Program Files (x86)\Opera2\opera.exe"
pause
exit
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
I needed to run taskkil twice, but if it works for you running it once then that is all you need.

Try

taskkill /im opera.exe
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"


0
 

Author Comment

by:theotherkitty
Comment Utility
this is working on the 2nd try now, on first attempt it says pid is still running. Trying to get a sleep cmd in there before it trys.
0
 

Author Comment

by:theotherkitty
Comment Utility
aw i should have said, heres the error i get. "Nother User is running this copy of opera, you should install opera on individual profiles to allow multiple copys to run independently"

But, on boot up, its not an issue and if i clear that error and run this the 2nd time, its fine.



taskkill /im opera.exe
sleep 10
taskkill /im opera.exe
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit
0
 

Author Comment

by:theotherkitty
Comment Utility
So the problem is for sure, in the killing of the pids. I wounder if i can rename one of the exefiles.
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 334 total points
Comment Utility
SO it appears the single taskkill didn't remove both copies of opera?

Or might this work:

taskkill /im opera.exe
sleep 10
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit
0
 

Author Comment

by:theotherkitty
Comment Utility
taskkill /im opera.exe
sleep 10
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit

tryed it no good, still cant get both pids down at same time. hmmm....is there a way to rename the executable bit on one of the operas so it has a different name?
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Before we go that route, we could try killing the tasks by PID.  With both of them running, see if this shows both instances, with different PIDs.

TASKLIST /FI "IMAGENAME eq OPERA.EXE" /FO CSV
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
While I am working on 32-bit XP and it could be behaving differently, I am definitely having to run taskkill for each running instance of the program.
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
Try this...

http://www.softtreetech.com/24x7/archive/49.htm

KillProcess Opera.exe
sleep 10
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit

0
 

Author Comment

by:theotherkitty
Comment Utility
grrrr

This works.

taskkill /f /im opera.exe
sleep 10
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit

BUT it opens up two pop up windows asking about the forced crash from the /f......
0
 

Author Comment

by:theotherkitty
Comment Utility
xuserx2000:, no go -=/.


this shouldent be that hard or is batch scripting this limited?
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
Using /f to force the programs to stop is untidy.

Try two taskkill lines with a sleep between them.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Well, taskkill /IM will typically remove all instances of any running images matching the specified name, so it could be something interesting about the EXE you are killing.

I thought you said earlier though that a single taskkill did kill both running instances, or did I misunderstand?

We could still try doing 2 taskkill commands, one for each PID, found from the tasklist.  I could craft that...

~bp
0
 
LVL 21

Expert Comment

by:yo_bee
Comment Utility
Can you use a vbs or VB script?
0
 

Author Comment

by:theotherkitty
Comment Utility
billprew:

So far i have had most success with

taskkill /f /im opera.exe
sleep 10
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit



But both instances then take me to the welcome back from a crash screen, IE continue from where you left off etc....if it wasent for these two pop ups id be fine. The other variations  toss a warning up about two instances.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Give this a try:

for /F "skip=1 tokens=2 delims=," %%A in ('tasklist /FI "imagename EQ firefox.exe" /FO CSV') do taskkill /PID %%A
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

Open in new window

0
 

Author Comment

by:theotherkitty
Comment Utility
at the moment i dont see away around these damn popups unless i can rename of the the opera.exes to something like opera2.exe so it sees it as a different program. I suppose i could do something lame like have autohotkey kill the pop ups, arrrrrrrg.!
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
You may still need a sleep after the kills, or between the opera loads...

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
Is there any way to have a batch script tab to the two current windows and  just send a return or enter comand? that would clear these.
0
 

Author Comment

by:theotherkitty
Comment Utility
billprew:, its all about getting the popups to go away, or not show up, once i clear those all is fine but it makes it so automation is useless in this case.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Nothing in the basic batch script capabilities to allow that, it would require an add on tool or VBS, etc.

~bp
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
No...it shouldn't be that hard.  And command line can do anything any program can do because any program can be invoked from command line.

0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
The only other thing I can think of (may take some googling) is if you can find out what opera.exe triggers off of to warn about a recovery.  Likely either a file or INI setting in the opera data files, or a setting in the regisrty.  If you found it then maybe you could "clear" it before restarting.

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
IS there an easier way to do this? I dont know much else but can this be done realy easy in python or perl?
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
What is the result you get using two taskkill lines with a sleep between them without the /f parameter?
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Just to make sure I understand, the problem isn't with the kills, right, those work okay?  But because you do kills, when you restart opera you get the popup warnings.

And it doesn't matter if you do the kill with /F or without it, right, either way you get the popup when restarting?

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
either way, with f or with out u get popups. with out the f its because it thinks theres still two instances running, with the f its the something has failed window.

http://i.imgur.com/fGNhz.jpg

http://i.imgur.com/C5vE4.jpg

thats as far as ive gotten, if i clear either error they repopulate
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
Please go back to my post... ID: 36499980


If you use the /T switch.. it will send a close command instead of trying to "kill" the process.
I wonder if that will prevent the popup with regard to crash.

KillProcess /T 3 Opera.exe
sleep 10
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit

0
 

Author Comment

by:theotherkitty
Comment Utility
sorry, i did try that. It doesnt error out, just opens new tabs in one of the browsers.
0
 

Author Comment

by:theotherkitty
Comment Utility
Is there any way to get it to take control of most current popups and just pass and enter command?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
If you don't use the /f parameter you need to  put in the sleep commands to give Opera time to shutdown in an orderly manner.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Can you confirm from my earlier post, that this does not work?

taskkill /im opera.exe
pause
"C:\Program Files (x86)\Opera\opera.exe"
pause
"C:\Program Files (x86)\Opera2\opera.exe"
pause
exit
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Naturally, you will have to click in to the script window and press a key to continue at each pause, but this is just a test to see what messages / popups you get.

~bp
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
...ok i've been googling...

Please see this link...

http://www.opera.com/support/usingopera/operaini/#windows

operaprefs.ini
  file specs.

There is a RUN parameter...and, according to that....if you can set it with a value of 0 in your script, then Opera will not run as if it has crashed.

Back up the file....
operaprefs.ini > copyofoperaprefs.ini

Edit the copyofoperaprefs.ini to set the Run=0
...then... before you invoke opera.exe

xcopy "C:\Program Files (x86)\Opera\copyofoperaprefs.ini" "C:\Program Files (x86)\Opera\operaprefs.ini" /y

That should overwrite it with the "i didn't crash" ini file.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Might be safer to just change that setting in the existing INI file, rather than restore the INI file each time, just in case there is any other useful info in there.

~bp
0
 
LVL 25

Expert Comment

by:Ron M
Comment Utility
Good point.


I love these kinds of questions.....
0
 

Author Comment

by:theotherkitty
Comment Utility
xuserx2000:, sadly both confs were already set to 0!
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
@theotherkitty

Here's a thought.  Shutdown opera normally through it's GUI.  Take a copy of the prefs file. Then start opera, and kill it with taskkill.  Take another copy of the prefs file, and compare to the prior version.  Perhaps there is some other indicator that a crash occurred.

~bp
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Also, where are you locating the config files, could there be other copies that are in use and you are looking in the wrong folder?

~bp
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Sadly I don't run opera so don't have it installed to be trying these things myself...

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
considering using SKULI or authotkey to by pass the popups, i cant believe how bad batch scriptings functionality is.
0
 

Author Comment

by:theotherkitty
Comment Utility
i'd be fine with even firefox if i knew there was a malware-spyware free plug in for auto refresh.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Don't yell at me, but can I ask what you are ultimately trying to accomplish?  Is this some sort of kiosk implementation or something?  Just wondering what it is that causes you to want to kill 2 running instances of opera just to restart them?

~bp
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
What happens when you run this script?


taskkill /im opera.exe
sleep 3
taskkill /im opera.exe
sleep 6
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"
sleep 5
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Sorry, just seeing your last post, and maybe that's a clue.  Are you essentially looking for a timer driven forced refresh of the two opera sessions to reload new web content periodically?

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
no worries, its for monitoring of different services, think MRTG or Nagios, or like keynote. SO yeah, keiosk mode that will A auto refresh from the application layer, B the browser can be set to refresh like Opera can (right click and do it) and C, remote ability to kill stale browses and reset URLS with out moving to a console. make sense?
0
 

Author Comment

by:theotherkitty
Comment Utility
billprew:
Sorry, just seeing your last post, and maybe that's a clue.  Are you essentially looking for a timer driven forced refresh of the two opera sessions to reload new web content periodically?

~bp

They will likely have a tasks scheduled to do so, but also need to be able to do it remote-ish. But yeah, thats the track im on, and why i have them as services.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
0
 

Author Comment

by:theotherkitty
Comment Utility
yeah, thats why i choose opera, because it will also do that in addition to the app doing it. But browsers hang and this is to prevent hangs and quickly re open and task them.
0
 

Author Comment

by:theotherkitty
Comment Utility
Its pretty much a back up, back up solution, make sense?
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
There are some interesting scripts on the page below, and seem to be related to kiosk mode.  Looks like they are solving similar problems, I see them using a little freeware utility I have used in the past called INIFILE to reset the Run flag.  But there also seem to be a bunch of kiosk command line switches.  Have you researched those at all (I'm not an opera guru) maybe they could help restart opera without the messages, etc?

http://sandbox.planetdaniel.net/wp-content/uploads/Batch-Script-examlples.bat_.txt

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
i'll look into it tomorrow, ive had it for the day -=/ check in tomorrow and see where i am?

Thanks all for the help. grrrrrrrrrrrr
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Sounds like a plan, sorry not more help yet. Post a note back here when you know more, I'll get alerted.

~bp
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
I have installed a second copy of Opera and can confirm that this script worked for me:

taskkill /im opera.exe
sleep 6
start "opera" "C:\Program Files\Opera\opera.exe"
start "opera2" "C:\Program Files\Opera2\opera.exe"
sleep 5

It is interesting that taskkill will shutdown both copies of Opera but it needs to be run twice to shutdown two copies of Firefox.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
FYI, looks like those sample scripts I stumbled across were linked from this post:

http://sandbox.planetdaniel.net/2009/09/setup-opera-kiosk-mode/

~bp
0
 

Author Comment

by:theotherkitty
Comment Utility
vk3kjc,

odd, i still get the same error with what you were running, one of the two i showed in the SS above. The task is already running........i'm stumped. I'm on windows 7 64bit. Opera version 11.51. I'm so close to being done with this UUUUUUUUUUG!!!!!!

taskkill /im opera.exe
sleep 6
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

exit
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
I have just rerun this on the nearest thing that I have to Windows 7 - Server 2008R2 (64-bit)

The following script worked there.

taskkill /im opera.exe
sleep 6
start "opera" "C:\Program Files (x86)\Opera\opera.exe"
start "opera2" "C:\Program Files (x86)\Opera2\opera.exe"

What I did find though was that sleep.exe is not a standard command and was something that I had added to my PC. Until I added it to the server I was occasionally getting an error message when Opera restarted. By adding the sleep.exe file to the server the script worked every time.
0
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 334 total points
Comment Utility
Yes, sleep is not a standard batch command.  So on the original server it should have been throwing an error when it hit that line, were you not seeing that before?

Here are a few alternate sleep techniques, including the builtin ping command usage as I mentioned earlier.

http://www.robvanderwoude.com/bht.php#Delay

~bp
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
I think my copy of sleep.exe might have come from one of the Microsoft resource kits. It definitely comes from Microsoft.
0
 

Author Comment

by:theotherkitty
Comment Utility
nice, PING 1.1.1.1 -n 10 -w 1000 >NUL may just work. will try when get home.
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
Perhaps pinging 127.0.0.1 (localhost) would be better.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
No, you want to ping an invalid address so that the -w parm kicks in giving an easy and predictable timeout.

~bp
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
But 1.1.1.1 is not invalid.
0
 
LVL 3

Assisted Solution

by:vk3kjc
vk3kjc earned 166 total points
Comment Utility
It is probably better to get sleep.exe from the Server 2003 Resource Kit at http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657
0
 
LVL 3

Expert Comment

by:vk3kjc
Comment Utility
When you download the Resource Kit you do not have to install it.

You can extract the files using 7-zip (http://www.7-zip.org/) in Windows Explorer. Right click on the rktools.exe file and using 7-zip extract to "rktools\"

In the rktools directory right click on rktools.msi and using 7-zip extract here

In the same directory find Cabs.winrk.cab and richt click and using 7-zip extract here

You should find sleep.exe is now in the same directory.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now