Jump to content
Sign in to follow this  
jack71

Autoit error: Variable subscript badly formatted, need help figuring this one out...

Recommended Posts

jack71
Having a problem with the error code: Variable subscript badly formatted, specifically concerning the following:
 
$usbloc = $AMyDriveLabels[$eIndex][0].
 
This script searches the machine for a secure flash drive (encrypted) that will be known as "ENCRYPTED FLASH DRIVE".  I need to unencrypt this flash drive and get the drive letter of the unencrypted flash drive for further functions.  If I unencrypt the drive prior to running this, it has no errors and gives me the location perfectly.  The problem occurs when I have the script unencrypt the drive then search for it.  It unencrypts the drive fine, verified by going to My Computer and going into the drive.  For whatever reason though it chucks up the error:  Variable subscript badly formatted @ line 28.  What am I missing here???
 
#include <Array.au3>
#include <File.au3>
#include <date.au3>

Global $ip = "localhost"
Global $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2")
Global $usbloc

USBStatus()

Func USBStatus()
;;;;;;Main Code Provided By: UEZ, big thanks!;;;;;

Local $aMyDriveLabels, $eIndex, $iIndex
If $CmdLine[0] > 0 Then $ip = $CmdLine[1]

$aMyDriveLabels = GetWMI($ip)
If IsArray($aMyDriveLabels) Then $iIndex = _ArraySearch($aMyDriveLabels, "ENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)

If @error Then ; No USB found inserted in the machine with Volume Name: ENCRYPTED FLASH DRIVE
msgbox(0, "NO USB IN", "LINE 21, NO USB INSERTED")
Exit
ElseIf Not @error Then ; FOUND USB with Volume Name: ENCRYPTED FLASH DRIVE DRIVE
$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)
    If @error Then ; DRIVE MUST BE STILL ENCRYPTED, RUN LOGIN FUNCTION TO UNENCRYPT FLASH DRIVE
        Login()
        $eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)
*******>$usbloc = $aMyDriveLabels[$eIndex][0]<********
        msgbox(0, "LOGGED IN AND FOUND", "LINE 29, LOGGED IN FLASH DRIVE AND FOUND IT AT: " & $usbloc)
        Exit
    ElseIf Not @error Then ; DRIVE ALREADY UNENCRYPTED, NOTHING TO DO
        $usbloc = $AMyDriveLabels[$eIndex][0]
        msgbox(0, "DRIVE ALREADY UNENCRYPTED", "DRIVE IS ALREADY UNENCRYPTED AND LOCATED AT: " & $usbloc)
        Exit
    EndIf
EndIf
EndFunc


Func GetWMI($srv)
    Local $DriveLabel, $sDriveLabels, $i
    Local $aDriveLabels[26][2]
    $colItems = $objWMIService.ExecQuery("SELECT Name, VolumeName FROM Win32_LogicalDisk", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $aDriveLabels[$i][0] = $objItem.Name
            $aDriveLabels[$i][1] = $objItem.VolumeName
            $i += 1
        Next
    EndIf
    ReDim $aDriveLabels[$i][2]
    Return $aDriveLabels
EndFunc

 

Share this post


Link to post
Share on other sites
UEZ

This seems to be the problem

 

$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)
        If @error Then ; DRIVE MUST BE STILL ENCRYPTED, RUN LOGIN FUNCTION TO UNENCRYPT FLASH DRIVE
            Login()
            $usbloc = $aMyDriveLabels[$eIndex][0]
 

because if _ArraySearch fails and error is set then the result is probably one of the values between -1 to 6 (I assume $eIndex is -1).

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
jchd

Looks like a logic error to me.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jack71

This seems to be the problem

 

$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)
        If @error Then ; DRIVE MUST BE STILL ENCRYPTED, RUN LOGIN FUNCTION TO UNENCRYPT FLASH DRIVE
            Login()
            $usbloc = $aMyDriveLabels[$eIndex][0]
 

because if _ArraySearch fails and error is set then the result is probably one of the values between -1 to 6 (I assume $eIndex is -1).

Br,

UEZ

 

 

UEZ, you are correct it is -1.  I understand why ArraySearch fails...the drive is still encrypted.  What I don't understand is when the drive is unencrypted (after the login() function is ran) how come when ArraySearch is performed again it still fails?  In fact I've tried While loops such as:

$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)
    If @error Then ; DRIVE MUST BE STILL ENCRYPTED, RUN LOGIN FUNCTION TO UNENCRYPT FLASH DRIVE
        Login()
While 1
$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)
     If @error Then
     $usbloc = "encrypted"
     sleep(1000)
     ElseIf Not @error Then
     $usbloc = $aMyDriveLabels[$eIndex][0]
     ExitLoop
     EndIf
WEnd

For whatever reason $EIndex is always -1 and never updates.  Even after unencrypting the drive.  However if I start the script over after it attempts the first time and Login(), I get no error.  $eIndex is then found.  :/

Edited by jack71

Share this post


Link to post
Share on other sites
UEZ

Try a 

_ArrayDisplay($aMyDriveLabels)

before

$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)

to see the content of the array. Maybe you can post the content.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
jack71

Try a 

_ArrayDisplay($aMyDriveLabels)

before

$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED FLASH DRIVE", 0, 0, 0, 0, 1, 2)

to see the content of the array. Maybe you can post the content.

Br,

UEZ

 

Row|Col 0|Col 1
[0]|C:|
[1]|D:|Storage
[2]|E:|Audio CD
[3]|F:|Secure+
[4]|G:|
 

Secure+ is the encrypted drive.  G: will be the drive after it is unencrypted.

Share this post


Link to post
Share on other sites
jack71

Interesting to note, i put _ArrayDisplay($aMyDriveLabels) in a While loop after the Login() function and it still Displays G: as empty or nothing there.  However I can go to My Computer and G: has a VolumeName and I can access it.  GRRRR!!!

Share this post


Link to post
Share on other sites
UEZ

Maybe you put a Sleep(1000) just after Login(). Maybe the script is too fast.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
jack71

Maybe you put a Sleep(1000) just after Login(). Maybe the script is too fast.

Br,

UEZ

 

Tried that, and just tried it again.  However I used sleep(10000).  For whatever reason, the $eIndex variable that does the arraysearch will not update.  I guess I could just have it EXIT after the Login() and relaunch itself :P.

Share this post


Link to post
Share on other sites
jack71

OK I'm back....

Never would have thought to do this but it seems to work:

$eIndex = _ArraySearch($aMyDriveLabels, "UNENCRYPTED DRIVE", 0, 0, 0, 0, 1, 2)
    If @error Then ; DRIVE MUST BE STILL ENCRYPTED, RUN LOGIN FUNCTION TO UNENCRYPT FLASH DRIVE
        Login()
        Sleep(3000)
        USBStatus()

If I make it restart the function USBStatus() it then finds the unencrypted drive location and no ERRORS.  I still don't understand why it arraysearch can't be updated?

Share this post


Link to post
Share on other sites
AdmiralAlkex

You only do the second _ArraySearch() if the first one fails, and you DON'T update the array between so of course the second one fails too. At the very least you're going to have to update or reload $aMyDriveLabels after Login().

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  

×