Sign in to follow this  
Followers 0
Ganda1f

Problem with _GUICtrlListView_GetItemChecked and _GUICtrlListView_SetItemChecked

7 posts in this topic

I am trying write a script to see if File and Print Sharing for Microsoft Networks is turned on or not. If it is not, I want to turn it on. There were past discussions on this and I never found a real resolution. I am using v3.2.10.0 as this was suppose to deal with SysListView32 better.

The following is the code I am using:

#Include <GuiListView.au3>

#include <Array.au3>

Run("control ncpa.cpl")

winwait("Network Connections")

winActivate("Network Connections")

send("local")

Send("!fr")

Winwait("Local Area Connection Properties")

Sleep(1000)

Send("f")

$Hwnd = ControlGetHandle("Local Area Connection Properties","",16012)

$Count = _GUICtrlListView_GetItemCount($Hwnd)

$ItemIndexCount = _GUICtrlListView_GetSelectedCount($Hwnd)

If $ItemIndexCount = 1 Then

$ItemIndex = _GUICtrlListView_GetSelectedIndices($Hwnd, False)

$BoxText = _GUICtrlListView_GetItemText($Hwnd, $ItemIndex)

; Check to see if the check box is checked.

$CheckedStatus = _GUICtrlListView_GetItemChecked($Hwnd, $ItemIndex)

If $CheckedStatus == False Then

_GUICtrlListView_SetItemChecked($Hwnd, $ItemIndex, 1) ;This will check File and Printer Sharing

EndIf

EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

When it executes the $CheckedStatus = _GUICtrlListView_GetItemChecked($Hwnd, $ItemIndex) line, I get an Explorer.exe - Application Error.

The instruction at "0x77419050" referenced memory at "0x014bc540". The memory could not be "read".

Removing that line and and just trying to set the checkmark with the _GUICtrlListView_SetItemChecked($Hwnd, $ItemIndex, 1) doesn't seem to do anything.

Any help would be appreciated.

Share this post


Link to post
Share on other sites



i'm not positive of this but i'd think this might be easier done with regread of the key.

then you could compare the value with what you need it to be and do a regwrite back to the key if need be.

only problem is i haven't found the key you need to check for and it may not be that simple as your connection names may vary from

local area connection 1

local area connection 2

etc...

good luck.

Share this post


Link to post
Share on other sites

Changed for next beta/release thanks Siao

Func _GUICtrlListView_GetItemChecked($hWnd, $iIndex)
    If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
    Local $struct_LVITEM = DllStructCreate($tagLVITEM), $iResult, $tMemMap, $pMemory
    If @error Then Return SetError($LV_ERR, $LV_ERR, False)
    DllStructSetData($struct_LVITEM, "Mask", $LVIF_STATE)
    DllStructSetData($struct_LVITEM, "Item", $iIndex)
    DllStructSetData($struct_LVITEM, "StateMask", 0xffff)

    If IsHWnd($hWnd) Then
        If _WinAPI_InProcess($hWnd, $_lv_ghLastWnd) Then
            $iResult = _SendMessage($hWnd, $LVM_GETITEMA, 0, DllStructGetPtr($struct_LVITEM), 0, "wparam", "ptr") <> 0
        Else
            $pMemory = _MemInit($hWnd, DllStructGetSize($struct_LVITEM), $tMemMap)
            _MemWrite($tMemMap, DllStructGetPtr($struct_LVITEM))
            $iResult = _SendMessage($hWnd, $LVM_GETITEMA, 0, $pMemory, 0, "wparam", "ptr") <> 0
            _MemRead($tMemMap, $pMemory, DllStructGetPtr($struct_LVITEM), DllStructGetSize($struct_LVITEM))
            _MemFree($tMemMap)
        EndIf
    Else
        $iResult = GUICtrlSendMsg($hWnd, $LVM_GETITEMA, 0, DllStructGetPtr($struct_LVITEM)) <> 0
    EndIf

    If Not $iResult Then Return SetError($LV_ERR, $LV_ERR, False)
    Return BitAND(DllStructGetData($struct_LVITEM, "State"), 0x2000) <> 0
EndFunc   ;==>_GUICtrlListView_GetItemChecked

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#include <GuiListView.au3>
#include <Array.au3>

Run("control ncpa.cpl")
winwait("Network Connections")
winActivate("Network Connections")

send("local")
Send("!fr")

WinWait("Local Area Connection Properties")
WinActivate("Local Area Connection Properties")
Send("f")


$Hwnd = ControlGetHandle("Local Area Connection Properties", "", 16012)
$Count = _GUICtrlListView_GetItemCount($Hwnd)
$ItemIndexCount = _GUICtrlListView_GetSelectedCount($Hwnd)
If $ItemIndexCount = 1 Then
    $ItemIndex = _GUICtrlListView_GetSelectedIndices($Hwnd, False)
    $BoxText = _GUICtrlListView_GetItemText($Hwnd, $ItemIndex)
    ConsoleWrite($BoxText & @LF)
    ; Check to see if the check box is checked.
    $iStateImage = _GUICtrlListView_GetItemStateImage($Hwnd, $ItemIndex)
    If $iStateImage == 3 Then
        _GUICtrlListView_SetItemStateImage($Hwnd, $ItemIndex, 2)
    EndIf
EndIf


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#include <GuiListView.au3>
#include <Array.au3>

Run("control ncpa.cpl")
winwait("Network Connections")
winActivate("Network Connections")

send("local")
Send("!fr")

WinWait("Local Area Connection Properties")
WinActivate("Local Area Connection Properties")
Send("f")


$Hwnd = ControlGetHandle("Local Area Connection Properties", "", 16012)
$Count = _GUICtrlListView_GetItemCount($Hwnd)
$ItemIndexCount = _GUICtrlListView_GetSelectedCount($Hwnd)
If $ItemIndexCount = 1 Then
    $ItemIndex = _GUICtrlListView_GetSelectedIndices($Hwnd, False)
    $BoxText = _GUICtrlListView_GetItemText($Hwnd, $ItemIndex)
    ConsoleWrite($BoxText & @LF)
    ; Check to see if the check box is checked.
    $iStateImage = _GUICtrlListView_GetItemStateImage($Hwnd, $ItemIndex)
    If $iStateImage == 3 Then
        _GUICtrlListView_SetItemStateImage($Hwnd, $ItemIndex, 2)
    EndIf
EndIf

Share this post


Link to post
Share on other sites

Sorry about that last one. Thanks for the help on this one so far. Both sets of code do seem to be setting the checkbox on screen, but when I click OK in that window (or script it), the check mark is not sticking when I go back in to check the properties.

Any other ideas?

Thanks again for the help!

Share this post


Link to post
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
Sign in to follow this  
Followers 0