0

I have a PowerShell script - it opens a MS Access database, run a VBA script, and later close itself. It runs greatly manually.
Scheduled user is in the 'Administrator' of the computer and E is a local drive.

However, when I schedule it as a Windows task, it hangs. Codes are below. Could anyone tell me what went wrong?

$Access = New-Object -Com Access.Application
$Access.OpenCurrentDatabase("E:\Audit\audit.accdb")
$Access.Run("fun_run")
$Access.CloseCurrentDatabase()
$Access.Quit()

[System.Runtime.InteropServices.Marshal]::ReleaseComObject($Access)
Remove-Variable Access
Paul Z
  • 27
  • 2
  • 9
  • 1
    [Related](https://stackoverflow.com/a/41635982/1630171). – Ansgar Wiechers Sep 13 '17 at 22:20
  • Are you running the scheduled task with the `Run with highest privileges` option? That can cause permissions issues. – Persistent13 Sep 13 '17 at 22:28
  • Please check Ansgar's link for some excellent troubleshooting steps. Aside from that, there's some info you left out that we would need to really be able to help here. What user context is the scheduled task running as? Is it running with highest privileges? Is the E: drive a local or mapped drive? Does that account being used have rights to logon as a batch job? – TheMadTechnician Sep 13 '17 at 22:51
  • Scheduled user is in the 'Administrator' of the computer and E is a local drive. – Paul Z Sep 13 '17 at 23:14
  • 1
    (1) You should be scripting "fun_run" in powershell, using OLEDB or DAO or ODBC or whatever. "Access.Application" is a heavy object prone to this kind of problem. (2) You need to test if you can even open and close the A.A object. (3) Does the Administrator have a default printer installed? – david Sep 15 '17 at 01:32
  • I would suggest`VBScript`for the beginning. Almost vba, so you just have to make some small adjustments usually. Then migrate to powershell. – BitAccesser Sep 22 '17 at 22:09

0 Answers0