Solved

Limit instances of a 3rd Party Application

Posted on 2014-03-13
4
313 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 77

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 83

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 83

Expert Comment

by:oBdA
ID: 39937579
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
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…

943 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now