Sign in to follow this  
Followers 0
cadeleon

String variable only enteringthe first character

10 posts in this topic

Hi there ! Newbie question.

Im creating a program to automate entry of the username and password in an intranet website for our company. The username consists of some characters and a variable which is the third octet of the IP address of the PC hosting the script. My problem is that the variable is only showing the first number. Some numbers have 2 and some have three but nevertheless, send is only sending the first integer of the variable represented. Help!!!

$chosenip = Run ("c:\ipget.bat");This batch file is actually doing a single ping and sends it to a file called pingtest.txt

$pStr = FileRead ("c:\PINGtest.txt")

$oct = StringSplit($pStr , ".")

$range = $oct[1] & "." & $oct[2] & "." & $oct[3] & "." & $oct[4]

MsgBox(0, "You are now in Computer number:", $oct[3]);at this point, all is still ok.

$sComputernumber = $oct[3]

Local $sUserName = "comp-" & $oct[3]

Local $sPassword = "<password>"

Local $sDomain = "<dummy.com>"

run ("C:\Program Files\Internet Explorer\iexplore.exe https://www.intranetwebsite.net/operations")

WinWaitActive("Connect to www.intranetwebsite.net")

sleep(100)

;Enter Login Credentials

sleep(100)

send("comp-{"& $sComputernumber & "}");This is where my problem is. $$sComputernumber for some reason only outputs the first integer. Say, if the computer is comp-195. Output will only be comp-1

sleep (100)

;send ("{TAB}")

Sleep(2000)

;Send("<password>{ENTER}")

Sleep(100)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Depends on how your ip.bat works, but try this

$chosenip = RunWait ("c:\ipget.bat");This batch file is actually doing a single ping and sends it to a file called pingtest.txt
$pStr = FileRead ("c:\PINGtest.txt")
$soct = StringStripWS($pStr)
$oct = StringSplit($soct, ".")

EDIT:

Or even

$pStr = @IPAddress1
$oct = StringSplit($pStr, ".")
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Depends on how your ip.bat works, but try this

$chosenip = RunWait ("c:\ipget.bat");This batch file is actually doing a single ping and sends it to a file called pingtest.txt
$pStr = FileRead ("c:\PINGtest.txt")
$soct = StringStripWS($pStr)
$oct = StringSplit($soct, ".")

EDIT:

Or even

$pStr = @IPAddress1
$oct = StringSplit($pStr, ".")

HI John thanks for your reply. Here is what is contained on Pingtest.txt

Pinging mylaptop3 [192.168.152.72] with 32 bytes of data:

Reply from 192.168.152.72: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.152.72:

Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

Share this post


Link to post
Share on other sites

Hi there. I tested your suggestions and it still did not fix the problem. Thanks though for presenting me with the line $pstr = @ipaddress. This saved me some tow lines of code and relying on the batch file for the results. :)

$soct = StringStripWS($pStr) does not work (Had an error) so i tried everything except this time I used $pStr = @IPAddress1. I still got the same results. (Please see attached.). The third octet of my IP address is 100 and the username is only showing comp-1. Should show comp-100.

post-66381-0-65043700-1311961515_thumb.j

Share this post


Link to post
Share on other sites

Well, I did not find what the solution was but I found a workaround. What I did was that I created a subroutine to copy the third octet to a file then tell the program to read the entry from that file and completely write all of the third octet onto the field. Final program looks like this...Thanks for all your help !

$pStr = @IPAddress1

$oct = StringSplit($pStr , ".")

$range = $oct[1] & "." & $oct[2] & "." & $oct[3] & "." & $oct[4]

MsgBox(0, "You are now on comp-", $oct[3])

;;This subroutine saves the 3rd octet to a temporary text file called c:\temp\test.txt

$file = FileOpen("c:\temp\test.txt", 1);this creates a blank file called test.txt file

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

filewrite("c:\temp\test.txt" , $oct[3]);this writes the 3rd octet onto the text file)

$ipoct = FileReadLine($File);This reads the line written to memory ans assigned a variable $ipoct

FileClose($file)

filedelete("c:\temp\test.txt")

https://www.intranet.net/operations")

run ("C:\Program Files\Internet Explorer\iexplore.exe https://www.intranet.net/storeoperations")

WinWaitActive("Connect to www.intranet.net")

sleep(100)

;Enter Login Credentials

sleep(100)

send("comp-")

send($ipoct)

sleep (100)

send ("{TAB}")

Sleep(2000)

Send("<password>{ENTER}")

Sleep(100)

Share this post


Link to post
Share on other sites

Well, this is my first program using autoit and I am still getting my feet wet in this environment. I have done a lot of scripts before but this was to modify logins, create batch files to automate mundane processes, mostly admin stuff. I was introduced to this program very recently by one of my colleagues. Now that I got my first program going, I can get more creative =) Thanks again!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Indeed.

You could start with getting familiar with Control* functions

an example would be

$hWnd = WinWaitActive("Connect to www.intranetwebsite.net"); returns a handel to the window

If you use the window info toll, its possible to get info about the controls in it, so you couls use ControlSend(), or ControlSetText() using the window handle and the control ID of the input field.

So say for instance, the window became minmized somehow, the data would still get sent to the control.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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