How to get all the processes with a specified name in NSIS installer - process

I want to kill RunDll32 process which is started from my install directory.
So if I use
${nsProcess::KillProcess} "rundll32.exe" $R0
It kills all the rundll32 processes on the system which I don't want to happen.
IMO, I have two options to fix this,
1. Identify interested process from commandline parameters
2. Identify from process startup directory (current directory).
I see there are few plugins to find the process but what they do is they just return found or not found. Instead I want IDs of the processes or list of these processes and then I'll check each process for command line or startup directory information and will act on the the required process.
BTW, I checked following plugins
http://nsis.sourceforge.net/FindProcDLL_plug-in
http://nsis.sourceforge.net/Processes_plug-in
http://forums.winamp.com/showthread.php?t=230998
Thanks

I fixed by using wmic query as follows:
StrCpy $1 "wmic Path win32_process where $\"name like 'Rundll32.exe' and CommandLine like '%$0%'$\" Call Terminate"
nsExec::Exec $1

If you control the .dll then the best option is to provide some sort of way to shutdown the app in a clean way. Perhaps you could find a window based on its class name and send it a WM_CLOSE message.
If you just need to shutdown the application during upgrade/uninstall then the LockedList plug-in is much better than just killing processes...

Related

How to know locked file process VB6

Facing one sporadic issue in legacy application developed in VB6. Application produces intermediate file and then tries to delete it once required output is produced. Application does delete files properly but sometimes, I am getting error stating "Path/File access error". I have tried adding delay to delete but this issue is not getting resolved.
I wanted to search if there is any possibility to check process name which has acquired lock in VB6. I tried searching but no luck so far.
Could anyone please tell me any way I can get process name which has locked file and causing to not delete?
Please note that this issue happens infrequently.
Windows does not keep a global database of who has what file open. This is for speed reasons. Although it does keep a list of other computers with files open on this computer.
For debugging purposes you can enable a global database. Remember to un-enable it.
So to enable
Openfiles /local on
then reboot.
To query
Openfiles /query /v
See
Openfiles /?
Openfiles /local /?
Openfiles /query /?

SSIS Execute Process Task Can't Find executable

I am using the 7zip standalone .exe to unzip a file. I am using the Execute Process task for this. I have tested this over and over again on multiple machines and I know it works (at least in debug mode/visual studio). I have uploaded this package the server. I have created a job that calls said package from the Package Store. The package is not able to find the .exe no matter where I put it.
My first thought was to put the .exe on the C:\ drive, which failed. I have also failed in my attempts to place the .exe on a network location that the account the package is running under has full control over.
Basically, has anybody else had issues getting the Execute Process Task to find an executable when the package is uploaded to the server?
The error message is
Can't find 7za.exe in directory C:\7zip
I'll risk a downvote for being wrong, but I believe you have a permission issue.
You say it runs fine on other servers from BIDS, try it without BIDS. Call it from a command-line on a box that it works on.
dtexec.exe /file C:\HereComesTheUnzipper.dtsx
If that works, then repeat the step on the troublesome server. RDC into the box and try again
dtexec.exe /ser localhost /sq HereComesTheUnzipper
If that still works, then you are looking at an issue with the job. What account is the SQL Agent service running as? Is the SSIS job step running as a particular set of credentials? If so, is it a SQL Server login (which wouldn't map to anything on the physical box)? Regardless of what your answer is, the resolution will be to ensure the account has access to
7z.exe
whatever scratch area 7zip may use while unpacking files (I assume %temp%)
the output folder (C:\bin\7z.exe -e e:\data\MyThing.7z)

Detect file in use by other process

On windows and such I used to use a trick to find out of a file is currently in use (written specifically).
I use to open the file for writing and if it failed most likey another process is busy accessing it.
Sadly these trick (using C OPEN with exclusive lock for writing) doesn't work on my Mac. While my curl in a terminal is still writing my -fileBusy() check fails.
fcnt call on the fd with F_GETLK doesn't reveal any locking as well.
Is there any chance for me to detect if a file is in use by another process?
Ps> listening for fsevents can't be done because my app launches after the is created by the other app / process.
Apple confirmed via email that the solution described in the link below is a valid one and not considered a private API.
More information:
http://lists.apple.com/archives/cocoa-dev/2010/May/msg01455.html
You could try running the following shell command using NSTask:
lsof -Fc path/to/thefile
That will give you the process ID and name of any process(es) that have thefile open.

Multiple Job (j3)

I am trying to run a GNU make file with multiple jobs.
When I try executing ' make.exe -r -j3', the receive the following to errors:
make.exe: Do not specify -j or --jobs if sh.exe is not available.
make.exe: Resetting make for single job mode.
Do I have to add ' $(SH) -c' somewhere in the makefile? If so, where?
The error message suggests that make cannot find sh.exe. The file names indicate you are probably on CygWin. I would investigate setting the PATH to include the location of sh.exe, or defining the value of SHELL to the name (or, even, full path) of your shell.
Are you running this on Windows (more specifically, in the "windows" shell?). If you are, you might want to read this:
http://www.gnu.org/software/make/manual/make.html#Parallel
more specifically:
On MS-DOS, the ā€˜-jā€™ option has no effect, since that system doesn't support multi-processing.
Once again, assuming you're running on windows, you should get MinGW or CygWin

Powershell - Check if file is in use

Is there a Powershell command to check if a file is in use by another user? If not, what would it take to write a script that can?
You can never tell if a file is currently being used only that it was recently being used. The reason why is that the moment the script returns the file could be closed by whatever program was previously using it. Writing scripts like this will only lead to flaky behavior.
A much better approach is to just do whatever the script was going to do if the file wasn't in use and catch the exceptions that result from a use conflict. The end result will be a much simpler and more reliable program.
There isn't a built-in command that I'm aware of however there are several tools you can use for this:
net file
From SysInternals on Technet (psfile and handle):
psfile.exe # lists and allows you to close remotely opened files
handle.exe | select-string ': File'
I find that using the SysInternals "ListDlls.exe" is pretty easy and convenient:
c:\SysInternals\Listdlls.exe -d AssemblyInUse.dll
ListDLLs v3.1 - List loaded DLLs
Copyright (C) 1997-2011 Mark Russinovich
Sysinternals - www.sysinternals.com
----------------------------------------------------------------------------
powershell.exe pid: 7296
Command line: "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe"
I hope that helps!