Solved

simple batch file to kill broswer and restart again.

Posted on 2011-09-07
73
1,717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 26
  • 24
  • 14
  • +2
73 Comments
 
LVL 3

Expert Comment

by:vk3kjc
ID: 36499845
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
ID: 36499852
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 54

Expert Comment

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

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

~bp
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

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

Expert Comment

by:Bill Prew
ID: 36499914
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
ID: 36499928
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
ID: 36499939
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
ID: 36499948
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
ID: 36499954
So the problem is for sure, in the killing of the pids. I wounder if i can rename one of the exefiles.
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 334 total points
ID: 36499956
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
ID: 36499969
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 54

Expert Comment

by:Bill Prew
ID: 36499975
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
ID: 36499979
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 Malmstead
ID: 36499980
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
ID: 36499985
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
ID: 36499991
xuserx2000:, no go -=/.


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

Expert Comment

by:vk3kjc
ID: 36499999
Using /f to force the programs to stop is untidy.

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

Expert Comment

by:Bill Prew
ID: 36500005
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 23

Expert Comment

by:yo_bee
ID: 36500007
Can you use a vbs or VB script?
0
 

Author Comment

by:theotherkitty
ID: 36500018
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 54

Expert Comment

by:Bill Prew
ID: 36500027
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
ID: 36500034
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 54

Expert Comment

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

~bp
0
 

Author Comment

by:theotherkitty
ID: 36500038
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
ID: 36500049
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 54

Expert Comment

by:Bill Prew
ID: 36500050
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 Malmstead
ID: 36500055
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 54

Expert Comment

by:Bill Prew
ID: 36500057
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
ID: 36500060
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
ID: 36500066
What is the result you get using two taskkill lines with a sleep between them without the /f parameter?
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36500071
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
ID: 36500093
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 Malmstead
ID: 36500097
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
ID: 36500113
sorry, i did try that. It doesnt error out, just opens new tabs in one of the browsers.
0
 

Author Comment

by:theotherkitty
ID: 36500124
Is there any way to get it to take control of most current popups and just pass and enter command?
0
 
LVL 3

Expert Comment

by:vk3kjc
ID: 36500136
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 54

Expert Comment

by:Bill Prew
ID: 36500155
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 54

Expert Comment

by:Bill Prew
ID: 36500157
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 Malmstead
ID: 36500176
...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 54

Expert Comment

by:Bill Prew
ID: 36500206
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 Malmstead
ID: 36500214
Good point.


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

Author Comment

by:theotherkitty
ID: 36500216
xuserx2000:, sadly both confs were already set to 0!
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36500227
@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 54

Expert Comment

by:Bill Prew
ID: 36500231
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 54

Expert Comment

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

~bp
0
 

Author Comment

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

Author Comment

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

Expert Comment

by:Bill Prew
ID: 36500257
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
ID: 36500262
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 54

Expert Comment

by:Bill Prew
ID: 36500263
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
ID: 36500265
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
ID: 36500270
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 54

Expert Comment

by:Bill Prew
ID: 36500272
0
 

Author Comment

by:theotherkitty
ID: 36500276
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
ID: 36500278
Its pretty much a back up, back up solution, make sense?
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36500292
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
ID: 36500297
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 54

Expert Comment

by:Bill Prew
ID: 36500304
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
ID: 36500312
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 54

Expert Comment

by:Bill Prew
ID: 36500317
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
ID: 36500587
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
ID: 36500756
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 54

Assisted Solution

by:Bill Prew
Bill Prew earned 334 total points
ID: 36502313
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
ID: 36502792
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
ID: 36506717
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
ID: 36507613
Perhaps pinging 127.0.0.1 (localhost) would be better.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36507624
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
ID: 36507683
But 1.1.1.1 is not invalid.
0
 
LVL 3

Assisted Solution

by:vk3kjc
vk3kjc earned 166 total points
ID: 36507717
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
ID: 36507784
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EA Azure explanation please 3 77
Need help Creating a Powershell script 8 98
powershell switch statement 7 48
CSV file copy field 1 to field 2 2 63
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 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