Python Forum
Trying to use win32 Sendkeys to log into database overnight
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to use win32 Sendkeys to log into database overnight
#1
I am trying to log into and run a macro in an Access database while not at my computer. I have written a script that achieves what I want while I am logged in but when I schedule the task to run overnight it does not work. What would cause this to happen?

I have tried writing a script that keeps the computer awake by sending a key repeatedly for 12 hours but that did not help. I have other Python programs that run overnight that don't use sendkeys and they have no problems.

I have tried running it only up to before the macro and it appears to not be saving the dates or entering a password. If I run it with the macro, I see it attempted the macro but did not start it because it does not have the password.

The popup is asking for the password to make the ODBC connection between Access and the backend Oracle database.

All of this is done on a virtual desktop that stays logged in for 24 hours. The physical computer is explicitly told to sleep. Is it possible that sendkeys is trying to send from the physical keyboard?

This is the latest Python 3. I am using 32bit Anaconda/Python on Windows 10.

My script is like this:

import win32com.client
import win32api

access = win32com.client.Dispatch("Access.Application")
shell = win32com.client.Dispatch("WScript.Shell") 
access.OpenCurrentDatabase("myDbPath")

time.sleep(400) #I've tried less time too
shell.Sendkeys("{TAB}") # tab to button that triggers the login popup
time.sleep(10)
shell.Sendkeys("{ENTER}") 
time.sleep(10)
shell.Sendkeys("pw")
time.sleep(10)
shell.Sendkeys("{ENTER}")
time.sleep(10)

shell.Sendkeys("{TAB}") # go to start date field
time.sleep(10)
shell.Sendkeys(startDate) # fill start date
time.sleep(10)  
shell.Sendkeys("{TAB}") # go to enddate field
time.sleep(10)
shell.Sendkeys(endDate) # fill end date
time.sleep(10)
shell.Sendkeys("{TAB}") # to save dates button
time.sleep(10)
shell.Sendkeys("{ENTER}") # click save dates button    
time.sleep(10)
access.DoCmd.RunMacro('myMacro') # run macro

access.CloseCurrentDatabase()
access.Application.Quit()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SendKeys not working SanjayGMusafir 4 488 Jan-16-2024, 12:07 PM
Last Post: EdwardMatthew
  Python library for win32 console commands eldiener 3 3,488 Aug-24-2021, 10:28 PM
Last Post: bowlofred
  Win32\ping.exe windows pops up -very annoying... tester_V 9 3,236 Aug-12-2021, 06:54 AM
Last Post: tester_V
Exclamation binwalk Win32 compile hackstunt 2 3,822 Feb-24-2021, 05:14 PM
Last Post: nilamo
  pyarrow throws oserror winerror 193 1 is not a valid win32 application aupres 2 3,800 Oct-21-2020, 01:04 AM
Last Post: aupres
  win32 API: Launch Application to RDP session from background process python script rangeshgupta 0 2,162 May-28-2020, 09:41 PM
Last Post: rangeshgupta
  C:\Windows\System32\appwiz.cpl is not a valid Win32 application Marceepoo 8 5,197 Mar-15-2020, 04:46 AM
Last Post: buran
  Search box python selenium sendkeys dorabajji 0 1,498 Mar-10-2020, 09:41 AM
Last Post: dorabajji
  Pymssql library failing when upgrading to Python 3.7 - win32 issue stixmagiggins 5 7,474 Jun-24-2019, 06:46 AM
Last Post: snippsat
  win32 GetWindowRect for window dimensions MrMajorThorburn 3 4,658 Apr-08-2019, 04:08 PM
Last Post: MrMajorThorburn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020