Close previously opened application - photoshop-script

Using Javascript, I do this:
var file = File('C:/myapplication.exe');
file.execute();
It opens the application. After I open it, I need it closed. I use this:
file.close();
No luck. What am I doing wrong? I use this in a Photoshop script (jsx).

Not sure which versions are supported but you can
app.system("Taskkill /F /IM myapplication.exe");
This is of course windows only.
If this does not work you can write Taskkill /F /IM myapplication.exe to a bat file and execute that file.
var bat = new File("C:/killmyapp.bat");
bat.open("w");
bat.writeln("Taskkill /F /IM myapplication.exe");
bat.close();
bat.execute();
This is basically same as terminating application from windows task manager.

Related

Closing only a window of an active application via .bat file

I am looking for a solution to close a window and leave the .exe running.
The .bat file:
#echo off
TITLE Bejelentkezes ujrainditasa
TASKKILL /F /im eszig-eid.exe
TASKKILL /F /im eszig-cmu.exe
start /d "C:\Program Files (x86)\ESZEMELYI\eSzemelyi_Kliens" eszig-cmu.exe
So, the eszig-cmu.exe must stay running, but when the code executes it opens the window of the program, and I don't need it. I want to close only the window of the application, like how I mentioned and leave the .exe (the active program) running! I also apply the solution in PowerShell! I only curious about the solution!

Batch File as Service - TaskKill not killing task

If I run my batch script as normal from cmd it seems to work fine.
What I'm trying to do is setup my script as a service using nssm. That seems to work as expected except for Taskkill - this isn't killing the desired application for some reason.
Anybody have some suggestions?
This is my taskkill code in my bat file:
TASKKILL /f /t /im "application.exe"

Closing a window which pops up while running batch file

There is this application build process that I am trying to automate. For this i wrote a java file, which runs every 24 hours.
A batch file is called from here that runs the application build whenever it is called.
I've run into a small problem, when the build fails due to incomplete or invalid files, a window pops up which tells me to look at the logs.
Since I haven't written the build files, I'm not really sure where this gets created from. I wanted to know if I can close this window while the process runs from the bat file.
It may be possible using taskkill, but you'd have to devise a filter that would ideally only match the process displaying the window and never match any other process. Something like:
taskkill /im program.exe
or maybe:
taskkill /fi "windowtitle eq title*"
You might also want to include the /f flag for forceful termination.
You'd also have to try and make sure that the taskkill command doesn't run too quickly and precede the creation of the popup window. You could try to query for the existence of such a process/window; your best bet here is probably wmic. Maybe:
#echo off
setlocal enabledelayedexpansion
set title=Notepad
set pid=
for /f %%i in ('wmic process where "caption like \"%%!title!%%\"" get processid^| findstr /r [0-9]') do #set pid=%%i
if "!pid!" neq "" taskkill /f /pid !pid!
There's no guarantee this will always work, but it's probably the best you can do.

Executing a command when closing Batch file

I have a batch file playing a sound in the background while it runs, using the method at Batch file executing a sound silently however, when I exit the batch file, the music will continue to play.
Id there any way to run a command while a batch file is closing, so that the sound file will stop playing?
I've tried an example I found called onexit:
onexit taskkill /im wmplayer.exe
But it doesn't work.
Just :
taskkill /f /im wmplayer.exe
Should work.
First idea i had is another batch:
#ECHO OFF
START "" /W <YourBatchhere>
TASKKILL /im "wmplayer.exe"
should do the job :)
The /W will wait at that point, still YourBatchhere has ended.
Regardless of success or error.

How to combine a batch file and a vbs script into one .exe

I'd like to be able to combine a vbs script I made for a batch file into one .exe for an end user and so I can assign an icon to it. I've been trying to look for a way on the web but can't find anything that's useful.
I want to combine this vbs script:
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c CheckIn.bat"
oShell.Run strArgs, 0, false
With this batch file:
#echo off
REM A message to ask the user to save their Outlook emails they have open
mshta javascript:alert("Please be sure to save any emails that you need in Outlook. Click OK to continue.");close();
REM This will stop DM, Email Marker, Email Filer, Interceptor, Papihost, and Outlook.
taskkill /IM DM.exe /F
taskkill /IM DMMarkEmail.exe /F
taskkill /IM EmailAutoBulkFiling.exe /F
taskkill /IM Interceptor.exe /F
taskkill /IM OUTLOOK.EXE /F
taskkill /IM PAPIHost.exe /F
REM This will delete the DM cache in Appdata under the current user
RMDIR /s /q "%userprofile%\Appdata\Roaming\OpenText\DM\Cache"
REM This will start all of the programs that were closed
REM DM and Interceptor restart when Outlook starts back up
START OUTLOOK.EXE
REM Commenting the Marker and Filer since some users don't want it
REM START DMMarkemail.exe
REM START Email AutoBulkFiling.exe
REM START "C:\Program Files\Open Text\DM Extensions\DM.exe"
REM START "C:\Program Files\Open Text\DM Extensions\Interceptor.exe"
REM START PAPIHost.exe
#echo off
I'm not sure if there's a simple way that's just eluding me at the moment, thanks in advance for your feedback.
If you send the taskkill without /f it's like a normal close. The user should be prompted to save emails. You can send it with /f later to force a close.
One way to achieve what you want is to put the batch commands into vbs oShell.Run commands. There is no need to put commands into variables before executing them and it makes your code confusing.
EG
oShell.Run "taskkill /IM DM.exe /F", 0, false
Then see this post on how to convert to an exe
How can I convert a VBScript to an executable (EXE) file?
PS: You should be able to run your script directly as a vb.net program rather than running it in the script control. Just put the vb.net headers and footers in.

Resources