Jump to content

ControlCommand IsChecked not working


Recommended Posts

I'm trying to check the status of the checkbox for sharing a folder that you see when you right-click on a  folder, go to the sharing tab, then click on Advanced Sharing.

The check box is labelled Share this folder, and looking at it using AutoIt window info, I get the following information..

>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    1020
Text:    &Share this folder
Position:    15, 16
Size:    306, 13
ControlClick Coords:    57, 4
Style:    0x50010003
ExStyle:    0x00000004
Handle:    0x0000000000420A52

I'm using the following code..

If ControlCommand("Sharing","","[CLASS:Button; INSTANCE:1]","IsChecked","") = 0 Then
    MsgBox(0, "", "not checked")
Else
    MsgBox(0, "", "checked")
EndIf

But this insists the check box isn't checked when it is.  I have also tried ControlCommand("Sharing","","[ID:1020]","IsChecked","") and ControlCommand("Sharing","","Share this folder","IsChecked","") and ControlCommand("Sharing","","&Share this folder","IsChecked",""), with no joy.

 

Any ideas?

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

EarthShine - sorry for the slow reply - been busy.

Thanks for the confirmation - are you able to get it to be checked regardless of which state it is in? - I really only need to make sure it is checked.

 

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

Try this :

#RequireAdmin

Opt ("MustDeclareVars", 1)

Local $hWnd = WinGetHandle ("[CLASS:#32770]")
WinActivate ($hWnd)
WinWaitActive ($hWnd)
ControlClick ($hWnd, "", "[CLASSNN:Button1]")
ControlClick ($hWnd, "", "[CLASSNN:Button9]")

MsgBox ($MB_SYSTEMMODAL,"",ControlCommand ($hWnd, "", "[CLASSNN:Button1]", "IsChecked", ""))

Working for me...

Link to comment
Share on other sites

Hi Nine,

I've tried your code, and it doesn't work for me - the msgbox just displays 0, regardless of the state of the checkbox.

Looking a bit more into this - the Properties form has the class ID 32770, and so does the Advanced Sharing form, so I think it's getting confused about which form it should be looking at.

I tried altering the WinGetHandle line to 

local $hwnd = WinGetHandle("[CLASS:#32770]", "Advanced Sharing")

...but that made no difference.

(I want to use the Advanced sharing form, as once I've got around the checkbox hiccup, I then need to go into Permissions and set those - more checkboxes!)

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

Link to comment
Share on other sites

On 7/5/2019 at 1:35 PM, Nine said:

@ozymandius257 It also works for me using this :

#include <GuiButton.au3>

;previous code goes here
Local $hButton = ControlGetHandle ($hWnd, "", "[CLASSNN:Button1]")
MsgBox ($MB_SYSTEMMODAL,"",_GUICtrlButton_GetCheck ($hButton))


 

 

this produces the same thing on my machine that I was getting, always returning 0, admin or not. does not work on later builds of Windows 10, should be reported as a bug

 

last week when i was responding to this, my cpu died and everything went black... what a nice way to go... anyway, I can check and uncheck the box at will , just cannot read it's state properly. Windows 10 Build 1903

 

i was using my WaitForControls to click it so i have proper logging and dynamic wait

#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include 'log4a.au3'
#include 'WaitForControls.au3'

#RequireAdmin

Const $TD_BTN_SHARE = '&Share this folder'
Const $text = "Advanced Sharing"
Const $class = "[CLASS:#32770]"
Const $button1 = "[CLASS:Button; INSTANCE:1]"

#Region ;**** Logging ****
; Enable logging and don't write to stderr
_log4a_SetEnable()
; Write to stderr, set min level to warn, customize message format
_log4a_SetErrorStream()
_log4a_SetCompiledOutput($LOG4A_OUTPUT_FILE)
_log4a_SetMinLevel($LOG4A_LEVEL_INFO)
; If @compiled Then _log4a_SetMinLevel($LOG4A_LEVEL_WARN) ; Change the min level if the script is compiled
_log4a_SetFormat("${date} | ${host} | ${level} | ${message}")
#EndRegion ;**** Logging ****

$var = ControlCommand("Sharing","","[CLASS:Button; INSTANCE:1]","IsChecked","")

If $var Then
    MsgBox(0, "not checked", $var)
Else
    MsgBox(0, "checked ", $var)
EndIf

_log4a_Info('Begin Test()')
_checkClickCtrl($class, $text, $button1, $TD_BTN_SHARE, 0)
_log4a_Info('End Test()')

 

WaitForControls.au3

log4a.au3

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

@Earthshine Strange. I searched for a win10 bug of that, couldn't find.  Would you mind testing this :

#include <Constants.au3>
#include <GuiButton.au3>
#include <SendMessage.au3>

#RequireAdmin

Opt ("MustDeclareVars", 1)

Local $hWnd = WinGetHandle ("[CLASS:#32770]")
WinActivate ($hWnd)
WinWaitActive ($hWnd)
ControlClick ($hWnd, "", "[CLASSNN:Button1]")
ControlClick ($hWnd, "", "[CLASSNN:Button9]")

Local $hButton = ControlGetHandle ($hWnd, "", "[CLASSNN:Button1]")
MsgBox ($MB_SYSTEMMODAL,"",_SendMessageA ($hButton, $BM_GETCHECK, 0, 0))

 

Link to comment
Share on other sites

@Nine, @Earthshine

I've just tested your code above and it works! 

It reported 0 when the checkbox is unchecked, and 1 when it is checked, and I've tested this on win 10 and PosReady7.

 

All I've got to do now is work my way through the rest of the code to set permissions :)

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

  • ozymandius257 changed the title to [SOLVED] ControlCommand IsChecked not working
4 hours ago, ozymandius257 said:

I've just tested your code above and it works

 

30 minutes ago, Earthshine said:

tested your code and it worked with the _SendMessage, nice

:thumbsup:

Link to comment
Share on other sites

@Nine, @Earthshine

Well, this is annoying - I've been testing your code with just the advanced sharing window open, which is how it seemed to be working.

Now I've got around to putting in the rest of the code to open that window, it's stopped working again.

Here's my code, note that I got the function _FilePropertiesDialog from elsewhere on the forum as a way to display the properties window for the folder.

Can you see what's going wrong here?

 

#include <GuiTab.au3>
#include <GuiButton.au3>

HotKeySet("{Esc}", "OnExit")

AutoItSetOption("WinTitleMatchMode", 2)
_FilePropertiesDialog("c:\test","Shortcut",2)

$hwnd = WinWait("Properties", "", 2)
If $hwnd = 0 Then
    MsgBox(0, "", "Error - Properties window not found")
    Exit
EndIf

$hwnd = ControlGetHandle("Test Properties", "", "SysTabControl321")
$Sharingtab = _GUICtrlTab_FindTab($hwnd, "Sharing")
If $Sharingtab = -1 Then
    MsgBox(0, "", "Cannot find the sharing tab - sorry")
    Exit
EndIf
_GUICtrlTab_ActivateTab($hwnd, $Sharingtab)
Sleep(200)

;click on advanced sharing
Send("!d")
Sleep(200)

Local $hWnd = WinGetHandle ("[CLASS:#32770]")
WinActivate ($hWnd)
WinWaitActive ($hWnd)

Local $hButton = ControlGetHandle ($hWnd, "", "[CLASSNN:Button1]")
MsgBox ($MB_SYSTEMMODAL,"",_SendMessageA ($hButton, $BM_GETCHECK, 0, 0))


Exit


Func _FilePropertiesDialog($sObjName,$sPropPage="",$iObjType=0x02,$hWnd=0)
    Local $sPropPageType="ptr"
    If IsString($sPropPage) And $sPropPage<>"" Then
        $sPropPageType="wstr"
    Else
        $sPropPage=0
    EndIf
    Local $aRet=DllCall("shell32.dll","bool","SHObjectProperties","hwnd",$hWnd,"dword",$iObjType,"wstr",$sObjName,$sPropPageType,$sPropPage)
    If @error Then Return SetError(2,@error,False)
    If Not $aRet[0] Then Return SetError(3,0,False)
    Return True
EndFunc

Func OnExit()
    Exit
EndFunc

 

Back up my hard drive? - I can't even find reverse gear.

Link to comment
Share on other sites

  • ozymandius257 changed the title to ControlCommand IsChecked not working

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

×
×
  • Create New...