• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
dunkie12

Disable the Close Program "X" button on a command prompt

11 posts in this topic

Hi all,

As part of the startup of our SOE PC's for the first time, I have automatic login enabled for one single login. When the machine logs in, it runs a command script that refreshes the domain group policy, adds an account into the local administrator group and imports a registry key that is cleared by sysprep. The script then uses the sleep tool to wait 60 seconds before rebooting the machine.

I'm wanting to disable the close program button for this script so our users cannot kill the script and gain access to windows. Does anyone know of a way to disable the Close Program or "X" button on a command prompt window please?

0

Share this post


Link to post
Share on other sites

A quick google search revealed the following method creating a program in VB6. I guess you could load this up in your script as the first thing it runs.

here is a simple example that will find the command prompt window by it's window caption and disable the "x"

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _

(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal _

wFlags As Long) As Long

Private Const MF_BYPOSITION = &H400

Private Sub Command1_Click()

Dim cmdHwnd As Long, SysMenu As Long, Res As Long

cmdHwnd = FindWindow(vbNullString, "C:\WINDOWS\system32\cmd.exe")

If cmdHwnd <> 0 Then

SysMenu = GetSystemMenu(cmdHwnd, 0)

Res = RemoveMenu(SysMenu, 6, MF_BYPOSITION)

SetForegroundWindow cmdHwnd

End If

End Sub

Source: http://www.experts-exchange.com/Programmin...Q_21805315.html

I have access to Visual Studio somewhere so I could attempt to build this for you at somepoint if you are not able to, just PM me if you want anything like this.

Edited by infiniti25
1

Share this post


Link to post
Share on other sites

From what you've said there is no need to have a visible window showing since there is no user interaction required. Therefore you can simply prevent the window from showing!

There are many ways of doing that, third party 'hide' utilities or vbscripting being the most common methods.

0

Share this post


Link to post
Share on other sites

Thanks for your replies - I guess I forgot to mention the command prompt also displays a message that says "Please wait while your antivirus software is updated".

Whilst this message isn't essential it's nice to have it there so the user's don't panic at not being able to use the desktop or interact with their PC.

The utility that regenerates the SID's in our antivirus is also closeable so I guess it doesn't make much difference...

Thanks for your suggestions!

0

Share this post


Link to post
Share on other sites

please, i have try in vb express 2010 and not good result about close (x) command prompt

please anybody can help me?

0

Share this post


Link to post
Share on other sites

jaclaz, i cant acsses your link, i try but i cant, so

0

Share this post


Link to post
Share on other sites

jaclaz, i cant acsses your link, i try but i cant, so

 

It worked for me just now.

 

Cheers and Regards

0

Share this post


Link to post
Share on other sites

What do you mean cannot access? :unsure:

 

What do you get?

 

Like a 404, a suffusion of yellow, your PC shuts down :w00t: or explodes :ph34r:, what?

The links:

http://www.donationcoder.com/

http://www.donationcoder.com/Software/Skrommel/index.html

http://www.donationcoder.com/Software/Skrommel/index.html#NoClose

 

Disable the Close button (X) of selected windows.

Features:

- Press Ctrl+1 to Enable or Disable the Close button of the active window.

- Press Ctrl+2 to Add a rule.

- Automatic enabling and disabling of close buttons on program start and stop, and on window creation.

- Change hotkeys and automation options.

Changes:

- 2006.05.02 - v1.1: Corrected a settings error, changed the about dialog.

Thanks to mouser at DonationCoder Forum for the idea!

all work here, the direct link to the download is:

http://www.donationcoder.com/Software/Skrommel/NoClose/NoClose.exe

but if the above ones don't work, possibly this one would not also.

 

jaclaz

0

Share this post


Link to post
Share on other sites

ohh jaclaz, thank you for helped me. its amazing tool for me,

but my teacher just want it in vb.net language

:(

0

Share this post


Link to post
Share on other sites

... but my teacher just want it in vb.net language.

What part of "help with academic material, such as assignments, is not permitted on MSFN" (Rule #2c) did you fail to understand, iinfarlina? :angry:

0

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.