Sign in to follow this  
Followers 0
MikeS

Use Autoit with GUI to update login.cmd

14 posts in this topic

Hello,

I like to know how I can write a GUI that can update with parameters that can write to a cmd file. (Login.cmd )

Example:

Net use \\192.168.1.111\ipc$ /user:192.168.1.111\Username Password

I would like to have a utilty that can write three parameters into this cmd file. Using a simple Autoit GUI

1) ipaddress

2) username

3) password

So if I can have three text boxes to input these parameters, the Autoit GUI can then input this into the login.cmd file.

What I 'm trying to do is have the user use the GUI, instead of editing my login.cmd file.

Thanks, for your help

Mike

Share this post


Link to post
Share on other sites



Hello,

I like to know how I can write a GUI that can update with parameters that can write to a cmd file. (Login.cmd )

Example:

Net use \\192.168.1.111\ipc$ /user:192.168.1.111\Username Password

I would like to have a utilty that can write three parameters into this cmd file. Using a simple Autoit GUI

1) ipaddress

2) username

3) password

So if I can have three text boxes to input these parameters, the Autoit GUI can then input this into the login.cmd file.

What I 'm trying to do is have the user use the GUI, instead of editing my login.cmd file.

Thanks, for your help

Mike

Mike, I hope you aren't expecting someone to write this out for you. There are several functions that I feel you should look at to accomplish what you are wanting to do.

FileWrite, FileWriteLine, InputBox

You actually wouldn't need to create a full fledged GUI if you use the above function list, and compare it to the help file to figure out what each function does, and how it will help you.

Mike, I would also like to recommend a tutorial that will help you get started in a scripting environment.

Welcome to AutoIt 1-2-3

If you post some code then people will be more willing to help you debug it. It seems though you are expecting us to spend our valuable time that we are donating to help to write your entire script for you.

I hope I have been of some assistance,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Mike, I hope you aren't expecting someone to write this out for you. There are several functions that I feel you should look at to accomplish what you are wanting to do.

FileWrite, FileWriteLine, InputBox

You actually wouldn't need to create a full fledged GUI if you use the above function list, and compare it to the help file to figure out what each function does, and how it will help you.

Mike, I would also like to recommend a tutorial that will help you get started in a scripting environment.

Welcome to AutoIt 1-2-3

If you post some code then people will be more willing to help you debug it. It seems though you are expecting us to spend our valuable time that we are donating to help to write your entire script for you.

I hope I have been of some assistance,

JS

Here is what I have so far, but still need help linking the variables to the inputbox, then to the file.


;Autoit Script v1.0
;Writes to Login.cmd file, with user input dialog


;-----   DEFINE ALL VARIABLES AND CLEAR CURRENT VALUES

Dim $username
Dim $password
Dim $ipaddress

$username = ""
$password = ""
$ipaddress = ""

;Places the input box in the top left corner displaying the characters as they 
;are typed.
$username = InputBox("Login Information", "Enter your username.", "", "")

;Asks the user to enter a password.  Don't forget to validate it!
$passwd = InputBox("Security Check", "Enter your password.", "", "*")

;Asks the user to enter a 1 or 2 character response.  The M in the password 
;field indicates that blank string are not accepted and the 2 indicates that the 
;responce will be at most 2 characters long.
$ipaddress = InputBox("Workstation Information", "Enter the IP Address of Workstation.", "", "")

;Text that I need to get writen to push.cmd file
;username is Mike Smith
;password is 12345678
;IP address is 10.16.115.124
;
;Net use \\10.16.115.124\ipc$  /user:10.16.115.124\Mike Smith 12345678
;

$file = FileOpen("c:\push.cmd", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, "Line1")
FileWrite($file, "Still Line1" & @CRLF)
FileWrite($file, "Line2")

FileClose($file)

This is what I did to the push.cmd file.

Net use \\$ipaddress\ipc$  /user:10.16.115.124\MIke Smith 12345678

Result is this:

$ipaddressStill Line1
Line2

So if I can get help with linking these together is will help me, learn the processes.

Thanks,

Mike


            
                


    Edited  by MikeS
    
    

            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
MikeS   

    
        
    
             0
    
        
    

        
            
                Seeker
            
            

            
                

    
        
    

            
            Members
            
            
                

    
        
    
             0
    
        
    

                19 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #4 · 
            Posted 
            
            
            
        
    

    


            
        
            I also tried this, with no luck?

$file = FileOpen("c:\push.cmd", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$FindText = "@ipaddress"
$ReplaceText = "cat"

$FileContents = FileRead("push.cmd")
$FileContents = StringReplace($FileContents,$FindText,$ReplaceText)

;FileWrite($file, "ipaddress")
;FileWrite($file, "Still Line1" & @CRLF)
;FileWrite($file, "Line2")

FileClose($file)


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
MikeS   

    
        
    
             0
    
        
    

        
            
                Seeker
            
            

            
                

    
        
    

            
            Members
            
            
                

    
        
    
             0
    
        
    

                19 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #5 · 
            Posted 
            
            
            
        
    

    


            
        
            Found this, but having trouble converting it to work with my project.

It seems hard to me, but I'm replacing an ip address, which is always different, so how can I adopt this sample code into my project.

It seems just what I need.

$oIE = _IECreate()
_IENavigate($oIE, "http://www.autoitscript.com/")

$body = _IEBodyReadHTML($oIE)

If StringInStr($body, "automation") Then
    MsgBox(0, "Success", "The string was found")
    $newbody = StringReplace($body, "automation", "AUTOMATION - Yeah!")
    _IEBodyWriteHTML($oIE, $newbody)
Else
    MsgBox(0, "Fail", "The string was NOT found")
EndIf

Exit


Thanks, for your help.

Mike


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
James   

    
        
    
             373
    
        
    

        
            
                Pessimist
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             373
    
        
    

                10,228 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #6 · 
            Posted 
            
            
            
        
    

    


            
        
            Thats for Automating IE functions. If your using your script for CMD, I don't think it will do it for you.


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ
  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
MikeS   

    
        
    
             0
    
        
    

        
            
                Seeker
            
            

            
                

    
        
    

            
            Members
            
            
                

    
        
    
             0
    
        
    

                19 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #7 · 
            Posted 
            
            
            
        
    

    


            
        
            Thanks for the information.

So do you know which one of these functions will work for me.

Mike


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
Zedna   

    
        
    
             134
    
        
    

        
            
                AutoIt rulez!
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             134
    
        
    

                8,905 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #8 · 
            Posted 
            
            
            
        
    

    


            
        
            Thanks for the information.

So do you know which one of these functions will work for me.

Mike

;Autoit Script v1.0
;Writes to Login.cmd file, with user input dialog


;----- DEFINE ALL VARIABLES AND CLEAR CURRENT VALUES

Dim $username
Dim $password
Dim $ipaddress

$username = ""
$password = ""
$ipaddress = ""

;Places the input box in the top left corner displaying the characters as they
;are typed.
$username = InputBox("Login Information", "Enter your username.", "", "")

;Asks the user to enter a password. Don't forget to validate it!
$passwd = InputBox("Security Check", "Enter your password.", "", "*")

;Asks the user to enter a 1 or 2 character response. The M in the password
;field indicates that blank string are not accepted and the 2 indicates that the
;responce will be at most 2 characters long.
$ipaddress = InputBox("Workstation Information", "Enter the IP Address of Workstation.", "", "")

;Text that I need to get writen to push.cmd file
;username is Mike Smith
;password is 12345678
;IP address is 10.16.115.124
;
;Net use \\10.16.115.124\ipc$ /user:10.16.115.124\Mike Smith 12345678

$text = @CRLF & 'Net use \\' & $ipaddress & '\ipc$ /user:' & $ipaddress & '\' & $username & ' ' & $passwd & @CRLF

$file = FileOpen("c:\push.cmd", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $text)
FileClose($file)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

;Autoit Script v1.0
;Writes to Login.cmd file, with user input dialog
;----- DEFINE ALL VARIABLES AND CLEAR CURRENT VALUES

Dim $username
Dim $password
Dim $ipaddress

$username = ""
$password = ""
$ipaddress = ""

;Places the input box in the top left corner displaying the characters as they
;are typed.
$username = InputBox("Login Information", "Enter your username.", "", "")

;Asks the user to enter a password. Don't forget to validate it!
$passwd = InputBox("Security Check", "Enter your password.", "", "*")

;Asks the user to enter a 1 or 2 character response. The M in the password
;field indicates that blank string are not accepted and the 2 indicates that the
;responce will be at most 2 characters long.
$ipaddress = InputBox("Workstation Information", "Enter the IP Address of Workstation.", "", "")

;Text that I need to get writen to push.cmd file
;username is Mike Smith
;password is 12345678
;IP address is 10.16.115.124
;
;Net use \\10.16.115.124\ipc$ /user:10.16.115.124\Mike Smith 12345678

$text = @CRLF & 'Net use \\' & $ipaddress & '\ipc$ /user:' & $ipaddress & '\' & $username & ' ' & $passwd & @CRLF

$file = FileOpen("c:\push.cmd", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $text)
FileClose($file)
Thanks for all of your help.

I do have one other question, with this code.

I need to write to the push.cmd file, but I need to not append lines to it, I need to update the parameters already in place within the file.

So everytime I reference username, i'd use $username, so is that the right Autoit Function FileWrite

Like this:

CD C:\FastPush\vnc7

Net use \\@ipaddress\ipc$ /user:10.16.115.124\Mike Smith 12345678

call "C:\\FastPush\vnc7\vnc7.noicons.cmd" 10.16.115.124 /ULTRA /noshortcut

mkdir \\10.16.115.124\c$\temp

Change to:

CD C:\FastPush\vnc7

Net use \\@ipaddress\ipc$ /user:@ipaddress\$username $password

call "C:\\FastPush\vnc7\vnc7.noicons.cmd" @ipaddress/ULTRA /noshortcut

mkdir \\@ipaddress\c$\temp

I hope you can understand what I'm trying to do, if not please post, and I'll try to answer your questions.

It seems like I need to replace, to be able to replace file text properties?

Thanks, again

Mike

Edited by MikeS

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

$file_name = 'c:\login.cmd'

$text = FileRead($file_name)
$text = StringReplace($text, '10.16.115.124', $ipaddress)
$text = StringReplace($text, 'Mike Smith', $username)
$text = StringReplace($text, '12345678', $password)

FileDelete($file_name)
FileWrite($file_name, $text)

Edited by Zedna

Share this post


Link to post
Share on other sites

Hi, Zedna

Where do I place this code?

Also I see the variables Mike Smith, but these will change everytime this script is ran.

What my plan is to have Autoit display Input Boxes, that the user will input username, password and ipaddress of machine he or she is trying to connect to. I Autoit will then write this information for the input box to the push.cmd file.

So I thought I would set the variables inside the push.cmd file before using the file.

So how can I get this implemented using this code?

Thanks,

MIke

Share this post


Link to post
Share on other sites

I gave you only ideas how to achieve some functionality in AutoIt.

You must learn something from the HelpFile and improve this base code for your needs.

If you encounter some AutoIt problem post it here we will see...

Share this post


Link to post
Share on other sites

How can I set a varable for an username, password, or ip address. When they will always be different?

I guess this is were I need help. because once I figure that out I can you the StringReplace to replace the variable with the input box parameters. I have seen now how you can use the FileWrite to replace text you already know.

I have look into the help files and tutorials too.

Thanks,

Mike

Share this post


Link to post
Share on other sites

Const $template = _
'CD C:\FastPush\vnc7' & @CRLF & _
'Net use \\%ipadress%\ipc$ /user:@ipaddress\%username% %password%' & @CRLF & _
'call "C:\\FastPush\vnc7\vnc7.noicons.cmd" %ipadress%/ULTRA /noshortcut' & @CRLF & _
'mkdir \\%ipadress%\c$\temp'

$file_name = 'c:\login.cmd'

$text = $template
$text = StringReplace($text, '%ipadress%', $ipaddress)
$text = StringReplace($text, '%username%', $username)
$text = StringReplace($text, '%password%', $password)

FileWrite($file_name, $text)

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