Solved

Limit instances of a 3rd Party Application

Posted on 2014-03-13
4
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 78

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 84

Accepted Solution

by:
oBdA earned 500 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 84

Expert Comment

by:oBdA
ID: 39937579
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

710 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