Jump to content
Sign in to follow this  
JakeLynagh

Saving a Log?

Recommended Posts

JakeLynagh

I have a script that automatically registers a number of times to a website generating random usernames.

How can I make it save a log of all of the usernames it generates to a .txt file?

Thanks.

Share this post


Link to post
Share on other sites
Rad

;Append a line of text to the end of a previously opened text file.

FileWrite("filename", "text")

You should probrably put this in the user creation function.

$FileLocation = @scriptdir & "\names.txt"

...

Func AddName()
  $name = GenRandomName()
  FileWrite($FileLocation, $name)
Endfunc

Then you could use FileReadLine() and read in the lines to an array, and check if a random name is already taken by comparing the random name to each item in the array.

Edited by Rad

Share this post


Link to post
Share on other sites
JakeLynagh

;Append a line of text to the end of a previously opened text file.

FileWrite("filename", "text")

You should probrably put this in the user creation function.

$FileLocation = @scriptdir & "\names.txt"

...

Func AddName()
  $name = GenRandomName()
  FileWrite($FileLocation, $name)
Endfunc

Then you could use FileReadLine() and read in the lines to an array, and check if a random name is already taken by comparing the random name to each item in the array.

Sorry, I have absolutely no idea what any of that means...

This is only the second thing I have written in Autoit I am still learning the functions.

This is what I have:

$o_IE = _IECreate ()
$site = ("https://www.website/register")
_IENavigate ($o_IE, $site)
MouseClick("left", 400, 100 )
Dim $list[6] = ["John", "Mary", "Suzy", "Stacy", "Peter", "Phill"]
$user = $list[Random(0, 6, 1)]
$number = random(1000, 9999, 1)


Send("{tab}{tab}{tab}{tab}"  & $user & $number & "{tab}Password{tab}Password" & $user & $number & "@hotmail.com" "{tab}{enter}")

Can you please let me know what I need?

Share this post


Link to post
Share on other sites
Rad

Alright, well the main function I want you to look at is FileWrite. The first parameter is the location "C:\Your File.txt" and the second is the name you used, lets say John.

Since you determine the name randomly you would need to keep track of it. Then you would write the name to a file, so that you can later check to see if the name is already registered.

Try here, stuff added in Bold for you to see.

$o_IE = _IECreate ()
$site = ("https://www.website/register")
_IENavigate ($o_IE, $site)
MouseClick("left", 400, 100 )
Dim $list[6] = ["John", "Mary", "Suzy", "Stacy", "Peter", "Phill"]
$user = $list[Random(0, 6, 1)]
$number = random(1000, 9999, 1)
[b]$username = $user & $number[/b]


Send("{tab}{tab}{tab}{tab}"  & [b]$Username[/b] & "{tab}Password{tab}Password" & [b]$Username[/b] & "@hotmail.com" "{tab}{enter}")

[b]FileWrite("C:\NamesUsed.txt", $Username)

The filewrite would output a file in your C:\ drive called NamesUsed, and add to the last line of the file John.

Edited by Rad

Share this post


Link to post
Share on other sites
JakeLynagh

I see what you have done, and shortening the $username $user and $number waqs an excellent idea, thanks.

But I get this:

$user = $list[Random(0, 6, 1)]

$user = ^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Alright, well the main function I want you to look at is FileWrite. The first parameter is the location "C:\Your File.txt" and the second is the name you used, lets say John.

Since you determine the name randomly you would need to keep track of it. Then you would write the name to a file, so that you can later check to see if the name is already registered.

Try here, stuff added in Bold for you to see.

$o_IE = _IECreate ()
$site = ("https://www.website/register")
_IENavigate ($o_IE, $site)
MouseClick("left", 400, 100 )
Dim $list[6] = ["John", "Mary", "Suzy", "Stacy", "Peter", "Phill"]
$user = $list[Random(0, 6, 1)]
$number = random(1000, 9999, 1)
[b]$username = $user & $number[/b]


Send("{tab}{tab}{tab}{tab}"  & [b]$Username[/b] & "{tab}Password{tab}Password" & [b]$Username[/b] & "@hotmail.com" "{tab}{enter}")

[b]FileWrite("C:\NamesUsed.txt", $Username)

The filewrite would output a file in your C:\ drive called NamesUsed, and add to the last line of the file John.

Share this post


Link to post
Share on other sites
Rad

You need to declare the size of the variable first, I just noticed that you did that but the name of the variable is wrong. Change $list to $user

Dim $user[6] = ["John", "Mary", "Suzy", "Stacy", "Peter", "Phill"]
$user = $list[Random(0, 6, 1)]

I also just realized the bold tags dont even work in the code boxes...

Edited by Rad

Share this post


Link to post
Share on other sites
JakeLynagh

Thanks.

But I have another error:

$user = $list[Random(0, 6, 1)]

$list isn't declared again, what do I do with that ^^^

Share this post


Link to post
Share on other sites
Rad

Lol

Sorry I'm not awake.

Ok, restore the variable back to list and in the Random() function the "max" (second value) needs to be one less than the size of the array.

$o_IE = _IECreate ()
$site = ("https://www.website/register")
_IENavigate ($o_IE, $site)
MouseClick("left", 400, 100 )
Dim $list[6] = ["John", "Mary", "Suzy", "Stacy", "Peter", "Phill"]
$user = $list[Random(0, 5, 1)]
$number = random(1000, 9999, 1)
[b]$username = $user & $number[/b]


Send("{tab}{tab}{tab}{tab}"  & [b]$Username[/b] & "{tab}Password{tab}Password" & [b]$Username[/b] & "@hotmail.com" "{tab}{enter}")

[b]FileWrite("C:\NamesUsed.txt", $Username)

That should work, good luck I'm going back to bed.

Share this post


Link to post
Share on other sites
JakeLynagh

Okay, now that Rad's gone to bed can anyone help me with this?

It says error in expression.

I have changed password to:

$password = random(10000, 99999, 1)

And the error is in:

Send("{tab}{tab}{tab}{tab}" & $username & "{tab}" & $password & "{tab}" & $password & "" & $username & "@hotmail.com" "{tab}{enter}")

Thanks.

Share this post


Link to post
Share on other sites
JakeLynagh

Surely someone knows what the error is in this string:

Send("{tab}{tab}{tab}{tab}" & $username & "{tab}" & $password & "{tab}" & $password & "" & $username & "@hotmail.com" "{tab}{enter}")

Share this post


Link to post
Share on other sites
JakeLynagh

It looks really simple, but as I say I am new to this...

Anyone?

Share this post


Link to post
Share on other sites
glasglow

password & "" & $....maybe right there with the double quotes

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  

×