Jump to content

Help: Script to mount USB never exits


Recommended Posts

WinWait("Login device DT4000","")
If Not WinActive("Login device DT4000","") Then WinActivate("Login device DT4000","")
WinWaitActive("Login device DT4000","")
Send("Password")
Send("{ENTER}")
WinWaitActive("My USB","")
Send("{ENTER}")
Sleep(2000)
Exit

I have a password protected USB that I want to auto login after mounting. The above script works but never closes. I have tried adding loops for closing when process is active, tried a win close if then loop etc, but nothing seems to work.

I tried making it a function and the script will then close, but it never passes the password into the "Login device DT4000".

 

So my questions are:

1. why will the above never close

2. If I add func LoginUSB() and endfunc, why are the send inputs not passed to the active window?

 

Thanks in advance

Link to comment
Share on other sites

  • Developers
  1. I assume on one of the WinWaitActive() lines

Add 

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info

.. run the script and hover over the systrayicon to get the actual scriptline it is hanging on.

Jos

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

Its hanging by showing paused at line 15:

WinWaitActive("Login device DT4000","")

It sees the active window and passes in the commands, the window closes, it acknowledges the 2nd window which also closes, but the debug shows it hasn't exited from the first window for some reason

I tried adding a WinClose, but then it pauses at line 13:

WinWait("Login device DT4000","")

Here's what I added to try to force the first window to close:

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
WinWait("Login device DT4000","")
If Not WinActive("Login device DT4000","") Then WinActivate("Login device DT4000","")
WinWaitActive("Login device DT4000","")
Send("Password")
Send("{ENTER}")
WinClose("Login device DT4000","")
WinWaitActive("My USB","")
Send("{ENTER}")
Sleep(2000)
Exit

I don't understand how its getting hung up on the first window

Edited by Novice101
Link to comment
Share on other sites

  • Developers

There are no 13 or 15 lines in your posted script. ;)

You probably also need to consider some sleep() statements between actions to give them time to process your send() commands.

Jos

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

Sorry about that, I cut out the default editor inputs:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName



 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
WinWaitActive("Login device DT4000","")
Send("Password")
Sleep(2000)
Send("{ENTER}")
Sleep(2000)
WinClose("Login device DT4000","")
WinWaitActive("My USB","")
Send("{ENTER}")
Sleep(2000)
Exit

I tried adding sleep commands but to no avail. It keeps failing at line 13

WinWaitActive("Login device DT4000","")

I did notice that if I put any delay inside the WinWaitActive statement it never sees the window at all,

e.g.

WinWaitActive("Login device DT4000","",5)

without the delay it passes the information through. Its almost as if the script is looking for a different name, or the window has a different name than what the AU3Info window says it is called

Link to comment
Share on other sites

Instead of using WinWaitActive, you could try with WinWait, and use ControlSend instead of Send.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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