Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

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

- - - - -

  • Please log in to reply
3 replies to this topic

#1
dunkie12

dunkie12

    Newbie

  • Members
  • 17 posts
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?


How to remove advertisement from MSFN

#2
infiniti25

infiniti25

    Junior

  • Members
  • Pip
  • 97 posts
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-e...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, 04 December 2008 - 07:32 AM.


#3
Yz÷wl

Yz÷wl

    Wise Owl

  • Super Moderator
  • 4,506 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#4
dunkie12

dunkie12

    Newbie

  • Members
  • 17 posts
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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN