Ignoring GetTreeNode with multiple entries of the same name

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
GerryB
Newbie
Posts: 7
Joined: Tue Jul 18, 2006 8:29 am

Ignoring GetTreeNode with multiple entries of the same name

Post by GerryB » Tue Jul 18, 2006 8:54 am

I am trying to set the DVD Region of all drives present on a machine. Some machines will have multiple drives of the same type, and I can't figure out how to set the region on the first one, and remove it from the GetTreeNode results of subsequent searches.

Here is the code I have so far.. I have broken it several times trying to figure it out so I know I have some repair work to do... but it is the generally working code I have so far.

I have it reading a DVD.ini file located in %filepath% for the device name, searching for the device in device manager, and moving to the next line in the ini if that drive it is not found. If it is found it will set the DVD region for that drive and then re-read the same line in the ini to search for extra drives of the same name. The problem I am facing is it always finds the location of the first drive of that name, and I do not know how to ignore those results.

Currently I have it set to run on XP, but will be using the systempath variable to make it functional on W2K and XP.

Also, I think I am mis-understanding the GetTreeNode results
"GetTreeNode>WindowTitle,ClassName,Instance,Text,Case,Partial,Result,Handle"
Specifically, "Result: Gets set to the zero based index of the item or -1 if not found."

What is the zero based index? In my code am I using this result properly?

Thanks in advance for any suggestions you may have.

Code: Select all

Let>iniline=0
let>filepath=c:\configfile\
let>systempath=c:\windows\system32

gosub>Sub_StartDM
gosub>Sub_SelectDVD
gosub>Sub_Get_Drive_Location


SRT>Sub_StartDM
ExecuteFile>%systempath%\devmgmt.msc
wait>delay
WaitWindowOpen>Device Manager
wait>1
SetFocus>Device Manager
Press Tab
Wait>1
END>Sub_StartDM

SRT>Sub_SelectDVD
GetTreeNode>Device Manager,SysTreeView32,0,DVD/CD-ROM drives,1,0,DVD_CD,Handle
//MessageModal>%result% and handle  %handle%
//set %result% as variable
Let>DVD_Parent=%DVD_CD%
//MessageModal>%DVD_Parent%
if>Result=-1
WriteLn>%filepath%\logfile.txt,,Failure:DVD/CD-Rom drop down box not found
endif
wait>delay
Press Home
Press Down * %DVD_Parent%
Press Right
wait>delay
END>Sub_SelectDVD


SRT>Sub_Get_Drive_Location
Label>Get_Drive_Locations
Let>iniline=iniline+1
ReadLn>%filepath%\DVD.ini,%iniLine%,drivename
If>drivename=##EOF##,Done
//go to label>Done
ENDIF
Let>Drive_Name=%drivename%
GetTreeNode>Device Manager,SysTreeView32,0,%Drive_Name%,1,0,Drive_Location,Drive_Handle
//messagemodal>%Drive_Location% %Drive_Handle%
IF>%Drive_Location%=-1
Goto>Get_Drive_Locations
ELSE
     IF>%Drive_Location%<0>Distance_From_Parent=%Drive_Location%-%DVD_Parent%
     //MessageModal>%Distance_From_Parent%
     EndIF
     IF>%Drive_Location%=0
	 //Drive name not found
     ELSE
	      IF>%Drive_Handle%=%Previous_Handle%
	      goto>Get_Drive_Locations
	      //need to ignore this drive
	      ELSE
	      wait>delay
          Press Down * %Distance_From_Parent%
          gosub>Sub_Drive_Selected
	      ENDIF
     ENDIF
ENDIF
goto>Get_Drive_Locations
END>Sub_Get_Drive_Location

SRT>Sub_Drive_Selected
wait>1
Press Enter
wait>1
WaitWindowOpen>%Drive_Name% Properties*
wait>1
SetFocus>%Drive_Name% Properties*
wait>delay
Press CTRL
wait>1
Press Tab
wait>1
Press Tab
wait>1
Release CTRL
wait>delay
Send Character/Text>U
wait>delay
Send Character/Text>n
wait>delay
Send Character/Text>i
wait>delay
Send Character/Text>t
wait>delay
Send Character/Text>e
wait>delay
Send Character/Text>d
wait>delay
Send Character/Text> 
wait>delay
Send Character/Text>S
wait>delay
Send Character/Text>t
wait>delay
Press Enter
wait>1
PushButton>DVD Region Change*,OK
wait>1
IfWindowOpen>DVD Region Change Error,RegionFailure,NoFailure
Label>RegionFailure
WriteLn>%filepath%\logfile.txt,,Failure:%Drive_Name% Region not set -- needs DVD media
PushButton>DVD Region Change Error,OK
wait>1
PushButton>Properties*,Cancel
wait>1
Let>Previous_Handle=%Drive_Handle%
Let>iniline=iniline-1
gosub>Sub_Get_Drive_Location

Label>NoFailure
PushButton>Properties*,OK
wait>1
Let>Previous_Handle=%Drive_Handle%
WriteLn>%filepath%\logfile.txt,,Success:%Drive_Name% Region set
Let>iniline=iniline-1
gosub>Sub_Get_Drive_Location
End>Sub_Drive_Selected

Label>Done
CloseWindow>Device Manager

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 21, 2006 3:03 pm

GerryB,

I tried running through your code to see what it was doing and you are correct, it is broken. You are not using the If> statement correctly in a couple of places. You are also using variables that have not been defined. But those problems can wait. First, there's no way to debug this without seeing the ini file you call: C:\configfile\dvd.ini. The script sort of works up to the point where you take info from that file. If there is something private about the info, can you at least post something generic that is in the same format?

Later,
Dick

GerryB
Newbie
Posts: 7
Joined: Tue Jul 18, 2006 8:29 am

Post by GerryB » Sat Jul 22, 2006 7:43 am

The DVD.ini file contains the model name as it appears in device manager of all the drives that need to be configured in our environment, each device name is listed on a new line. For instance "LITE-ON DVDRW SOHW-S" is on line one, and "HL-DT-SR DVD 4242" is on line two, and etc. I expect the ini file in our environment to grow to several dozen or hundred device names, but only have two or three devices in each machine.

One caveat you may experience.. some drives require a DVD disc to be present to set the region, also **IMPORTANT** when debugging, do not have it set the region to anything but the one you actually use, such as region 1 for USA, as the drive will lock out after a certain amount of changes and be stuck on the last region set. It won't be a problem setting it multiple times to the same region as it doesn't actually make a change, but you won't see the "PushButton>DVD Region Change*,OK" line as neccessary,since that only shows up the first time th region is set.


I have the code working flawlessly when all of the DVD devices in the machine are named differently, but when I have the same drive model in the machine multipel times it will only configure the first one that appears with that name. I will post updated code later this morning, which I have cleaned up slightly and added some error checking. Also it appears the code did not post exactly as I have it, such as

Code: Select all

ELSE
     IF>%Drive_Location%<0>Distance_From_Parent=%Drive_Location%-%DVD_Parent%
should be
"
ELSE
IF>%Drive_Location%0
Let>Distance_From_Parent=%Drive_Location%-%DVD_Parent%
"
Looks like I have to disable HTML in the post for the snippet to show up corrently. I will do this when I post my latest revision.

I thought I may have flaws in my IF statements, but where do I have undefined variables? Perhaps I am confused on how to define/initialize those. I found my variables %Drive_Handle% and %Previous_Handle% were not performing as I thought they did... they provide the result of the "device manager" windows handle.. not a handle of the gettreenode> item I searched for.. oops. I've cleaned that up in my new code..

Thank you for looking into this, I really appreciate it as I have a lot to learn.

Gerry

GerryB
Newbie
Posts: 7
Joined: Tue Jul 18, 2006 8:29 am

Post by GerryB » Sat Jul 22, 2006 10:22 pm

Here is my latest code

Code: Select all

Let>iniline=0
let>filepath=c:\winnt\custom
let>systempath=c:\winnt\system32

gosub>Sub_StartDM
gosub>Sub_SelectDVD
gosub>Sub_Get_Drive_Location


SRT>Sub_StartDM
ExecuteFile>%systempath%\devmgmt.msc
wait>delay
WaitWindowOpen>Device Manager
wait>1
SetFocus>Device Manager
Press Tab
Wait>1
END>Sub_StartDM

SRT>Sub_SelectDVD
GetTreeNode>Device Manager,SysTreeView32,0,DVD/CD-ROM drives,1,0,DVD_CD,DVD_CD_Handle
//MessageModal>%DVD_CD% and handle  %DVD_CD_Handle%
//set %result% as variable
Let>DVD_Parent=%DVD_CD%
//MessageModal>%DVD_Parent%
if>Result=-1
  WriteLn>%filepath%\logfile.txt,,Failure:DVD/CD-Rom drop down box not found
endif
wait>delay
Press Home
Press Down * %DVD_Parent%
Press Right
wait>delay
END>Sub_SelectDVD


SRT>Sub_Get_Drive_Location
Label>Get_Drive_Locations
Let>iniline=iniline+1
ReadLn>%filepath%\DVD.ini,%iniLine%,drivename
If>drivename=##EOF##,Done
  //go to label>Done
ENDIF
If>drivename=##NOFILE##
  WriteLn>%filepath%\logfile.txt,,Failure:ini config file not found
ENDIF
Let>Drive_Name=%drivename%
GetTreeNode>Device Manager,SysTreeView32,0,%Drive_Name%,1,0,Drive_Location,Drive_Handle
//Drive_Handle is actually the handle of the Device Manager window, not the Drive_Name location...
//messagemodal>Drive_location is %Drive_Location% and Drive_Handle is %Drive_Handle%
IF>%Drive_Location%=-1
  Goto>Get_Drive_Locations
ELSE
     IF>%Drive_Location%<>0
	   Let>Distance_From_Parent=%Drive_Location%-%DVD_Parent%
       //MessageModal>distance from parent %Distance_From_Parent%
     EndIF
     IF>%Drive_Location%=0
	   //Drive type of %Drive_Name% not found
     ELSE
	      //IF>%Drive_Handle%=%Previous_Handle%
		    //need code to ignore previous drives here
		    //Drive_Handle is %Drive_Handle% Previous_Handle is %Previous_Handle%
	        //goto>Get_Drive_Locations
	        //need to ignore this drive
	        //ELSE
	      wait>delay
          Press Down * %Distance_From_Parent%
          gosub>Sub_Drive_Selected
	        //ENDIF
     ENDIF
ENDIF
goto>Get_Drive_Locations
END>Sub_Get_Drive_Location

SRT>Sub_Drive_Selected
wait>1
Press Enter
wait>delay
WaitWindowOpen>%Drive_Name% Properties*
wait>delay
SetFocus>%Drive_Name% Properties*
wait>delay
Press CTRL
wait>delay
Press Tab
wait>delay
Press Tab
wait>delay
Release CTRL
wait>delay
Send Character/Text>u
wait>delay
Send Character/Text>n
wait>delay
Send Character/Text>i
wait>delay
Send Character/Text>t
wait>delay
Send Character/Text>e
wait>delay
Send Character/Text>d
wait>delay
Send Character/Text> 
wait>delay
Send Character/Text>s
wait>delay
Send Character/Text>t
wait>delay
Press Enter
wait>1
Let>WW_TIMEOUT=3
WaitWindowOpen>DVD Region Change
If>WW_RESULT=FALSE
  //DVD Region Change window did not open, Region previously set or script hung
  //need to use static "Current Region" field to determine this and abort before we get here
  //for now we will continue as if region was previously set
  WriteLn>%filepath%\logfile.txt,,CheckDrive:%Drive_Name% region previously set or error in script.
  IfWindowOpen>%Drive_Name% Properties*
    //Properties window did not close as would be expected if region previously set, drive failed
    WriteLn>%filepath%\logfile.txt,,Failure:%Drive_Name% region not set - unexpected window handling
	SetFocus>%Drive_Name% Properties*
	PushButton>%Drive_Name% Properties*,Cancel
  ENDIF
  wait>delay
  Press Left
  wait>delay
  //Let>Previous_Handle=%Drive_Handle%
  //Let>iniline=iniline-1
  //re-enable last line when multi-drives are supported
  gosub>Sub_Get_Drive_Location
ENDIF

wait>1
PushButton>DVD Region Change,OK
wait>1
IfWindowOpen>DVD Region Change Error
  PushButton>DVD Region Change Error,OK
  wait>delay
  WriteLn>%filepath%\logfile.txt,,Failure:%Drive_Name% region not set
  PushButton>%Drive_Name% Properties*,Cancel
  wait>delay
  Press Left
  wait>delay
  //Let>Previous_Handle=%Drive_Handle%
  //Let>iniline=iniline-1
  //re-enable last line when multi-drives are supported
  gosub>Sub_Get_Drive_Location
EndIF
PushButton>%Drive_Name% Properties*,OK
wait>delay
Press Left
wait>delay
WriteLn>%filepath%\logfile.txt,,Success:%Drive_Name% Region set
//Let>Previous_Handle=%Drive_Handle%
//Let>iniline=iniline-1
//re-enable last line when multi-drives are supported
gosub>Sub_Get_Drive_Location
End>Sub_Drive_Selected

Label>Done
CloseWindow>Device Manager

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jul 24, 2006 2:39 pm

GerryB,

It appears the bad if> statements were due to posting with HTML enabled.

You still have an undefined variable: "delay". However, if the script is working without defining "delay" perhaps you don't need those waits.

Here are the first few lines of your script with some comments in red. Sounds like you have it working?


//You have wait>delay specified multiple times but you have not
//assigned a value to "delay"
//eg.
Let>delay=0.5

Let>iniline=0
let>filepath=c:\winnt\custom

//Macro Scheduler has a built in variable for the system directory "SYS_DIR"
//or you could use the environment variable "windir" with system32
//eg.
//GetEnvVar>windir,systempath
//Concat>systempath,\system32
//This makes the script portable between operating systems.

//let>systempath=c:\winnt\system32
Let>systempath=%SYS_DIR%


Later,
Dick

GerryB
Newbie
Posts: 7
Joined: Tue Jul 18, 2006 8:29 am

Post by GerryB » Tue Jul 25, 2006 5:37 pm

Thanks, I did not know I had to define delay, I thought that was built in as I had seen it in some other code posted here and it was not defined.

Thanks for the SYS_DIR tip, I had found that little gem the other day in the help file, as this code will have to be portable..

But no, I have not yet gotten it fully functional.. still having trouble finding/setting the second drive of the same name. Is there any way to extract all of the text within a listbox, to analyze at a later time?

Thanks,
Gerry

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts