Jump to content

Recommended Posts

Posted

I decided to automate the process of logging into 12 DMS100 switches at work via telnet using SmarTerm. I successfully wrote a script that did this for each switch individually so now for further practice I am trying doing the same thing using an array.

However, I have found myself in a situation where I am using sort of a dual array (if I can describe it as such) and I would like to get your input on whether or not I am proceeding correctly.

When I attempt to run the script, the telnet session for the first switch will open but the log in process will not take place and the script will not proceed beyond that. Can I use two separate arrays in a script like this?

Global $arr[12], $name[12]

$arr[0]="C:\Users\User\Desktop\DMS\switch1.stw"
$arr[1]="C:\Users\User\Desktop\DMS\switch2.stw"
$arr[2]="C:\Users\User\Desktop\DMS\switch3.stw"
$arr[3]="C:\Users\User\Desktop\DMS\switch4.stw"
$arr[4]="C:\Users\User\Desktop\DMS\switch5.stw"
$arr[5]="C:\Users\User\Desktop\DMS\switch6.stw"
$arr[6]="C:\Users\User\Desktop\DMS\switch7.stw"
$arr[7]="C:\Users\User\Desktop\DMS\switch8.stw"
$arr[8]="C:\Users\User\Desktop\DMS\switch9.stw"
$arr[9]="C:\Users\User\Desktop\DMS\switch10.stw"
$arr[10]="C:\Users\User\Desktop\DMS\switch11.stw"
$arr[11]="C:\Users\User\Desktop\DMS\switch12.stw"

$name[0]="switch1"
$name[1]="switch2"
$name[2]="switch3"
$name[3]="switch4"
$name[4]="switch5"
$name[5]="switch6"
$name[6]="switch7"
$name[7]="switch8"
$name[8]="switch9"
$name[9]="switch10"
$name[10]="switch11"
$name[11]="switch12"

For $a = 0 To 11

    ShellExecute($arr[$a])
    WinWaitActive ("SmarTerm - [$name[$a]]")
Send ("Username")
Send ("{ENTER}")
Send ("Password")
Send ("{ENTER}")

Next

Posted

I see nothing wrong with your script. Maybe it hangs on WinWaitActive. Add

AutoItSetOption("TrayIconDebug", 1)

to your script.
When you move the mouse over the tray icon the currently executed statement will be displayed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
3 minutes ago, water said:

I see nothing wrong with your script. Maybe it hangs on WinWaitActive. Add

AutoItSetOption("TrayIconDebug", 1)

to your script.
When you move the mouse over the tray icon the currently executed statement will be displayed.

Thanks for your speedy response. Should I add this command at the very end of my script?

Posted

No, ad it at the top of your script.

BTW: Please press the reply button not the quote button. The thread gets longer and longer by quoting posts and ends unreadable ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
1 hour ago, nemo1478 said:

WinWaitActive ("SmarTerm - [$name[$a]]")

Change this to this.

WaitActive ("SmarTerm - [" & $name[$a]& "]")

See if that works.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)

The name of the first Window is "SmarTerm - [switch1]" (including the brackets)?
Seems I was blind - BrewManNH found the bug :)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Yes the window name includes those square brackets. I edited the script as suggested by BrewManNH and it works now. I guess the double brackets is a no no. Never would have figured that one out. Thanks guys!

Posted
2 minutes ago, nemo1478 said:

I guess the double brackets is a no no.

No, the problem was that you were using the literal string of the array name instead of using the contents of the array element. My code separates the strings from the variables.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted
3 minutes ago, BrewManNH said:

No, the problem was that you were using the literal string of the array name instead of using the contents of the array element. My code separates the strings from the variables.

Oh I see what you're saying now. Shouldn't I have gotten a similar error at the ShellExecute command? Didn't I also use the literal expression there?

Posted
7 minutes ago, nemo1478 said:

Shouldn't I have gotten a similar error at the ShellExecute command? Didn't I also use the literal expression there?

No, in that command, you used the array variable's name but it's not enclosed in quotes so it's not a string.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted
5 minutes ago, BrewManNH said:

No, in that command, you used the array variable's name but it's not enclosed in quotes so it's not a string.

I understand. Thanks to everyone who contributed.

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
×
×
  • Create New...