Solved

Limit instances of a 3rd Party Application

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

20 Experts available now in Live!

Get 1:1 Help Now