Sign in to follow this  
Followers 0
Guest tommyboy22481

How to Automatically Enter Password

11 posts in this topic

I am a DB admin where I work. We use MS Access for a frontend to all our DB's. For security reasons we are using a custom system.mdw, which requires you to login everytime you open Access, which I do all day long. I am sick of typing the password over and over so I came up with this script. I changed the MDB file association to point to the compiled script instead of Access so whenever I click on an MDB the script gets run with the MDB filename as an argument. The script then opens the MDB and waits for the login window to show up then enters the password. This works somewhat, but the problem I am having is that DB's run from the desktop (I'm using XP) does not pass the filename argument correctly.

Is there a better way to do this? I don't like the fact that I have to hard code the path to access but since I am modifying the MDB file association I don't think I can do it any other way. Why does the argument get messed up when clicking on an MDB from the desktop?

Here's the code I am using:

Dim $dbName
$dbName = $CmdLine[1]

; Append the cmd line argument and run the program 
Run("C:\Program Files\Microsoft Office 97\Office\MSACCESS.EXE " & $dbName)

; Wait for the window to become active
WinWaitActive("Logon")

; Now that the window is active type the password an hit enter
Sleep(5)
Send("PASSWORD{ENTER}")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is not a direct answer but it might help you give ideas. NOTE--DllCall requies the latest "unstable" version of AutoIt

Until I found the real soultion, I used the following script on machines where Outlook 2000 refused to remember the username and domain. (If you remove $cmdLine[1] and hard-code the username, you could remove the command-line checking stuff.)

; Allow only one instance of this script
$script_ID = "Outlook 2000 AutoIt script workaround"
If WinExists($script_ID) Then Exit;It's already running
AutoItWinSetTitle($script_ID)

;Hide AutoIt's tray icon
Opt("TrayIconHide", 1)

; Check command line
If $CmdLine[0] < 1 Then
   MsgBox(4096,"Instructoins","Create a shortcut to this EXE, and put username on the command line.") 
   Exit
EndIf
;;;

; If Outlook is already open, then do not run it a second time
If Not ProcessExists("Outlook.exe") Then
; Run outlook without having to know its exact path
   DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", "", _
   "string", "outlook.exe", "string", "", "string", "", "long", @SW_SHOWNORMAL)
EndIf

; The body of the script
$title = "Enter Password"
WinWait($title)
ControlSetText($title,"","Edit1", $cmdLine[1]);username text field
ControlSetText($title,"","Edit2", "EXAMPLEMAIL");domain text field
ControlFocus($title,"","Edit3");move cursor to password field

Use the AU3_SPY program to determine the right paramters for ControlSetText...

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

There is probably a space in the filepath\filename.

could try to put in inside double quotes like:

$dbName = ""
For $x = 1 To $CmdLine[0]
   $dbName = $dbName & " " & $CmdLine[$x]
Next
;.....
Run('C:\Program Files\Microsoft Office 97\Office\MSACCESS.EXE "' & $dbName &'"')

edit: added the cmdline$ concatenation

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

There is probably a space in the filepath\filename.

could try to put in inside double quotes like:

Run('C:\Program Files\Microsoft Office 97\Office\MSACCESS.EXE "' & $dbName &'"')

<{POST_SNAPBACK}>

Right on the money, works great now! :)

Any ideas on a better (more portable) way of doing this? The only thing I don't like is hard coding the Access path. At first I thought about having a tray program enter the password whenever it saw the Login window, but that would be another program always running in the background which I can live without. Is there maybe a registry value I can pull the Access path from each time?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Why not just have a script that waits until you run access to then perform its job? That way you can just put your .mdb back in the proper place and while the script is running it will just automatically log you in.

Something like this...

HotKeySet("^!x", "mExit")

While 1
   If ProcessExists("MSACCESS.exe") Then
      WinActivate("MS Access");You get the picture right?
     ;your username password stuff here
   EndIf
   Sleep(100)
WEnd

Func mExit()
   Exit
End Func

That above is using the process. You may not want to do that. You may want to figure out the window title check see if the window exists then go from there. I hope this helps you out.

JS

Edited by JSThePatriot

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

Right on the money, works great now!  :)

Any ideas on a better (more portable) way of doing this? The only thing I don't like is hard coding the Access path. At first I thought about having a tray program enter the password whenever it saw the Login window, but that would be another program always running in the background which I can live without. Is there maybe a registry value I can pull the Access path from each time?

<{POST_SNAPBACK}>

have a look somewhere at this spot in the registry:

RegRead('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\msaccess.exe', '')

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You can use this to run default program for your MDB or anything else you put in.

Dim $dbName
$dbName = $CmdLine[1]

; Append the cmd line argument and run the program
Run(@ComSpec &' /c start  "' & $dbName & '"','',@sw_hide); starts $dbName with default program.

; Wait for the window to become active
WinWaitActive("Logon")

; Now that the window is active type the password an hit enter
Sleep(5)
Send("PASSWORD{ENTER}")

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Oh never mind if you didnt want a script constantly running in bg :-P

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

You can use this to run default program for your MDB or anything else you put in.

; Append the cmd line argument and run the program

Run(@ComSpec &' /c start  "' & $dbName & '"','',@sw_hide); starts $dbName with default program.

I saw that technique, but doesn't that rely on the File association to start the correct app? I changed the MDB file association to point to my script, so I think this code would create an infinite loop.

I will look at the Reg key, Thanks everyone!!

Share this post


Link to post
Share on other sites

Regkey is the best way to go.

Dim $dbName
$dbName = $CmdLine[1]
$ACCESSPATH=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE", "")

; Append the cmd line argument and run the program
Run($ACCESSPATH & ' "' & $dbName & '"','')

; Wait for the window to become active
WinWaitActive("Logon")

; Now that the window is active type the password an hit enter
Sleep(5)
Send("PASSWORD{ENTER}")

AutoIt3, the MACGYVER Pocket Knife for computers.

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