In the bat/cmd world, here is a sanitized version of what I've used which seems to work with both XP and Windows 7.
-----------------
echo off
setlocal
set imgname=whatever.exe
set exeName=whatever.exe
set found=
set user=
for /f "tokens=*" %%a in ('tasklist /v ^| findstr /i "%imgName%"') do set
found=Y
for /f "tokens=8,*" %%b in ('tasklist /v ^| findstr /i "%imgName%"') do set
user=%%b
if "%found%"=="Y" cls&echo Sorry, %user% is already running this
application.&pause&goto :EOF
start C:\Path\To\%exename%
-----------------
On Tue, Jun 1, 2010 at 1:39 PM, tony patton <[email protected]
> wrote:
> Try this, change strProcName and strProcPath in lines 6 & 7
> Also change the message in line 17 to suit.
>
> Some applications, such as UltraVNC run 2 processes, so for something like
> that, change the 0 in line 16
>
> This has only been tested on WinXP SP3, so YMMV on later OSs.
> Quick and nasty, but gets round the issue of the users being able to delete
> the lock file.
>
> I use PrimalScript for all my scripting and the handiest thing I use it for
> is to compile scripts in exe's so that the code can't be changed to increase
> the number, but I'm sure google would throw up some alternatives.
>
> --8<------------------------------------------------------------
> Option Explicit
>
> Dim objWMIService, colProcesses, objShell
> Dim strProcName, strProcPath
>
> strProcName = "notepad.exe"
> strProcPath = "c:\windows\system32\"
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
>
> Set colProcesses = objWMIService.ExecQuery _
> ("SELECT * FROM Win32_Process WHERE Name = " & _
> "'" & strProcName & "'")
>
> If colProcesses.Count > 0 Then
> MsgBox "UltraVNC is already running." & vbCrLf & vbCrLf & "Only 1
> instance is permitted at a time.", vbOK, "Process already running."
> Else
> Set objShell = CreateObject("WScript.Shell")
> objShell.Run strProcPath & strProcName
> Set objShell = nothing
> End If
> --8<------------------------------------------------------------
>
> Regards
>
> Tony Patton
> Desktop Operations Cavan
> Ext 8078
> Direct Dial 049 435 2878
> email: [email protected]
>
>
>
> From: "Joseph L. Casale" <[email protected]>
> To: "NT System Admin Issues" <[email protected]
> >
> Date: 01/06/2010 18:18
> Subject: RE: Limit the amount of times an application can be
> opened?
> ------------------------------
>
>
>
> Only problem with that is permissions.
> If “I” am launching the app, I am creating the lock file, which isn’t
> secure. If someone is clever, or even in an accidental situation this can be
> bypassed…
>
> *From:* John Aldrich
> [mailto:[email protected]<[email protected]>]
> *
> Sent:* Tuesday, June 01, 2010 9:24 AM*
> To:* NT System Admin Issues*
> Subject:* RE: Limit the amount of times an application can be opened?
>
> Use a batchfile to create a “.lock” file and check for the existence of
> that file and if it exists, have the batch file exit.
>
> [image: John-Aldrich][image: Tile-Tools]
>
> *From:* Craig Gauss
> [mailto:[email protected]<[email protected]>]
> *
> Sent:* Tuesday, June 01, 2010 11:10 AM*
> To:* NT System Admin Issues*
> Subject:* Limit the amount of times an application can be opened?
>
> We have one application that is absolute resource hog. Unfortunately the
> users will open it over and over again, usually bringing the system to a
> crawl. It has been very difficult to train them to only open it once.
> Anyone have any ideas on how we could limit the amount of times it is
> opened?
>
>
> Craig Gauss, Technical Supervisor/Security Officer
> Riverview Hospital Association
>
>
>
>
>
>
>
>
>
>
> This e-mail is intended only for the addressee named above. The contents
> should not be copied nor disclosed to any other person. Any views or opinions
> expressed are solely those of the sender and do not necessarily represent
> those of QUINN-Insurance Limited (Under Administration), unless otherwise
> specifically stated . As internet communications are not secure,
> QUINN-Insurance Limited (Under Administration) is not responsible for the
> contents of this message nor
> responsible for any change made to this message after it was sent by the
> original sender. Although virus scanning is used on all inbound and outbound
> e-mail, we advise you to carry out your own virus check before opening any
> attachment. We cannot accept liability for any damage sustained as a result
> of any software viruses.
>
> ====================================================================
>
> QUINN-Insurance Limited (Under Administration) is regulated by the Financial
> Regulator and
> regulated by the Financial Services Authority for the conduct of UK
> business.
>
> ====================================================================
>
> QUINN-Insurance Limited (Under Administration) is registered in Ireland,
> registration number
> 240768 and is a private company limited by shares.
> Its head office is at Dublin Road, Cavan, Co. Cavan.
>
>
>
>
> This message is for the designated recipient only and may contain privileged,
> proprietary, or otherwise private information. If you have received it in
> error, please notify the sender immediately and delete the original. Any
> other use of the email by you is prohibited.
>
>
>
>
>
>
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~<<image/jpeg>>
<<image/jpeg>>
