Jump to content

Disable or hide a control in another application


Recommended Posts

Hi all,

Is it possible to disable a button or control in an app I did not create?  For example, just a random EXIT button in a windows app like office, or adobe?  I just want to prevent a user from clicking it

Edited by wisem2540
Link to comment
Share on other sites

In theory, yes...but it also depends on the application and the control.

To illustrate, here's a crude example that disables the = button on the windows calculator:
 

If Not ProcessExists("calc.exe") Then Run(@SystemDir & "\calc.exe")
ProcessWait("calc.exe")

$hWnd = WinGetHandle("Calculator")
If Not IsHWnd($hWnd) Then Exit

ControlDisable($hWnd, "", "Button28")

 

Link to comment
Share on other sites

Hi.

My "="-Button is "Button30". And code above is only working on english speaking systems because of "calculator". But it works.

But if I try ControlHide($hWnd, "", "Button30") instead of ControlDisable() it's not working (but returns 1 - meaning success). So your right - in theory.

Regards, Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

And I am curious

On 8/3/2017 at 11:57 AM, wisem2540 said:

Hi all,

Is it possible to disable a button or control in an app I did not create?  For example, just a random EXIT button in a windows app like office, or adobe?  I just want to prevent a user from clicking it

I am actually curious about this too.

 

On 8/3/2017 at 8:31 PM, spudw2k said:

In theory, yes...but it also depends on the application and the control.

To illustrate, here's a crude example that disables the = button on the windows calculator:
 

If Not ProcessExists("calc.exe") Then Run(@SystemDir & "\calc.exe")
ProcessWait("calc.exe")

$hWnd = WinGetHandle("Calculator")
If Not IsHWnd($hWnd) Then Exit

ControlDisable($hWnd, "", "Button28")

 

@spudw2k, do you think you could go into a bit more detail as what kinds of control items autoit is able to manipulate (change the state of) like you did with the calculator example and which controls autoit is unable to modify.

Link to comment
Share on other sites

Natively, AutoIt can interact with most "Standard Microsoft Controls".  

This note in on the Controls help file page.
"Note: AutoIt only works with standard Microsoft controls. Some applications write their own custom controls which may look like a standard MS control but may resist automation.  Experiment!"

There are libraries to interact and UDFs to interact with non-standard controls (.Net for example), but I have little to no experience automating/interacting-with those.

Link to comment
Share on other sites

On 5/8/2017 at 0:09 AM, Simpel said:

But if I try ControlHide($hWnd, "", "Button30") instead of ControlDisable() it's not working (but returns 1 - meaning success). So your right - in theory.

It works for me:

ba3AuLn.png

And here is my code:

If Not ProcessExists("calc.exe") Then Run(@SystemDir & "\calc.exe")
ProcessWait("calc.exe")

$hWnd = WinGetHandle("Calculator")
If Not IsHWnd($hWnd) Then Exit

ControlHide($hWnd, "", "Button28")

 

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Funny. It's not working for me.

I definitely have to use "Button30" to disable "=" (Win 7). But anyway ControlHide() isn't working. Maybe you need admin privilege? I'm a standard user.

Regards, Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Maybe it depends on the version of Windows, what version are you using? and what edition?

18 minutes ago, Simpel said:

Maybe you need admin privilege? I'm a standard user.

I ran the script as a standard user too.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

That is console saying:

ConsoleWrite("Arch: " & @OSArch & @CRLF & "Build: " & @OSBuild & @CRLF & "ServicePack: " & @OSServicePack & @CRLF & "Type: " & @OSType & @CRLF & "Version: " & @OSVersion & @CRLF )
Arch: X64
Build: 7601
ServicePack: Service Pack 1
Type: WIN32_NT
Version: WIN_7

Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...