Jump to content

need help looping a script


Recommended Posts

here's the situation. My script is meant to log a user into a program, perform a couple of functions, then log them out... then go to another user and repeat it

I have it already so the script logs the user in to the program, does the functions, then logs him out. Other than copy and pasting the the script 120 times and changing the user name in each instance, is there a way to pull the username from a set list, then perform the functions, log out, get the next name on the list and go again, then repeat the list once it is done?

if so, how? thanks. feel free to email me at hulksmash90@hotmail.com with any answers.

Link to comment
Share on other sites

Try RunAsSet to re-run your script with that user's permissions without logging on and off each time. As for users list, try enumerating the folders in C:\Documents And Settings\ You may get a bad apple in that bunch, but it is the closest thing I know of.

Who else would I be?
Link to comment
Share on other sites

Try RunAsSet to re-run your script with that user's permissions without logging on and off each time. As for users list, try enumerating the folders in C:\Documents And Settings\ You may get a bad apple in that bunch, but it is the closest thing I know of.

<{POST_SNAPBACK}>

No No No, the point is to log in as a specific user, ie. John314, to a specific program that requires that users id and password, not a windows login. Say for example... Logging in to.. an online video game. It askes for user id, (script inserts it) then password (script inserts it) then does what it needs to do... then logs that user out. Then it starts the program back up logs in a different user (user #2 down the list of users), does what it needs to do, logs out, then goes on to #3 does what it needs to do. continues doing that for all 120 users... then repeats the entire list again, logging in John314 to do it's business, log out, log in user #2 and so on...

I can always have it copied and pasted 120 times and fill in the user names on each instance by hand... but that's the pain in the ass I was hoping to avoid.

Link to comment
Share on other sites

  • Developers

No No No, the point is to log in as a specific user, ie.  John314, to a specific program that requires that users id and password, not a windows login.  Say for example...  Logging in to.. an online video game.  It askes for user id, (script inserts it)  then password (script inserts it)  then does what it needs to do... then logs that user out.  Then it starts the program back up logs in a different user (user #2 down the list of users), does what it needs to do, logs out, then goes on to #3  does what it needs to do.  continues doing that for all 120 users... then repeats the entire list again, logging in John314 to do it's business, log out, log in user #2 and so on...  

I can always have it copied and pasted 120 times and fill in the user names on each instance by hand... but that's the pain in the ass I was hoping to avoid.

<{POST_SNAPBACK}>

How is the user/password info available ?

Put your Logic into a Func... EndFunc and call it for ever userid/password combo..

As an example (Untested)

$file = FileOpen("userinfotest.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
   MsgBox(0, "Error", "Unable to open file.")
   Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
  ; asssume the record looks like :  Username,Password
   $UserInfo = StringSplit($line,",")
   DoYourThingFunc($UserInfo[1],$UserInfo[2])
Wend
FileClose($file)
Exit

Func DoYourThingFunc($Username,$Password)
  ; here goes your logic
EndFunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I had the same problem, and I use the oldest method, mayby stupidly simple, but works.

$password1 = aaaaa

$password2 = bbbbbb

$password3 = cccccc

.

.

.

$password120 = aabbccdd

then, same for the usernames

$username1 = xxxxxxx

$username2 = yyyyyyy

$username3 = zzzzzzzzzz

.

.

.

$username120 = aaabbbccc

then, use if .. then

$counter = 0

do

$counter = $counter + 1

if $counter = 1 then $username = $username1 and $password = $password1

if $counter = 2 then $username = $username2 and $password = $password2

if $counter = 3 then $username = $username3 and $password = $password3

.

.

.

if $counter = 120 then $username = $username120 and $password = $password120

; "(Here, you put your script that is already running, using for the pasword = $password and for the username = $username.)"

until $counter = 120

I know, I know, seems to be silly, maybe it is, but it perfectly works. I am sure you can do it with an array, but honestly, I dont know how to use them really well.

To do your script, you can use excell not to type so much, save it as text, and import it to your script.

Hope this will works for you, It worked for me

Edited by jurco
Link to comment
Share on other sites

Also you can make 2 files one with the names list and the other with the passwords list.

Using a While 1 loop (closed when the FileReadLine @error is <>0) you can do all the code you want changing name and pass with easy.

To be sure of never lose your files of name and passes you should also

FileInstall() them in the begin of the script.

E.g.

;I assume that the two files are well done and have the same number of lines.
;and to a line x there is the right name and the relative password.

FileInstall('passwords.txt')
FileInstall('names.txt')

$handlep = FileOpen('passwords.txt',0)
$handlen = FileOpen('names.txt',0)
$c = 0
While 1
   $c = $c + 1
   $n = FileReadLine($handlen,$c)
   $p = FileReadLine($handlep,$c)
   If @error Then Exitloop

  ;your code here, the password is in $p and your name is in $n
  ;Send($n,1)
  ;Send(@tab)
  ;Send($p,1)
  ;Ect
WEnd
FileClose($handlen)
FileClose($handlep)

Msgbox(0,'','All done!',10)

Of course, and it is maybe easier, you can use only a file with lines like

name=pass

and stringsplit every line at the =, but you MUST be sure that no passes or names uses the = inside or find a char that never appear.

Edited by ezzetabi
Link to comment
Share on other sites

what you could try also is to build an ini file with as many section as you need, in each section you could find keys like username and password... You could name your section like that:

e.g.

[section1]

user=john312

password=password

[section2]

user=smith312

password=administrator

...

[section120]

And in your script, you could use a For loop instead:

For i = 1 to 120 Step 1

;then you input your steps to start your app

;To get user/password coresponding to the user you coud do:

$password = IniRead($IniFile, "Section" & $i, "password")

Next

Link to comment
Share on other sites

Even better use a While 1 that exits when IniRead returns the 'not found' string (that it may be a non writeable string like @tab ot @cr) so you don't need to change the source every time you add a section.

The drawback is that if you skip a number (maybe because you removed it since obsolete) it will ignore all sections after. (ops)

Link to comment
Share on other sites

That can be easily solved by adding a third value: Active. You could check if the username and passwords are active before attempting to use them. It works good for security purposes also... it is always good to have a record of past records. Most systems actually never remove the users they "delete", they just change a flag to keep historical records. Just a thought! :ph34r: Happy Posting!

*** Matt @ MPCS

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