How can I disable e.g. minimize button in my .cmd script with code and commands in .vbs or powershel

Discussion in 'Scripting' started by RemixPL1994, Jan 31, 2023.

  1. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #1 RemixPL1994, Jan 31, 2023
    Last edited: Jan 31, 2023
    How can I disable e.g. minimize button in my .cmd script / window with code and commands in .vbs or powershell?

    If you use a different programming language for this and then put the code in the .exe to be able to refer to it, for example, in the middle of your script, then this way will also be interesting to me.

    Using the command in the .CMD script itself, loading an external .exe like this:

    START additional.exe "block window minimization"

    I'm talking about this button, of course:

    upload_2023-1-31_10-20-52.png

    In the same way, separately, I would also like to know if there is a way to additionally be able to block the maximization of the .CMD window using the button next to minimization and block the closing of the CMD window by pressing the X button.

    These are all 3 buttons next to each other in the upper right corner of the CMD console after running the script.

    In addition, I'm also interested in whether there is any way to block the stretching of the CMD window using mouse grabbing.

    My CMD window after firing looks like this:

    upload_2023-1-31_10-24-21.png

    And when I grab its edges I can't make it bigger but I can make it smaller:

    upload_2023-1-31_10-26-24.png

    If there is a way to somehow disable the ability to shrink the window, I'd like to know that too.

    What is important, I care about the way that the moving bars that are marked on the screen when the CMD window has been zoomed out do not appear and are not visible.

    Coming to the end of my message, there is one more thing I want to ask.

    Having a script in CMD where you use TASKKILL /F /IM explorer.exe in your commands and then start explorer.exe to restart the windows file explorer and the system explorer shell, I encounter a troublesome problem related to this.

    Before the script uses the command TASKKILL /F /IM explorer.exe my window is on top, I can enter text in it, accept changes after PAUSE on the keyboard by pressing the buttons because it is focused and active. But when exporer.exe is restarted, after the start explorer.exe command, the window is still visible to me on top, but I can no longer confirm any changes through the keyboard because the focus escapes to the icons on the desktop and pressing Y-YES / N-NO does not nothing happens on the CMD console only on desktop icons searching for their name.

    Only when I click the mouse again on the CMD window, the focus is restored and I can accept changes again using the buttons on the keyboard.

    Is there any way to make the CMD window after restarting explorer.exe still always on top / active and have focus on itself?

    With this code you can quickly check what I mean.

    Before reboot you can make changes, after reboot you can't and you have to manually click the mouse again on the CMD window because the focus is lost:

    upload_2023-1-31_10-30-3.png

    So, in conclusion, what do I care about and what am I looking for?

    I need to find a way to:


    - block / gray out the minimize button of the CMD window
    - lock/gray out the maximize button of the CMD window
    - lock / gray out the CMD window close button [X]
    - lock stretching and shrinking the CMD window
    - a way to keep window activity always on top and that window focus is not lost after restarting explorer.exe

    If any of you here on the forum has any way to do this from inside a CMD script, please help and advice on how to get it.

    If it can't be done with batch commands, it can also be .VBS and powershell and their commands loaded by the batch script as external.

    It can also be any other programming language saved in the .exe file and also references to it in the middle of the CMD script, such as START additional.exe "block window minimization"

    The important thing is that each feature/function and blocking options can be selected separately and decide which ones I want to use at a given moment, instead of having the whole file do it on a "block all always" basis.
     
  2. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    Check in rtool ps1 folder
    There is a solution for you
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #3 RemixPL1994, Jan 31, 2023
    Last edited: Jan 31, 2023
    (OP)
    Typing rtool here on the search engine finds your topic with the configuration for Office.

    Can you please point me to a link to the relevant topic?

    If it's a stupid thing to ask and I didn't understand then I'm sorry but I'm really not sure. Thanks in advance.

    upload_2023-1-31_11-19-6.png
     
  4. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    #4 Dark Dinosaur, Jan 31, 2023
    Last edited: Jan 31, 2023
    You lazy i get it ...
    this code will disable MAX, MIN

    this are the option you can play with
    const uint SC_CLOSE = 0xF060;
    const uint SC_MAXIMIZE = 0xF030;
    const uint SC_MINIMIZE = 0xF020;
    const uint SC_SIZE = 0xF000;

    using deleteMenu win32 api,
    to remove what you need

    DeleteMenu(hMenu, SC_???, MF_BYCOMMAND);

    Source code ... from here
    https://stackoverflow.com/questions/13763134/disabling-the-cmd-close-button-by-batch-command

    Code:
    @cls
    @echo off
    >nul chcp 437
    setLocal EnableExtensions EnableDelayedExpansion
    
    call :export Dis_X_Y >"%temp%\Dis_X_Y.ps1"
    2>nul powershell -ExecutionPolicy bypass -nop -file "%temp%\Dis_X_Y.ps1"
    pause
    exit /b
    
    :: Some s**ti code here ...
    :: Some s**ti code here ...
    :: Some s**ti code here ...
    
    :export
    rem AveYo's :export text attachments snippet
    setlocal enabledelayedexpansion || Prints all text between lines starting with :NAME:[ and :NAME:] - A pure batch snippet by AveYo
    set [=&for /f "delims=:" %%s in ('findstr/nbrc:":%~1:\[" /c:":%~1:\]" "%~f0"') do if defined [ (set/a ]=%%s-3) else set/a [=%%s-1
    <"%~fs0" ((for /l %%i in (0 1 %[%) do set /p =)&for /l %%i in (%[% 1 %]%) do (set txt=&set /p txt=&echo(!txt!)) &endlocal &exit/b
    
    :Dis_X_Y:[
    <# disabling the cmd close button by batch command #>
    <# https://stackoverflow.com/questions/13763134/disabling-the-cmd-close-button-by-batch-command #>
    
    $code = @'
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    
    namespace CloseButtonToggle {
    
     internal static class WinAPI {
       [DllImport("kernel32.dll")]
       internal static extern IntPtr GetConsoleWindow();
    
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       internal static extern bool DeleteMenu(IntPtr hMenu,
                              uint uPosition, uint uFlags);
    
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       internal static extern bool DrawMenuBar(IntPtr hWnd);
    
       [DllImport("user32.dll")]
       internal static extern IntPtr GetSystemMenu(IntPtr hWnd,
                  [MarshalAs(UnmanagedType.Bool)]bool bRevert);
    
       const uint SC_CLOSE     = 0xF060;
       const uint SC_MAXIMIZE  = 0xF030;
       const uint SC_MINIMIZE  = 0xF020;
       const uint SC_SIZE      = 0xF000;
       const uint MF_BYCOMMAND = 0;
    
       internal static void ChangeCurrentState(IntPtr Console, bool state) {
         IntPtr hMenu = GetSystemMenu(Console, state);
         DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND);
         DrawMenuBar(Console);
       }
       internal static void ChangeCurrentState(bool state) {
         IntPtr Console = GetConsoleWindow();
         IntPtr hMenu = GetSystemMenu(Console, state);
         DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND);
         DrawMenuBar(Console);
       }
     }
    
     public static class Status {
       public static void Disable(IntPtr Console) {
         WinAPI.ChangeCurrentState(Console, false); //its 'true' if need to enable
       }
       public static void Disable() {
         WinAPI.ChangeCurrentState(false); //its 'true' if need to enable
       }
     }
    }
    '@
    
    Add-Type $code;
    [CloseButtonToggle.Status]::Disable();
    exit;
    :Dis_X_Y:]
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #5 RemixPL1994, Jan 31, 2023
    Last edited: Jan 31, 2023
    (OP)
    @Dark Dinosaur

    Thank you very much. You may not believe me, you may think I'm lazy. It doesn't matter to me what you think because I'm grateful that you helped me and took your time to do this.

    I really don't understand English well and "I'm learning all these things" but I couldn't find it when I saw your first message.

    I tested it and I see it works very well!

    Will surprise you. I have been looking for this solution since 2017.

    I have tried many times on my own, with the help of other people, looking for a solution and nothing. You showed me immediately how to do it today. I'm really grateful to you.

    It seems like the last thing I'm looking for is to fix the CMD window losing focus after restarting .explorer.exe and having to click on the CMD window again to become the active window selection source instead of the previous desktop after losing focus.

    Do you have any knowledge on this topic and what to do to get rid of this defect? Perhaps you are also able to come to this simply?

    Best regards.

    Btw. Also thanks to your examples I understood how to add DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND); because straight in the code shown from you it was not included from AveYo's.

    So in addition, I easily avoided further problems with analyzing how to do it, and I learned immediately by trying it and understanding it in practice.

    Here is my video on YT where I present the focus problem I'm talking about:

     
  6. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #7 RemixPL1994, Jan 31, 2023
    Last edited: Jan 31, 2023
    (OP)
  7. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    a good example can be found here
    https://stackoverflow.com/questions/42566799/how-to-bring-focus-to-window-by-process-name

    Code:
    function Show-Window {
      param(
        [Parameter(Mandatory)]
        [string] $ProcessName
      )
    
      # As a courtesy, strip '.exe' from the name, if present.
      $ProcessName = $ProcessName -replace '\.exe$'
    
      # Get the PID of the first instance of a process with the given name
      # that has a non-empty window title.
      # NOTE: If multiple instances have visible windows, it is undefined
      #       which one is returned.
      $hWnd = (Get-Process -ErrorAction Ignore $ProcessName).Where({ $_.MainWindowTitle }, 'First').MainWindowHandle
    
      if (-not $hWnd) { Throw "No $ProcessName process with a non-empty window title found." }
    
      $type = Add-Type -PassThru -NameSpace Util -Name SetFgWin -MemberDefinition @'
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);   
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool IsIconic(IntPtr hWnd);    // Is the window minimized?
    '@
    
      # Note:
      #  * This can still fail, because the window could have been closed since
      #    the title was obtained.
      #  * If the target window is currently minimized, it gets the *focus*, but its
      #    *not restored*.
      $null = $type::SetForegroundWindow($hWnd)
      # If the window is minimized, restore it.
      # Note: We don't call ShowWindow() *unconditionally*, because doing so would
      #       restore a currently *maximized* window instead of activating it in its current state.
      if ($type::IsIconic($hwnd)) {
        $type::ShowWindow($hwnd, 9) # SW_RESTORE
      }
    
    }
    
    # Sample invocation
    Show-Window notepad
    Code:
    Param(
        [string] $proc="C:\Program Files (x86)\Citrix\ICA Client\concentr.exe",
        [string] $adm
    )
    Clear-Host
    
    Add-Type @"
        using System;
        using System.Runtime.InteropServices;
        public class WinAp {
          [DllImport("user32.dll")]
          [return: MarshalAs(UnmanagedType.Bool)]
          public static extern bool SetForegroundWindow(IntPtr hWnd);
    
          [DllImport("user32.dll")]
          [return: MarshalAs(UnmanagedType.Bool)]
          public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        }
    "@
    $p = Get-Process | Where {$_.mainWindowTitle} |
        Where {$_.Name -like "$proc"}
    if (($p -eq $null) -and ($adm -ne "")) {
        Start-Process "$proc" -Verb runAs
    } elseif (($p -eq $null) -and ($adm -eq "")) {
        Start-Process "$proc"
    } else {
        $h = $p.MainWindowHandle
        [void] [WinAp]::SetForegroundWindow($h)
        [void] [WinAp]::ShowWindow($h, 3)
    }
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    since you allready have ps script.
    just made the nececery changs

    IntPtr Console = GetConsoleWindow();

    Code:
      $type = Add-Type -PassThru -NameSpace Util -Name SetFgWin -MemberDefinition @'
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);   
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool IsIconic(IntPtr hWnd);    // Is the window minimized?
    '@
    
      # Note:
      #  * This can still fail, because the window could have been closed since
      #    the title was obtained.
      #  * If the target window is currently minimized, it gets the *focus*, but its
      #    *not restored*.
      $null = $type::SetForegroundWindow($hWnd)
      # If the window is minimized, restore it.
      # Note: We don't call ShowWindow() *unconditionally*, because doing so would
      #       restore a currently *maximized* window instead of activating it in its current state.
      if ($type::IsIconic($hwnd)) {
        $type::ShowWindow($hwnd, 9) # SW_RESTORE
      }
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    #10 Dark Dinosaur, Jan 31, 2023
    Last edited: Jan 31, 2023
    v4.0 with auto elevate
    Code:
    @cls
    @echo off
    >nul chcp 437
    setLocal EnableExtensions EnableDelayedExpansion
    
    rem Run as Admin with native shell, any path, params, loop guard, minimal i/o, by AveYo
    >nul reg add hkcu\software\classes\.Admin\shell\runas\command /f /ve /d "cmd /x /d /r set \"f0=%%2\" &call \"%%2\" %%3" & set "_= %*"
    >nul fltmc || if "%f0%" neq "%~f0" ( cd.>"%tmp%\runas.Admin" & start "%~n0" /high "%tmp%\runas.Admin" "%~f0" "%_:"=""%" &exit /b )
    
    echo:
    echo Kill explorer
    (>nul TASKKILL /F /IM explorer.exe)
    (>nul timeout /t 1)
    echo Start explorer
    start "" explorer.exe
    (>nul timeout /t 1)
    echo Activate cmd window
    call :export Activate >"%temp%\script.ps1"
    2>nul powershell -ExecutionPolicy bypass -nop -file "%temp%\script.ps1"
    echo Disable Size,Max,Min options
    call :export Dis_Min_Max >"%temp%\script.ps1"
    2>nul powershell -ExecutionPolicy bypass -nop -file "%temp%\script.ps1"
    echo:
    pause
    exit /b
    
    :: Some s**ti code here ...
    :: Some s**ti code here ...
    :: Some s**ti code here ...
    
    :export
    rem AveYo's :export text attachments snippet
    setlocal enabledelayedexpansion || Prints all text between lines starting with :NAME:[ and :NAME:] - A pure batch snippet by AveYo
    set [=&for /f "delims=:" %%s in ('findstr/nbrc:":%~1:\[" /c:":%~1:\]" "%~f0"') do if defined [ (set/a ]=%%s-3) else set/a [=%%s-1
    <"%~fs0" ((for /l %%i in (0 1 %[%) do set /p =)&for /l %%i in (%[% 1 %]%) do (set txt=&set /p txt=&echo(!txt!)) &endlocal &exit/b
    
    :Dis_Min_Max:[
    <# disabling the cmd close button by batch command #>
    <# https://stackoverflow.com/questions/13763134/disabling-the-cmd-close-button-by-batch-command #>
    
    <# How to bring focus to window by process name? #>
    <# https://stackoverflow.com/questions/42566799/how-to-bring-focus-to-window-by-process-name #>
    
    
    $code = @'
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    
    namespace Win32_Api {
    
     public static class WinAPI {
       [DllImport("kernel32.dll")]
       public static extern IntPtr GetConsoleWindow();
    
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       public static extern bool DeleteMenu(IntPtr hMenu,
                              uint uPosition, uint uFlags);
    
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       public static extern bool DrawMenuBar(IntPtr hWnd);
    
       [DllImport("user32.dll")]
       public static extern IntPtr GetSystemMenu(IntPtr hWnd,
                  [MarshalAs(UnmanagedType.Bool)]bool bRevert);
                  
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
    
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
          
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool IsIconic(IntPtr hWnd);    // Is the window minimized?
    
       const uint SC_CLOSE     = 0xF060;
       const uint SC_MAXIMIZE  = 0xF030;
       const uint SC_MINIMIZE  = 0xF020;
       const uint SC_SIZE      = 0xF000;
       const uint MF_BYCOMMAND = 0;
    
       internal static void ChangeCurrentState(IntPtr Console, bool state) {
         IntPtr hMenu = GetSystemMenu(Console, state);
         DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND);
         DrawMenuBar(Console);
       }
       internal static void ChangeCurrentState(bool state) {
         IntPtr Console = GetConsoleWindow();
         IntPtr hMenu = GetSystemMenu(Console, state);
         DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND);
         DeleteMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND);
         DrawMenuBar(Console);
       }
     }
    
     public static class Status {
       public static void Disable(IntPtr Console) {
         WinAPI.ChangeCurrentState(Console, false); //its 'true' if need to enable
       }
       public static void Disable() {
         WinAPI.ChangeCurrentState(false); //its 'true' if need to enable
       }
     }
    }
    '@
    
    Add-Type $code;
    [Win32_Api.Status]::Disable();
    exit;
    :Dis_Min_Max:]
    
    :Activate:[
    <# disabling the cmd close button by batch command #>
    <# https://stackoverflow.com/questions/13763134/disabling-the-cmd-close-button-by-batch-command #>
    
    <# How to bring focus to window by process name? #>
    <# https://stackoverflow.com/questions/42566799/how-to-bring-focus-to-window-by-process-name #>
    
    $code = @'
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    
    namespace Win32_Api {
    
     public static class WinAPI {
       [DllImport("kernel32.dll")]
       public static extern IntPtr GetConsoleWindow();
    
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       public static extern bool DeleteMenu(IntPtr hMenu,
                              uint uPosition, uint uFlags);
    
       [DllImport("user32.dll")]
       [return: MarshalAs(UnmanagedType.Bool)]
       public static extern bool DrawMenuBar(IntPtr hWnd);
    
       [DllImport("user32.dll")]
       public static extern IntPtr GetSystemMenu(IntPtr hWnd,
                  [MarshalAs(UnmanagedType.Bool)]bool bRevert);
                  
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
    
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
          
        [DllImport("user32.dll", SetLastError=true)]
        public static extern bool IsIconic(IntPtr hWnd);    // Is the window minimized?
    
       const uint SC_CLOSE     = 0xF060;
       const uint SC_MAXIMIZE  = 0xF030;
       const uint SC_MINIMIZE  = 0xF020;
       const uint SC_SIZE      = 0xF000;
       const uint MF_BYCOMMAND = 0;
     }
    }
    '@
    
    Add-Type $code;
    $hwnd = [Win32_Api.WinAPI]::GetConsoleWindow()
    
    # Note:
    #  * This can still fail, because the window could have been closed since
    #    the title was obtained.
    #  * If the target window is currently minimized, it gets the *focus*, but its
    #    *not restored*.
    $null = [Win32_Api.WinAPI]::SetForegroundWindow($hWnd)
    # If the window is minimized, restore it.
    # Note: We don't call ShowWindow() *unconditionally*, because doing so would
    #       restore a currently *maximized* window instead of activating it in its current state.
    if ([Win32_Api.WinAPI]::IsIconic($hwnd)) {
    [Win32_Api.WinAPI]::ShowWindow($hwnd, 9) | out-null # SW_RESTORE
    }
    exit;
    :Activate:]
     

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #11 RemixPL1994, Jan 31, 2023
    Last edited: Jan 31, 2023
    (OP)
    @Dark Dinosaur

    Hello, many thanks for all your help. I checked the whole thing and everything seems to work perfectly on my Windows 10 64 bit.

    I want to test it even more thoroughly and calmly for a long time on other operating systems, e.g. XP 32 bit, Vista 32 bit, Windows 7 64 bit to see if it works on every system or only on Vista and up, etc.

    If I stumble across something I don't know, I'll come back here in this topic.

    The last question I have for now is which version of the code is the latest?

    I see that the version of the code pasted in the forum contains names such as namespace Win32_Api and [Win32_Api.Status]::Disable(); and the downloadable version called Windows Stuff etc contains the namespace CloseButtonToggle and [CloseButtonToggle.Status]::Disable();

    Also, I compared both files and one has 188 lines of code and the other has 204.

    Here is a screenshot with a comparison. Please just point me to the latest one with the latest code fixes, the best one on which I can start my research and tests:

    upload_2023-1-31_19-32-29.png

    To make it simpler:

    Code pasted in the forum - 188 characters.

    Code taken from the file - 204 characters.

    While I know that renamed functions don't have to matter, the difference of 188 vs 204 characters confuses me as to whether it's better to use one or the other.

    Is 204 corrected to 188 optimized cleaner code or incomplete legacy code.
     
  11. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    #12 Dark Dinosaur, Jan 31, 2023
    Last edited: Jan 31, 2023
    this should be the latest
    clean un-necessary stuff
    new names etc

    B.T.W
    this will not work on new terminal :)
    only on --> conhost.exe host --> cmd.exe
     

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    Thank you, now I'm sure that the version with 188 code is cleaner and newer :D

    I don't use powershell at all, only batch scripts, i.e. fired in cmd.exe, so no problem for me :)

    I have already tested it and found that:

    everything works for me on windows 10 pro x64 bit

    on win7 pro x64 bit restoring focus, blocking window stretching/shrinking and blocking close button [X] works

    but it doesn't work for the minimize and maximize button.

    on vista x32 bit everything works again except restoring window focus.

    Nothing works on XP x32 bit. It's not hard to guess that it's because of the lack of powershell, which in XP is not native.

    I wonder if it could be done with the help of .VBS or natively typed code together with powershell to .EXE so that it also worked in XP so that powershell was operated from the inside of the EXE file.

    Or another way.

    If it's not possible, it's hard and nothing bad will happen - I'm least interested in XP from the whole thing, so don't worry :D


    The most I would like to know if it can be investigated even more and otherwise why everything works on vista but restoring the focus does not work?

    And on win 7, restoring focus and the rest works together with the close button, but blocking the minimization and maximization of the window does not work.

    Perhaps you need separate number values and settings depending on the system so that the script always works on each system?

    Please check and verify if you can. @Dark Dinosaur
     
  13. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    I am not win32 api export
    Maybe abboodi1406 know :oops:
    Google is you best friend
    Maybe you will find there what you look for
    Or chatgpt lol

    Microsoft have API section
    With lot of info ...
    Maybe look there too ..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,759
    5,223
    120
    Using cmdow tool ? (For xp)
    But beware of people.. will say virus virus bla bla
    https://ritchielawrence.github.io/cmdow/

    Cmdow is a Win32 commandline utility for NT4/2000/XP/2003/2008/7 that allows windows to be listed, moved, resized, renamed, hidden/unhidden, disabled/enabled, minimized, maximized, restored, activated/inactivated, closed, killed and more.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #16 RemixPL1994, Jan 31, 2023
    Last edited: Jan 31, 2023
    (OP)
    @abbodi1406

    Hello. Please write. Do you have any idea why for windows 10 everything works but for win7 or vista randomly some 1 element of the whole does not work?


    I found that in Windows 7 in the appearance options, unchecking "use visual styles for windows and buttons" fixes blocking the window from maximizing and minimizing.

    Maybe now someone will have an idea why this breaks it and how to get around it?
     
  16. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    16,222
    84,900
    340
    I don't have any clue, sorry :)
     
  17. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #18 RemixPL1994, Feb 1, 2023
    Last edited: Feb 1, 2023
    (OP)
    Thank you for your answer.

    There's only one other person I can think of who might know. @AveYo



    I'm guessing that it may be related to Windows Aero which is present in Windows Vista and Windows 7 and is no longer present in Windows 10. And therefore the minimize / maximize windows buttons may have different numbers / different IDs when aero is on / off.

    But I have no idea why on Vista, whether Windows Aero is enabled or not, the focus doesn't want to work and it doesn't restore the window as active back.

    I will try restoring focus on windows vista x64 bit and see if it works well there.

    If so, this particular problem will only be with Vista x32 bit.


    Do you know any tool that can track the opened CMD window / launched batch script and to indicate all information about the ID, debugging, class names from the CMD window depending on where I point / press the mouse?

    I could then investigate whether there are any differences in the buttons and their data between Aero on / off and if there are differences, indicate them on the forum.