What is wrong with the code below, that is intended to only report something is done if it returns cleanly:
echo Other operations here & (echo Trying to launching Firefox & "%ProgramFiles(x64)%"\Mozilla\Firefox\Firefox.exe && echo Firefox has closed successfully) & echo More operations that should be done regardless here
I believe your syntax is correct, but your expectations are wrong.
You are launching a Windowed application - your command will not wait for Firefox to close before it carries on. Your code is probably properly reporting that Firefox was started. Only if Firefox fails to start (perhaps it doesn't exist on the machine), only then will your conditional code be bypassed.
Normally, if you want to launch a Windowed application and wait for it to finish (close) before continuing, then you would use START /WAIT.
echo previous command & (start /wait "" yourApp.exe && echo successful closure) & echo additional commmands
However, I'm not sure that will work with a browser like Firefox. Many browsers consist of multiple executables. The launching executable may launch auxiliary procsses and then shut down. Your command would happily report that the launching exe returned with success, even though the browser would still be running. Again, I'm not sure if Firefox behaves like this. But if it does, then the problem becomes much more difficult. You would have to run a process that polls to see if Firefox is still active.
Sorry guys, this syntax works, there was other issues with the surrounding code that I didn't realise. Don't suppose anyone knows of a better way to debug DOS "scripting", it's almost as bad as VBS error messages!
Related
When running an autoinstaller for Selenium and the proper driver version for chrome, I encountered an error that upon replacing the old driver and running a test launch of the browser, the program would get stuck and force excel to crash and reopen. The cause of the error was Smartscreen blocking the launch of the browser driver from the Selenium Folder in the background with no way to tell the operation it is safe.
Errors out in somewhere here after the print line. I suspect its either the Set or .get line however when I manually opened the driver and told the computer it was fine to run, the problem went away and Was unable to recreate it. This installer needs to be ran on any number of different computers and I would like to know if either A, there is a way to suspend the launch if it takes "X" amount of time to run or B, figure out a way to avoid having it happen all together.
Notes: These are company laptops so other programs, disabling Smartscreen, or other elevated privileges are more than likely disabled. Ive been lucky to get this far with installing Selenium
If x < 3 Then
Debug.Print "Chrome Driver Test, try " & x
On Error GoTo InstallOverride
Else
Call FixChromeDriver
On Error GoTo ErrorHandler
End If
Set driverTest = CreateObject("Selenium.ChromeDriver")
With driverTest
.AddArgument "--headless"
.Get "https://www.google.com"
.Quit
End With
Set driverTest = Nothing
Ok so I'm trying to end Comodo (free firewall service) so that I can install NVidia driver updates, and since I'm super lazy I want this all to be automatic whenever NVidia tries to update. After I want to reopen Comodo.
However I'm stuck on the first step since I have no idea on how to properly end Comodo, when I try taskkill it says:
ERROR: The process "cis.exe" with PID 6204 could not be terminated.
Reason: Element not found.
I'm new to batch and have no idea what this error message means since I can clearly see that "cis.exe" (which is Comodo) is running in the background at least and I can close it from the icon tray if I wanted to, and it spits out the same message when I try using "CisTray.exe".
Also any advice on where I should go for the next few parts would be greatly appreciated, thinking on using task scheduler to open the batch file when some kind of log or something is made by NVidia.
How do i do this?
i've tried all i can think of.
Browsing for my .exe file i want to run.
run a bat file
writing forcedos.exe in program textbox and path to my bat file in command line parameters textbox
Why cant it just work with an normal exe?
and i know it should run a program because it can restart the service correctly.
EDIT
Application: test.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Exception
This is my latest try to make it work.
the script has the code
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("iexplore")
Set objShell = Nothing
Now the script opens internet explorer if i run the cmd command
wscript.exe "C:\asfh.vbs"
The "run a program" recovery option for when a service crashes runs the specified executable in the same way as the service, i.e., it runs in session 0 (and so is affected by session 0 isolation, see also related questions) and it runs with the same security context as the service.
This means that it can't interact directly with the user (you can display a GUI, but nobody will see it) but it also restricts what the executable or script can do. For example, some shell API functions will not work properly unless the user account has been interactively logged in at some point. In the example script you posted, the script itself is probably running, but is unable to launch Internet Explorer because IE is only designed to run in an interactive session.
Provided you restrict yourself to basic functionality, it should all work as expected. (There is no master list that I know of describing what functionality is safe to use in a service context, but it is usually easy to guess. You can resort to trial and error if necessary!)
Also note that as far as I know forcedos.exe is no longer present in modern versions of Windows. If you want to run a batch file, you can specify cmd.exe as the application and /c myscript.bat as the command line parameters.
in advance, thank you for any insight you may be able to offer. i know that there is a very similar post to my scenario and i have tried all variations of the answer but cannot get it to work for me as per the initial or edited instructions. in order to circumvent the uac nags, i am running windows 7 (64 bit) and trying to run a batch file to simply 'route print cmd /k' via task scheduler and desktop shortcut but i want the DOS window to remain open and allow me to continue typing into it. when i execute the actual file, it runs as desired, however when it runs via task scheduler, the dos window closes immediately. to no avail, i have tried multiple things such as changing the 'program/script' field from C:\location\batchfilename.bat to just cmd and inputting the various arguments including cmd /k or /k or /k C:\location\batchfilename.bat to the task's 'add arguments' field and/or the batch script itself. although i do not want pause as it would close the window after pressing any key, i have also tried it in the script itself and the arguments field but it too does not keep the dos window open when running as scheduled task. nothing seems to work - your help is greatly appreciated!
I have a play application on a Windows 7 machine which I want to start via double click on a batch file.
This batch file starts a service. Calls the play application to run in production mode, waits for 5 seconds and open a browser with a specified url.
Therefore I used the following script:
call net start service1
CALL "D:\play-1.2.5\play.bat" start --%%%%prod -Dprecompiled=true
TIMEOUT /T 4
call "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" localhost:9000
exit
Now when I start the batch file the window opens and all commands are executed. Sadly Play is still writing his output to cmd and the window is not disappearing. If I close the window manually play is stop executing.
If I run play with "play start" from cmd, play is starting in the background and everything is fine. Play still runs even if I close the window.
I want to have exactly this behaviour when I start the application with my batch file.
Thanks
If you were using a linux-like environment, I' d recommend you to use 'nohup' command and a '&' sign in the end. However, as far as I know there is no direct equivalent of beautiful 'nohup' command on Windows, unfortunately. So, what I can think of is, you can create a tiny win api application that utilizes CreateProcess command and give it the required parameter to hide command line window as soon as the process is created. There are also other process creation functions such as WinExec that you can use to hide command line.
I don't know what Play is so I can only take a guess :) but try using the batch without the call's as I don't think they are necessary, and you never know, might fix the issue.
1) You see Play's output because ot redirect only system.out but write system.err to the same console.
2) I also have this problem and looking for a solution. As a workaround you could try to use some Java Wrapper and install your Play! application as a Windows Service.
3) Play! app could be started via Ant task. I haven't tried this yet.