Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to disable close "X" button in DOS  (Read 16286 times)

0 Members and 1 Guest are viewing this topic.

slab69

    Topic Starter


    Rookie

    How to disable close "X" button in DOS
    « on: April 13, 2009, 06:57:10 AM »
    I am running a script via dos at logon.  I would like to disable the close button so they can't just click the "X"   Is it possible to do so?

    Dias de verano

    • Guest
    Re: How to disable close "X" button in DOS
    « Reply #1 on: April 13, 2009, 08:30:17 AM »
    No.

    What does the script do?

    mroilfield



      Mentor
    • Thanked: 42
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 11
    Re: How to disable close "X" button in DOS
    « Reply #2 on: April 13, 2009, 08:31:59 AM »
    why would you want to?
    You can't fix Stupid!!!

    Dias de verano

    • Guest
    Re: How to disable close "X" button in DOS
    « Reply #3 on: April 13, 2009, 08:33:15 AM »
    why would you want to?

    That is what I am wondering.

    slab69

      Topic Starter


      Rookie

      Re: How to disable close "X" button in DOS
      « Reply #4 on: April 13, 2009, 10:39:00 AM »
      within the script, I am asking for user input with the results being sent to another pc within a log file.  I want to force them to enter the information during the logon process without allowing them to close the command window.

      mroilfield



        Mentor
      • Thanked: 42
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 11
      Re: How to disable close "X" button in DOS
      « Reply #5 on: April 13, 2009, 10:46:02 AM »
      What kind of information are you needing some one to enter during the Log-in process.

      This sounds fishy to me.
      You can't fix Stupid!!!

      macdad-



        Expert

        Thanked: 40
        Re: How to disable close "X" button in DOS
        « Reply #6 on: April 13, 2009, 11:09:41 AM »
        I smell virus...Seems to be a kind of keylogger.
        If you dont know DOS, you dont know Windows...

        Thats why Bill Gates created the Windows NT Family.

        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Re: How to disable close "X" button in DOS
        « Reply #7 on: April 13, 2009, 04:55:30 PM »
        I smell virus...Seems to be a kind of keylogger.

        Modern countries practice "Innocent until proven guilty", but we also have the right to not help the OP if we don't feel like helping (for whatever reason).
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        macdad-



          Expert

          Thanked: 40
          Re: How to disable close "X" button in DOS
          « Reply #8 on: April 14, 2009, 06:22:20 AM »
          Modern countries practice "Innocent until proven guilty", but we also have the right to not help the OP if we don't feel like helping (for whatever reason).

          Common Sense, is that reason  ;)
          If you dont know DOS, you dont know Windows...

          Thats why Bill Gates created the Windows NT Family.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: How to disable close "X" button in DOS
          « Reply #9 on: April 14, 2009, 07:17:36 AM »
          what is this "innocent until proven guilty" stuff you keep saying helpmeh.

          The problem is the only proof of guilt would be after the damage is done- and even then we would never know, so they would keep coming back, "how do I delete all the users documents", "how do I copy  a file "keylog.txt" from C:\ to a removable USB drive that is hidden from explorer", etc etc, and we'd have to blithely assist them because, I mean- how the heck can that be construed as malicious! keylog.txt, as they would say, is a recipe, and the drive is hidden so it doesn't get formatted by accident!

          "Innocent Until Proven Guilty" in a court of law. This isn't a court of law. So I guess we have to blithely assume all posters are legitimate, even for requests like, "how do I start a program as a service that won't show up in the services control panel?" or "how can I make a appInit_DLL", until they are proven guilty in a court of law. At which point, once again, we wouldn't know.

          Going with this "innocent until proven guilty" would cause a LOT of liability issues for CH in the long run, when the completely inept malware writer points at CH where he asked various questions like "how can I force a service to stop" and "how do I write a winlogon notify hook".

          Sorry I just had to say some funny thread titles.
          I was trying to dereference Null Pointers before it was cool.

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: How to disable close "X" button in DOS
          « Reply #10 on: April 14, 2009, 04:39:26 PM »
          what is this "innocent until proven guilty" stuff you keep saying helpmeh.

          The problem is the only proof of guilt would be after the damage is done- and even then we would never know, so they would keep coming back, "how do I delete all the users documents", "how do I copy  a file "keylog.txt" from C:\ to a removable USB drive that is hidden from explorer", etc etc, and we'd have to blithely assist them because, I mean- how the heck can that be construed as malicious! keylog.txt, as they would say, is a recipe, and the drive is hidden so it doesn't get formatted by accident!

          "Innocent Until Proven Guilty" in a court of law. This isn't a court of law. So I guess we have to blithely assume all posters are legitimate, even for requests like, "how do I start a program as a service that won't show up in the services control panel?" or "how can I make a appInit_DLL", until they are proven guilty in a court of law. At which point, once again, we wouldn't know.

          Going with this "innocent until proven guilty" would cause a LOT of liability issues for CH in the long run, when the completely inept malware writer points at CH where he asked various questions like "how can I force a service to stop" and "how do I write a winlogon notify hook".

          Sorry I just had to say some funny thread titles.
          I mean, like we can't outright say that the OP is a skiddie malware writer (fail), but we can obviously choose to not help him/her.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          slab69

            Topic Starter


            Rookie

            Re: How to disable close "X" button in DOS
            « Reply #11 on: April 20, 2009, 10:09:25 AM »
            LMAO  This is the first time I have been accused of being a virus writer, hacker, etc.   :)  I guess I can see how you may have thought so.

            I will give a brief explaination of what I am trying to do.  My dept does not have C# or any program writing software, so I am trying to write a little script using DOS until we have access to some software to do what we need.  what we are trying to accomplish is gather log in times and ask a simple question as to what "dept" they are in.  Once the user types in a response, the script simply sends a log entry with computername, time and date with the user's response to the question.  Once the user logs off, we have another script send log offf time and date along with the computername.  The reason we are doing all this is to circumvent the need to constantly ask our point of contacts for each classroom to send us their monthly usage. 
            With that being said, here is a sample of my script:
            @ echo off
            net use f: \\server01\d$
            cd\
            cls
            :start
            Set Unit=
            Echo For funding purposes, we need to know what Dept you are from
            Set /P Dept=Please enter dept ID 
            rem if /i %Dept% EQU "" goto start
            cls
            if "%Dept%"=="" (
            echo.
            echo Please enter your dept ID
            echo Please try again
            echo.
            goto start
            )
            Echo %Dept%, %computername%, %date%, %time%, Logon >>f:\test.txt


            I hope this helps clear up what I am trying to do and clear up the issue of the thinking that I am doing some type of keylogger.   :)

            gpl



              Apprentice
            • Thanked: 27
              Re: How to disable close "X" button in DOS
              « Reply #12 on: April 20, 2009, 10:48:35 AM »
              Wouldnt this information be held within the active directory ? and if not, why not

              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              Re: How to disable close "X" button in DOS
              « Reply #13 on: April 20, 2009, 11:45:26 AM »
              Quote
              My dept does not have C# or any program writing software, so I am trying to write a little script using DOS until we have access to some software to do what we need.
              You can download a FREE version of Visual C from Microsoft for evaluation. You can put what you need in a simple GUI Windows. Even so, the savvy user can close it just like almost any kind of window.

              macdad-



                Expert

                Thanked: 40
                Re: How to disable close "X" button in DOS
                « Reply #14 on: April 20, 2009, 11:47:38 AM »
                or heck, just get FreeBasic or even QBASIC
                If you dont know DOS, you dont know Windows...

                Thats why Bill Gates created the Windows NT Family.

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: How to disable close "X" button in DOS
                « Reply #15 on: April 20, 2009, 11:59:49 AM »
                Using the API you can programmatically:

                Acquire the System menu of the window. (GetSystemMenu(HWND))

                Call EnableMenuItem() with the appropriate flags and the SC_CLOSE ID (0x060).

                the "X" button as well as the close menu option will be disabled.


                Problem being, I don't think this works for command-windows,  they are a system-managed class (even uxtheme.dll can't work with them- ever notice the lack of Luna themes on cmd windows?

                Also, they might use a different ID for the menu items.
                I was trying to dereference Null Pointers before it was cool.

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: How to disable close "X" button in DOS
                « Reply #16 on: April 20, 2009, 12:11:02 PM »

                Hello B.C.
                well, what I intended was a suggested him that he writes the entire thing in Visual Basic or visuals see instead of doing it in a batch command.  And if those function calls are available in Visual Basic that would be persuaded to.
                On the Microsoft might he can download or near copies of Visual Basic that do not require that.net stuff.
                He and, this is done with voice recognition.  To some funny things.   :rofl:

                Batcher



                  Rookie

                  Thanked: 5
                  Re: How to disable close "X" button in DOS
                  « Reply #17 on: April 20, 2009, 08:49:43 PM »
                  You need a command line tool gray.exe. Then call it in your bat.

                  Code: [Select]
                  @echo off
                  rem Call gray.exe to disable "X" button
                  start /b gray.exe
                  rem Your commands below
                  echo This is a test
                  rem Kill process gray.exe to enable "X" button after your commands finished
                  taskkill /f /im gray.exe>nul
                  pause

                  Dias de verano

                  • Guest
                  Re: How to disable close "X" button in DOS
                  « Reply #18 on: April 21, 2009, 12:48:39 AM »
                  To some funny things.   :rofl:

                  To some stupid things  ::)

                  Dias de verano

                  • Guest
                  Re: How to disable close "X" button in DOS
                  « Reply #19 on: April 21, 2009, 12:51:12 AM »
                  You need a command line tool gray.exe.

                  Does it exist?

                  gh0std0g74



                    Apprentice

                    Thanked: 37
                    Re: How to disable close "X" button in DOS
                    « Reply #20 on: April 21, 2009, 12:56:21 AM »
                    @OP, i am not into windows login stuff, but i believe if you are having some sort of ActiveDirectory or LDAP where information of users are stored, there is no need to prompt user for any input. You just need a little bit scripting to get those information from the data store.

                    Batcher



                      Rookie

                      Thanked: 5
                      Re: How to disable close "X" button in DOS
                      « Reply #21 on: April 22, 2009, 10:06:09 AM »
                      Does it exist?

                      Yes, it does. I got it from a friend.

                      If you have interesting, I can email it to you. It's free : )

                      Dias de verano

                      • Guest
                      Re: How to disable close "X" button in DOS
                      « Reply #22 on: April 22, 2009, 10:19:01 AM »
                      Yes, it does. I got it from a friend.

                      If you have interesting, I can email it to you. It's free : )

                      We don't do things that way on here.

                      Batcher



                        Rookie

                        Thanked: 5
                        Re: How to disable close "X" button in DOS
                        « Reply #23 on: April 22, 2009, 10:21:14 AM »
                        We don't do things that way on here.

                        Sorry, I am newbee here. I am not familiar with the rules yet.

                        BC_Programmer


                          Mastermind
                        • Typing is no substitute for thinking.
                        • Thanked: 1140
                          • Yes
                          • Yes
                          • BC-Programming.com
                        • Certifications: List
                        • Computer: Specs
                        • Experience: Beginner
                        • OS: Windows 11
                        Re: How to disable close "X" button in DOS
                        « Reply #24 on: April 22, 2009, 11:01:27 AM »
                        lol. I love that "I got it from a friend" bit. way to be conspicuous.
                        I was trying to dereference Null Pointers before it was cool.

                        Batcher



                          Rookie

                          Thanked: 5
                          Re: How to disable close "X" button in DOS
                          « Reply #25 on: April 22, 2009, 08:24:03 PM »
                          lol. I love that "I got it from a friend" bit. way to be conspicuous.

                          That gray.exe is developed using C++. If you're interested in the source code, I can try ask it from him.

                          Reno



                            Hopeful
                          • Thanked: 32
                            Re: How to disable close "X" button in DOS
                            « Reply #26 on: April 23, 2009, 08:06:13 AM »
                            Using the API you can programmatically:

                            Acquire the System menu of the window. (GetSystemMenu(HWND))

                            Call EnableMenuItem() with the appropriate flags and the SC_CLOSE ID (0x060).

                            the "X" button as well as the close menu option will be disabled.


                            pseudocode based on BC_programmer workflow as mentioned above, working vb6 code below:
                            Code: [Select]
                            Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
                            Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
                            Private Declare Function RemoveMenu Lib "user32.dll" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
                            Private Const SC_CLOSE As Long = &HF060&

                            Sub main()
                                hwnd = FindWindow("ConsoleWindowClass", vbNullString)
                                If hwnd = 0 Then MsgBox "Console not running": Exit Sub
                                RemoveMenu GetSystemMenu(hwnd, 0), SC_CLOSE, 0
                            End Sub

                            BC_Programmer


                              Mastermind
                            • Typing is no substitute for thinking.
                            • Thanked: 1140
                              • Yes
                              • Yes
                              • BC-Programming.com
                            • Certifications: List
                            • Computer: Specs
                            • Experience: Beginner
                            • OS: Windows 11
                            Re: How to disable close "X" button in DOS
                            « Reply #27 on: April 23, 2009, 09:02:09 AM »
                            a good method to get the handle to the proper window, instead of findwindow (we can never know what it'll find, if there is more then one instance) is to use LINK to change the subsystem to CONSOLE and then use the console functions to determine the hwnd of the console window itself, which can be used as presented here.
                            I was trying to dereference Null Pointers before it was cool.

                            Reno



                              Hopeful
                            • Thanked: 32
                              Re: How to disable close "X" button in DOS
                              « Reply #28 on: April 23, 2009, 09:17:57 AM »
                              bc, which api are you refering to get current console hwnd? care to shed some light on me, plz  :P

                              you are correct, the above code only for one instance of console.

                              BC_Programmer


                                Mastermind
                              • Typing is no substitute for thinking.
                              • Thanked: 1140
                                • Yes
                                • Yes
                                • BC-Programming.com
                              • Certifications: List
                              • Computer: Specs
                              • Experience: Beginner
                              • OS: Windows 11
                              Re: How to disable close "X" button in DOS
                              « Reply #29 on: April 23, 2009, 09:38:49 AM »
                              W2K and up support GetConsoleWindow().

                              Code: [Select]
                              Private Declare Function GetConsoleWindow Lib "kernel32" () As Long

                              otherwise, you'd need to take the tortuous path.

                              This is the property from the Console Module I use...

                              of course... you could just use the module in a small program to change the system menu...

                              Some of the variables are member variables and the API's need to be declared as well. I'd visit the url given in the comments.



                              Code: [Select]
                                ' 124103 - HOWTO: Obtain a Console Window Handle (HWND)
                                 ' http://support.microsoft.com/default.aspx?scid=KB;en-us;q124103
                                 Dim os As OSVERSIONINFO
                                 Dim Title As String
                                 Dim Unique As String
                                 Dim nRet As Long

                                 ' Returned cached value, if possible.
                                 If m_hWnd = 0 Then
                                    ' Determine what operating system this is.
                                    os.dwOSVersionInfoSize = Len(os)
                                    Call GetVersionEx(os)

                                    If os.dwPlatformId = VER_PLATFORM_WIN32_NT _
                                       And os.dwMajorVersion >= 5 Then
                                       ' This is Windows2000 or later!
                                       m_hWnd = GetConsoleWindow()

                                    Else ' Take the tortuous path...
                                       ' Cache the associated title.
                                       Title = Space$(1024)
                                       nRet = GetConsoleTitle(Title, Len(Title))
                                       If nRet Then
                                          Title = Left$(Title, nRet)
                                       End If

                                       ' Construct unique string to use as new title.
                                       Unique = Format$(Now, "yyyymmddhhnnss") & Hex$(GetCurrentProcessId())

                                       ' Set new title to use for search.
                                       If SetConsoleTitle(Unique) Then
                                          ' Find window most likely to be our console.
                                          m_hWnd = FindConsole(Unique)
                                          ' Restore original title.
                                          Call SetConsoleTitle(Title)
                                       End If
                                    End If
                                 End If
                                 hWnd = m_hWnd
                              I was trying to dereference Null Pointers before it was cool.

                              Reno



                                Hopeful
                              • Thanked: 32
                                Re: How to disable close "X" button in DOS
                                « Reply #30 on: April 23, 2009, 09:47:59 AM »
                                it works great. GetConsoleWindow()  ;D nice

                                i keep searching for the keyword "console","std","process","window" in ApiViewer 2004, but couldn't find anything to get current console. no wonder, it's not listed there.

                                BC_Programmer


                                  Mastermind
                                • Typing is no substitute for thinking.
                                • Thanked: 1140
                                  • Yes
                                  • Yes
                                  • BC-Programming.com
                                • Certifications: List
                                • Computer: Specs
                                • Experience: Beginner
                                • OS: Windows 11
                                Re: How to disable close "X" button in DOS
                                « Reply #31 on: April 23, 2009, 09:59:52 AM »
                                heh, I know too, I was checking ApiViewer 2004.


                                Although I've found it's missing structures and functions when I need them most.
                                I was trying to dereference Null Pointers before it was cool.