Sign in to follow this  
Followers 0
killroy

Optimise Or Something..

5 posts in this topic

#1 ·  Posted (edited)

Hi all,

Just started using AutoIt today, damn what a fine program this is. Many thanks for your time and efforts put into this project!

I started to write a small executable which allows users to map a drive with a nice front GUI.

I was wondering if someone could look over it and see how I could optimise it, see what types of errors I am doing and such likes. It is fairly simple. I am unsure of the error functions "Username is empty" etc I don't know if you can have an If Else function like this .

If blah = 0 & bleh = 0 then

code

end if

Here is the code. I look forward to your responses.

GUICreate("KC Login",220,140,10,10)


GuiSetControl("label", "Username:",  5, 15, 50)
GuiSetControl("label", "Password:",  5, 35, 50)

$username = GuiSetControl("input", "", 60, 13, 150,17)
$password = GuiSetControl("input", "", 60, 33, 150,17)

$submit = GuiSetControl("button", "Login", 60, 53, 150,23)

$userdrive = GuiSetControl("checkbox", "Map User Drive", 60, 82, 150,23)
GUISetControlEx($userdrive,1)

$commondrive =GuiSetControl("checkbox", "Map Commons Drive", 60, 102, 150,23)

$userdriveletter = GUISetControl("combo", "my combo", 5,80,45)
GUISetControlData(-1,"M:|N:|O:","M:")
$commondriveletter = GUISetControl("combo", "my combo", 5,100,45)
GUISetControlData(-1,"X:|Y:|Z:","X:")


GUIWaitClose()


if $submit = GuiRead () then

    if GuiRead($username) = "" then

  msgbox(0,"Warning","Username is empty")
  run("login.exe")
    exit

    elseif GuiRead($password) = "" then

  msgbox(0,"Warning","Password is empty")
  run("login.exe")
    exit
    
    endif

    if GuiRead($userdrive) = 1 then


;Run("net use " & GuiRead($userdriveletter) & " \\192.168.2.2\c$","",@SW_HIDE); Test snippet ignore please.

  $i = 1
  While $i <= 6
  $var = "server" & $i
        $i = $i + 1
    Run("net use " & GuiRead($userdriveletter) & " \\" & $var & "\" & GuiRead($username) & " " & GuiRead($password) & " /USER:BCSDNET\" & GuiRead($username) & "","",@SW_HIDE)
  WEnd
    sleep(500)
    Run("explorer " & GuiRead($userdriveletter) & "")
  
    endif
 
    if GuiRead($commondrive) = 1 then

  Run("net use " & GuiRead($commondriveletter) & " \\192.168.2.2\d$","",@SW_HIDE)
  sleep(500)
  Run("explorer " & GuiRead($commondriveletter) & "")

    endif 
endif

Many thanks

Edited by killroy

Share this post


Link to post
Share on other sites



Hi all,

Just started using AutoIt today, damn what a fine program this is. Many thanks for your time and efforts put into this project!

I started to write a small executable which allows users to map a drive with a nice front GUI.

I was wondering if someone could look over it and see how I could optimise it, see what types of errors I am doing and such likes. It is fairly simple. I am unsure of the error functions "Username is empty" etc I don't know if you can have an If Else function like this .

If blah = 0 & bleh = 0 then

code

end if

Here is the code. I look forward to your responses.

Many thanks

Very good start.

not an optimisation but the while/wend can be change with a For/next

Instead of run("login.exe" you can have a big while including guiwaitclose which will exit when every parameters are ok. the success will leave this main while with exitloop.

error can display a message on the gui by updating an empty label with guiwrite.

this message can be shown in red using the GuiSetControlex

the recovery os error on run ("net ... can only be done with a timeout on the command.

to close the windows dialog box on error you can use a adlibenable function.

:D

Share this post


Link to post
Share on other sites

Hi jpm,

Thanks for the helpful advice. Another quick question. After reading a couple pages of the help file and the support forum I cannot find a way to hide the password for

$password = GuiSetControl("input", "", 60, 33, 150,17)

I can see with 'InputBox' you can specify which character to use to hide the text within the box.

Regards

Byron

Share this post


Link to post
Share on other sites
:D Maybe someone else could help with my incy, wincy, little problem. This is the only obstacle keeping me from using the script. :huh2:

Share this post


Link to post
Share on other sites

WOOHOO! nevermind I am thick.

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