Sign in to follow this  
Followers 0
ctyankeeinok

Problem with GetText in ControlTreeView on Windows 7

11 posts in this topic

#1 ·  Posted (edited)

I am trying to use the GetText option in the ControlTreeView function on the Device Manager. The intention of the code is to go through the entries until the desired device is found. The code traverses the tree view with no problems, but when I attempt the GetText, an error is returned with no results. How do I make GetText work? I have done this before on XP with no problem, but I have either made a dumb mistake or GetText operates differently on Windows 7.

I simplified this example to just look for a common USB Input Device.

$strDevice = "USB Input Device"
$foundDevice = False
Run("mmc devmgmt.msc")
WinWaitActive("Device Manager")

ControlFocus("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]")

; Device may appear in Root, Other Devices, or Ports, Keyboard, or somewhere else... We will look in each category
$tcount = ControlTreeView("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]","GetItemCount","#0")
MsgBox(0,"tcount","Node Count: "& $tcount)
for $x = 0 To ($tcount - 1) step 1
ControlTreeView("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]","Expand","#0|#"&$x)
$count = ControlTreeView("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]","GetItemCount","#0|#"&$x)
$text = ControlTreeView("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]","GetText","#0|#"&$x)
MsgBox(0,"count","Sub Item count: " & $count & " Node: " & $text)
for $i = 0 to ($count - 1) step 1
$text = ControlTreeView("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]","GetText","#0|#"&$x&"|#"&$i)
$errvar = @error
MsgBox(0,"Error or Text?", "Node/SubItem: " & $x &"/" & $i & " Error: " & $errvar & " Text: " & $text)
if @error = 1 Then
ExitLoop
Else
if StringInStr($text,$strDevice) > 0 Then
$foundDevice = True
ControlTreeView("Device Manager","Device Manager on local computer","[CLASSNN:SysTreeView321]","Select","#0|#"&$x&"|#"&$i)
ExitLoop 2 ; found it, now exit both loops
EndIf
EndIf
Next
Next
Edited by ctyankeeinok

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think I figured it out, but it presents another question. I was testing the script by using F5 (Go), in my SciTE editor. Apparently it runs the script as x86 and not x64. If I compile the script as x64, it works properly. So, my question now becomes, how do I get SciTE to run it as x64? I am running SciTE 3.2.0 from June 9, 2012.

Edited by ctyankeeinok

Share this post


Link to post
Share on other sites

And, to answer my own question again, I need to put the following at the top of my script.... Argh... I sure wish SciTE defaulted to x64. Someone please correct me if I am heading down the wrong path. Hopefully this helps someone else as well....

#AutoIt3Wrapper_UseX64=Y

Share this post


Link to post
Share on other sites

Thanks JohnOne. That is pretty interesting, but I am trying to solve a different problem. I am installing devices and I have to finish their configuration via Device Manager. So, I have to find them in the tree view and then update drivers, change ports, etc.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think I figured it out, but it presents another question. I was testing the script by using F5 (Go), in my SciTE editor. Apparently it runs the script as x86 and not x64. If I compile the script as x64, it works properly. So, my question now becomes, how do I get SciTE to run it as x64? I am running SciTE 3.2.0 from June 9, 2012.

Thank you for your post. I tried to replicate but I won't get it to work on Windows 7. Did you really figured it out? I can't get your code to work on windows7 no matter what but it works nicely on winXp. I use your code because it's an excellent simple test for the ctrlTreeView. I also tried _GuiCtrlTreeView_GetText with the same result. It won't return anything. I placed #AutoIt3Wrapper_UseX64=Y and tried to install AutoIt with both option 32/64 bits native. I also did check the x64 box in the compile window. Nothing works. I am using the latest version 3.3.10.2. Any Idea, when you said you firuire it out, are you actually able to get the text and the item count? Thank You in advance.

Edited by giogio3

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

giogio3, The code in first post works for me on Win 7 64 bit and AutoIt 3.3.10.2.

If you are running af 64 bit Windows you must run AutoIt scripts that deals with the operating system as 64 bit programs (x64).

You don't have to compile the script to test it. Just right click and run the script as a x64 program.

I have also tried to run the script as a 32 bit (x86) program on a 64 bit Win 7. Then I get empty text strings.

Edited by LarsJ

Share this post


Link to post
Share on other sites

Thank You so much. It is now partially resolved.

Your hint made me try different directions: I noticed that the run command was not working ( I had to start the devmgmt manually).

I found that I had to compile in x64 and then run it as administrator.

A question still remains:

 Can you confirm, as I see, that I cannot debug the code under the script editor? It runs without doing anything Exiting with code:0 even if I add as a very fist line ConsoleWrite("test").

In fact even a one line only code that says ConsoleWrite("test") or has MsgBox(0,"x","y") will not do anything in the script editor but will return exit code : 0 ( but runs as script correctly).

Where am I doing something wrong?

Also for the controlTreeView will I need to debug it with trial and errors by running the compiled version?

I am available to it but I would like to know if this is the only approach I can use.

Thank You!

Share this post


Link to post
Share on other sites

I just downloaded the script. Double clicked. And it was running. On XP 32 bit and Win 7 64 bit. I have administrator rights on Win 7. I have not compiled. There is absolutly nothing wrong with this script. I can debug the code under the Scite script editor as much as I want. No problems at all.

Share this post


Link to post
Share on other sites

Thank You! Much easier to debug when you know what the outcome must be. So I dag deeper and found out the reason:

I must run SciTE as Administrator! ( I changed its properties to always do it ).

See: http://windowssecrets.com/forums/showthread.php/152923-Difference-between-Run-as-administrator-vs-being-logged-in-as-admin

I guess you all knew that already.. but me.. I am new to x64 ms stuff.

Ciao

G

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