Jump to content

Error: Subscript used on non-accessible variable


Recommended Posts

I am working on an AutoIt script that will install the QuickLaunch toolbar to a user's desktop after they login to the network.  The compiled AutoitScript (AddQL.EXE) is run by a network VBS login script.  

When I run the AutoIt script by itself, it runs fine and give no errors.  When I manually run the VBS login script, the AutoIt script runs fine.  But when the user is actually logging in to the network and the login script is triggered, the AutoIt script gives an Error: Subscript used on non-accessible variable message, and the script fails.

Here is the AutoIt script for AddQL.EXE which I think properly handles the only array present ($oPosition):

#NoTrayIcon
;#RequireAdmin

Dim $strToolbarFolder, $oPosition[4], $AddRemove


$strToolBarFolder = "%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch"

; Disable user input from the mouse and keyboard
;BlockInput(1)
Sleep(500)
ControlFocus("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")

; Right click on the taskbar
$oPosition = ControlGetPos("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
;MsgBox (1,"oPosition[2] and [3]", "oPosition[2] = " & $oPosition[2] & " and oPosition[3] = " & $oPosition[3])
ControlFocus("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
ControlClick("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]", "secondary", 1, $oPosition[2], $oPosition[3])

; Sleep and send T to select the Toolbar and N for "New toolbar..."

Send("T")
Send("{RIGHT}")
Sleep(500)

Send("N")
Sleep(500)
; Wait for the "New Toolbar - Choose a folder" window
If Not WinWaitActive("New Toolbar - Choose a folder", "", 3) Then
   Exit 1
EndIf

; Lower send delays to speed up typing
Opt("SendKeyDelay", 1)
Opt("SendKeyDownDelay", 1)

; Type the name of the folder for the new toolbar
Send($strToolbarFolder)
; Set send delays to default values again
Opt("SendKeyDelay", 5)
Opt("SendKeyDownDelay", 5)

; Go to the folder and select the "Select Folder" button
Send("{ENTER}")
Sleep(500)
Send("{Tab}{ENTER}")

;Turn off text and titles for QL Toolbar
ControlFocus("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
$oPosition = ControlGetPos("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
;MsgBox (1,"oPosition(2) and (3)", "oPosition(2) = " & $oPosition[2] & " and oPosition(3) = " & $oPosition[3])
ControlFocus("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
;MsgBox (0,"oPosition(2) and (3)", "oPosition(2) = " & $oPosition[2] & " and oPosition(3) = " & $oPosition[3])
ControlClick("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]", "secondary", 1, $oPosition[2], $oPosition[3])
;ControlClick("[CLASS:Shell_TrayWnd]", "", "", "secondary", 1, $oPosition[2], $oPosition[3])
Send("x")
Sleep(200)
ControlClick("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]", "secondary", 1, $oPosition[2], $oPosition[3])
Send("w")
Send("{ENTER}")
Sleep(200)

; Enable user input from the mouse and keyboard
BlockInput(0)

Exit 0

 

And here is how I am calling it in the network VBS login script (Partial):

...

Sub FirstLogin
dim strQLFile 

strQLFile=EnvString("USERPROFILE")& "\AppData\Roaming\Microsoft\AddQL.exe"
If objFSO.FileExists(strQLFile) Then
    'objShell.Run strQLFile, 0, True
    objShell.Exec(strQLFile)
    objFSO.DeleteFile(strQLFile)
End If

End Sub

...

In the VBS script, the function EnvString simply gets the value of the %userprofile% variable from the local environment.  I have tried the VBS script using both the .Run and .Exec methods with no perceptible difference on the error message.

Can anyone shed any light on why this error message should be popping up under these circumstances?

TIA,

Peter Smick

Link to comment
Share on other sites

  • Moderators

Peter Smick,

Quote

I think properly handles the only array present ($oPosition)

I am afraid not - you are accessing the array elements without first testing that the array actually exists - which is why you get an error. When the script runs on log in, tit cannot find the position of the control - perhaps you need to Sleep a while before running the ControlGetPos line, or perhaps loop using WinExists until the Tray_Wnd is actually present.

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

1 hour ago, Melba23 said:

Peter Smick,

I am afraid not - you are accessing the array elements without first testing that the array actually exists - which is why you get an error. When the script runs on log in, tit cannot find the position of the control - perhaps you need to Sleep a while before running the ControlGetPos line, or perhaps loop using WinExists until the Tray_Wnd is actually present.

M23

Good thought.  I will certainly try the sleep and other suggestions you made and will report back.

Thanks,

Peter.

Link to comment
Share on other sites

  • Moderators

Peter Smick,

By all means. But when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

M23

 

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Excellent.  WinWaitActive did the trick.  This script is really used only the first time someone logs into the network, and it takes much longer than the normal login to create the new user's profile.  I had forgotten about this timing issue.  Thank you so much.

Can I ask whether you saw the earlier post about this same script titled Manipulating the Windows 10 Taskbar?  There I asked if anyone had any ideas about how to reposition the dividing bar between the QuickLaunch Toolbar and the rest of that taskbar, or differently, how to move the QL toolbar all the way to the left.  If you had any thoughts on that, I would be doubly forever indebted.

 

Peter

Edited by Peter Smick
Link to comment
Share on other sites

  • Moderators

Peter Smick,

Glad I could help.

How would you move the QL toolbar to where you wish it to be if you were to do it yourself?

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

When the QL Toolbar is installed on the taskbar and the taskbar is unlocked, a small vertical divider bar appears separating the main taskbar from the QL Toolbar.  (If multiple toolbars are installed, then they are separated from each other by a similar divider.)  When the QL Toolbar is first installed, it appears on the right end of the taskbar. 

To adjust it manually, I would grab its divider bar with a mouse and slide it all along the taskbar to the left until the QLToolBar and the main taskbar "switch places".  At this point the QL Toolbar is very wide and so I would next grab the Main Taskbar's divider and drag it some distance to the left to effectively shorten the QL Toolbar.

Assuming that my script above has correctly identified the QL Toolbar as a control on the Taskbar (and that it is in fact a control), I have tried to use ControlMove to relocate it within the Taskbar "window" but the command does not seem to do anything.  Also, using AutoInfo,  position info does not seem to change when I manually move the QL Toolbar divider or move the toolbar manually.  I have also not had any luck recording a mouse-based script, and would prefer not to have to rely on a mouse for this.

This is as far as my thinking has taken me so far.

Peter

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...