Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Limit instances of a 3rd Party Application

Posted on 2014-03-13
4
Medium Priority
?
359 Views
Last Modified: 2014-09-21
need a method to limit how many instances of a 3rd party program will run in a windows xp system.

I have an application and the way that it's started it can be hidden and thus opening a new instance each time as another program is full screen by default.

I need to limit this 3rd part y app to only instance of this exe at a time.

I also need a way to disable the minimize button of the 3rd party application also.
0
Comment
Question by:ATL74
  • 2
4 Comments
 
LVL 80

Expert Comment

by:arnold
ID: 39928050
The limit has to be an option enforceable by the application.

Alternatively, you would need to use a powershell cmd-let that check for the number of running processes. then terminate all but one.  IMHO, you may run into an issue where you terminate the wrong ones.

What process or how does this application start?

http://technet.microsoft.com/en-us/library/dd347650.aspx
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 39931231
There's a solution using AutoIt (a VB like script language, free for private and commercial use).
Get AutoIt and the customized SciTE download and install them on any machine; from the SciTE download page, get the new version of AutoIt3Wrapper.exe as well and place it in C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper after the installation: http://www.autoitscript.com/site/autoit/downloads/
Then open SciTE, paste the script below into a new document, save it with the name of your exe file and the extension .au3. In SciTE, hit F7 to compile the script into an exe file.
On the machines where the program is installed, rename whatever.exe to whatever.org.exe, and put the new exe you just compiled into the same folder.
The script will check if the program is already running and display an error if it is.
If it isn't running yet, it will start the .org.exe file and disable the Minimize function (the button in the title bar will still be there, but not functional anymore).
#cs
StartNoMinimize.au3
Script for AutoIT (http://www.autoitscript.com/)
Starts a program in the same folder as this script with the same name and the extension .org.exe, and removes "Minimize" from the system menu;
makes sure only one instance is running.
Tested and compiled with AutoIT v3.10.0.2; use SciTE or Aut2exe.exe to compile this script into an executable.
#ce
AutoItSetOption("TrayIconHide", 1)

Global Const $SC_MINIMIZE = 0xF020
Global Const $MF_BYCOMMAND = 0x0

Func _GetHwndFromPID($PID)
; AutoIT code for _GetHwndFromPID by BrettF (http://www.autoitscript.com/forum/index.php?showuser=16404),
; posted at http://www.autoitscript.com/forum/index.php?showtopic=85337&st=15&start=15
Local $hWnd
Local $stPID
Local $winlist2
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc ;==>_GetHwndFromPID

Func _RemoveMinimize($hWnd)
Local $ret
Local $hSystemMenu
	$ret = DllCall("user32.dll", "int_ptr", "GetSystemMenu", "hwnd", $hWnd, "int", 0)
	$hSystemMenu = $ret[0]
	DllCall("user32.dll", "int", "DeleteMenu", "hwnd", $hSystemMenu, "uint", $SC_MINIMIZE, "uint", $MF_BYCOMMAND)
EndFunc

Func _Main()
Local $intPid
Local $hWnd
Local $strRunProgram
	$arrProgramName = StringSplit(@ScriptName, ".")
	$strProgramFullPath = StringReplace(@ScriptFullPath, ".exe", ".org.exe")
	$strProcessName = StringReplace(@ScriptName, ".exe", ".org.exe")
	If (ProcessExists($strProcessName)) Then
		MsgBox(0 + 48, "Error", "Program already running: " & @CRLF & @ScriptName)
		Exit(1)
	EndIf
	$strRunProgram = '"' & $strProgramFullPath & '" ' & $CmdLineRaw
	$intPid = Run($strRunProgram)
	If ($intPid = 0) Then
		MsgBox(0 + 48, "Error", "Program not found: " & @CRLF & $strRunProgram)
		Exit(1)
	Else
		$hWnd = _GetHwndFromPID($intPid)
		_RemoveMinimize($hWnd)
	EndIf
EndFunc

; ****************************************************************************************************
_Main()
; ****************************************************************************************************

Open in new window

0
 

Author Comment

by:ATL74
ID: 39936886
Seems like the AutoIt website is no longer managed?
0
 
LVL 85

Expert Comment

by:oBdA
ID: 39937579
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

782 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