Sign in to follow this  
Followers 0
cheeseslice

Could someone help me tidy my script up please

1 post in this topic

Hi,

Could anyone just give me an idea how I can avoid duplicating some of my code, if it is possible.

What I am doing is selecting the first computer name in a text file, logging onto this machine using vncviewer, looping through each computer in the text file then going back to the beginning and going through the list again except this time I want to run an application. The reason for logging them all on then going back is to give it enough time to log on as I can't find a way to get autoscript to realise this through vncviewer.

I have this working but I have had to repeat the code to loop through the text file and just wondered how I could avoid this.

my code so far:

TCPStartup()

$textfile = "room1.txt"

$roomFile = FileOpen($textfile,0)

$i=1

$password = InputBox("Vnc Password","Please enter the vnc server password","","*")

$port = InputBox("Port Number","Please change port number if necessary","1090")

$username = InputBox("Username to logon with","Please enter username for workstations")

$userpassword = InputBox("Password","Please enter password for this username")

If $roomFile = -1 Then ; if the text file containing the computer names does not exist

MsgBox(0, "Error", "The Text File Does Not Exist")

Exit

EndIf

While 1

$computerName = FileReadLine($roomFile,$i) ;read the first computer name from the text file

If @error = -1 Then ExitLoop

;MsgBox(0, "Testing - Computername", $computerName)

$i = $i + 1

Call("vnc")

Wend

Sleep(20000) ;sleep after it has logged the user onto every machine

;MsgBox(0,"testing vnc finished","")

FileClose($roomFile)

$install = FileOpen($textfile,0)

while 1

$computerName = FileReadLine($install,$i)

If @error = -1 Then ExitLoop

msgBox(0, "testing 2nd time looping to run application", $computerName); application will run here instead

$i = $i + 1

WEnd

FileClose($install)

Func vnc()

$ip= TCPNameToIP($computerName) ;obtain ip address of computername for vnc viewer title

WinMinimizeAll()

$computernamelower=StringLower($computerName) ;convert computername to lowercase for vnc viewer title

Run("C:\Program Files\UltraVNC\vncviewer.exe " &$computerName & ":" &$port & " /password " &$password)

WinWaitActive($computernamelower &" ( "&$ip &" )")

send($username)

send("{tab}")

send($userpassword)

send("{enter}")

WinClose($computernamelower &" ( "&$ip &" )")

EndFunc

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