Solved

Limit instances of a 3rd Party Application

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sccm importing drivers 4 28
Thoughts on PC Doctor 11 48
Increment column based of a FK 8 23
Password manager for small company 3 14
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

777 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