Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

NT4 Cant I stop / restict a user closing a program?

Posted on 2009-06-29
3
Medium Priority
?
379 Views
Last Modified: 2013-12-28
Hi there,

I have an app on an NT4 box, if a user clicks the X top right corner to close, and not using the correct exit button in the app, the database corrupts.

Any Ideas?

Cheers
Anthony
0
Comment
Question by:antgodber
[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
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 24735756
You can compile the following script as "StartNoClose" using AutoIT (http://www.autoitscript.com/autoit3/downloads.shtml).
Then run your application through StartNoClose:
StartNoClose.exe "C:\Programe Files\Acme\acme.exe"
Note that you'll need the 3.2.12.1 version for this to work on NT4.
#cs
StartNoClose.au3
Skript for AutoIT (http://www.autoitscript.com/)
Starts the program passed as argument in the command line, and removes "Close" from the system menu;
this will disable the windows's "X" button as well, but it will not disable Alt-F4.
Posted at Experts Exchange by oBdA (http://www.experts-exchange.com/Q_24529579.html?cid=295)
 
Tested and compiled with AutoIT v3.2.12.1; use Aut2exe.exe to compile this script into an executable.
#ce
AutoItSetOption("TrayIconHide", 1)
 
Global Const $SC_CLOSE = 0xF060
Global Const $MF_BYCOMMAND = 0x0
 
Func _ParseCommandLine(ByRef $strRunProgram)
Local $i
	If $CmdLine[0] = 0 Then
		$Syntax = @ScriptName & @CRLF & _
			"Starts the program passed as argument and disables the system 'Close' menu." & @CRLF & _
			@CRLF & _
			"Syntax: " & _
			@ScriptName & " <Program>"
		MsgBox(0 + 32, @ScriptName & " Syntax", $Syntax)
		Exit(0)
	Else
		$strRunProgram = $CmdLineRaw
	EndIf
EndFunc
 
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 _RemoveClose($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_CLOSE, "uint", $MF_BYCOMMAND)
EndFunc
 
Func _Main()
Local $intPid
Local $hWnd
Local $strRunProgram
	_ParseCommandLine($strRunProgram)
;	When doing test runs out of SciTE, set $strRunProgram to the program you want to start; $CmdLineRaw will contain arguments 
;	from the wrapper in addition to the arguments specified in the View menu.
;	$strRunProgram = "calc.exe"
	$intPid = Run($strRunProgram)
	If ($intPid = 0) Then
		MsgBox(0 + 48, "Error", "Program not found: " & @CRLF & $strRunProgram)
		Exit(1)
	Else
		$hWnd = _GetHwndFromPID($intPid)
		_RemoveClose($hWnd)
	EndIf
EndFunc
 
; ****************************************************************************************************
_Main()
; ****************************************************************************************************

Open in new window

0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 34877590
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

604 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