Windows Scheduled Task - logon Password (1 Viewer)

FrostByte

Registered User.
Local time
Today, 21:24
Joined
Jan 15, 2015
Messages
56
Hi,

I have managed to create a task using windows scheduler which opens Access and runs a macro.

The macro runs if I manually enter the Logon Password (which is set under "Manage Users & Permissions" > User and Group Accounts) under Access 2016.

Is there a way to set this password in the scheduler or script, to avoid me having to manually enter it (which ruins the whole idea of a scheduled task)?


Thanks in advance
Steve
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:24
Joined
May 7, 2009
Messages
19,247
maybe add a script (vbscript or something) to your scheduled task that after the database is opened, you SendKeys the password.
 

FrostByte

Registered User.
Local time
Today, 21:24
Joined
Jan 15, 2015
Messages
56
---Update---

As per below.... With a massive thanks to Daniel Pineault I have managed to open a DB and use the /User and /pwd switches to pass a variable automatically!!

Note: I slightly edited it to include the /pwd switch

What I now DON'T know how to do, is run a macro after the DB is opened (from this code)!

Regards
Steve



'*******************************************************************************
'Date: 2008-05-27
'Author: Daniel Pineault / CARDA Consultants Inc.
' http://www.cardaconsultants.com
'Copyright: You are free to use the following code as you please so long as
' this header remains unaltered.
'Purpose: Launch the specified access database
'Revision: 2008-05-27 Initial Release
'*******************************************************************************

Dim sAcc
Dim sFrontEnd
Dim sSec
Dim sUser
Dim sPW
Dim objShellDb
Dim sComTxt

'Script Configuration Variable
'*******************************************************************************
'Specify the Fullpath and filename of the msaccess executable
sAcc = "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.exe"
'Specify the Fullpath and filename of the database to launch
sFrontEnd = "C:\Directory\MyDBFile.mdb"
'If your database is secured by an mdw file specify it below, otherwise
'leave its value blank
sSec = "C:\Directory\MyMDWFile.mdw"
'If your database is secured by an mdw file and you want to specify the
'username to use specify it below, otherwise leave its value blank
sUser = "UsernameHERE"
'password to use specify it below, otherwise leave its value blank
sPW = "PasswordHERE"


'*******************************************************************************
'*******************************************************************************
'You should not need to edit anything below this point
'*******************************************************************************
'*******************************************************************************


'Launch database
'*******************************************************************************
Set objShellDb = CreateObject("WScript.Shell")
'Build the command to launch the database
sComTxt = chr(34) & sAcc & chr(34) &_
" " & chr(34) & sFrontEnd & chr(34)
if isNull(sSec)=False AND sSec<>"" Then
sComTxt = sComTxt & " /wrkgrp " & chr(34) & sSec & chr(34)
End if
if isNull(sUser)=False AND sUser<>"" Then
sComTxt = sComTxt & " /user " & sUser
End if
if isNull(sPW)=False AND sPW<>"" Then
sComTxt = sComTxt & " /pwd " & sPW
End if
objShellDb.Run sComTxt 'Launch the database
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:24
Joined
Sep 21, 2011
Messages
14,361
Name the macro Autoexec or use the x switch as mentioned in the link.?


If using the switch
Code:
'************************************************* ******************************
'Date: 2008-05-27
'Author: Daniel Pineault / CARDA Consultants Inc.
' http://www.cardaconsultants.com
'Copyright: You are free to use the following code as you please so long as
' this header remains unaltered.
'Purpose: Launch the specified access database
'Revision: 2008-05-27 Initial Release
'************************************************* ******************************

Dim sAcc
Dim sFrontEnd
Dim sSec
Dim sUser
Dim sPW
Dim objShellDb
Dim sComTxt
[COLOR=red]Dim sMacro[/COLOR]
'Script Configuration Variable
'************************************************* ******************************
'Specify the Fullpath and filename of the msaccess executable
sAcc = "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.exe"
'Specify the Fullpath and filename of the database to launch
sFrontEnd = "C:\Directory\MyDBFile.mdb"
'If your database is secured by an mdw file specify it below, otherwise
'leave its value blank
sSec = "C:\Directory\MyMDWFile.mdw"
'If your database is secured by an mdw file and you want to specify the
'username to use specify it below, otherwise leave its value blank
sUser = "UsernameHERE"
'password to use specify it below, otherwise leave its value blank
sPW = "PasswordHERE"
[COLOR=red]sMacro = "YourMacroHere"[/COLOR]


'************************************************* ******************************
'************************************************* ******************************
'You should not need to edit anything below this point
'************************************************* ******************************
'************************************************* ******************************


'Launch database
'************************************************* ******************************
Set objShellDb = CreateObject("WScript.Shell")
'Build the command to launch the database
sComTxt = chr(34) & sAcc & chr(34) &_
" " & chr(34) & sFrontEnd & chr(34)
if isNull(sSec)=False AND sSec<>"" Then
sComTxt = sComTxt & " /wrkgrp " & chr(34) & sSec & chr(34)
End if
if isNull(sUser)=False AND sUser<>"" Then
sComTxt = sComTxt & " /user " & sUser
End if
if isNull(sPW)=False AND sPW<>"" Then
sComTxt = sComTxt & " /pwd " & sPW [COLOR=Red]& " /x " & sMacro[/COLOR]
End if
objShellDb.Run sComTxt 'Launch the database
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 21:24
Joined
Jan 14, 2017
Messages
18,247
As Gasman said, you can call the macro autoexec but that means it will run each time you start your database, whether run fr4om scheduled tasks or otherwise

Personally I would use the /x switch as listed in the link I gave in post #3 as it gives more flexibility

For info you can also run a function automatically using the /cmd switch.
e.g. if /cmd "Attendance" is used, it runs an UpdateAttendance procedure
In that case there is an extra step needed

As an example, the code below gives 4 possible ways of running a database depending on the /cmd switch used
The code is used in the Form_Load event of the startup form

NOTE: don't omit the line in BOLD or it won't work!

Code:
Private Sub Form_Load()

'get the command line switch used to open the app (if any)
Dim ComLineArgs As String
[B]ComLineArgs = Trim(Command())[/B]

Select Case ComLineArgs
Case "Admin"
        DoCmd.Close acForm, Me.Name
       [COLOR="SeaGreen"] 'open admin form[/COLOR]
        DoCmd.OpenForm "frmAdmin"
Case "Settings"
        DoCmd.Close acForm, Me.Name
         [COLOR="SeaGreen"] 'open settings form[/COLOR]
         DoCmd.OpenForm "frmSettings"
Case "Attendance"
        DoCmd.Close acForm, Me.Name
        [COLOR="seagreen"]'run code[/COLOR]
        UpdateAttendance
Case Else
     'do something else
End Select

'any other code here

End Sub

HTH
 

FrostByte

Registered User.
Local time
Today, 21:24
Joined
Jan 15, 2015
Messages
56
Thanks Gasman / isladogs. Im going to play about with these options tomorrow.

What if I wanted to run more than one macro?

I also think this is a great post for other users!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:24
Joined
Feb 28, 2001
Messages
27,226
To run more than one macro, have your one macro do a RunCode and have the called function trigger multiple macros.

Always always ALWAYS remember to end your outermost macro with something that quits the application so you don't leave it hanging open when you wanted it closed.
 

isladogs

MVP / VIP
Local time
Today, 21:24
Joined
Jan 14, 2017
Messages
18,247
The same point applies if you want to run multiple functions. Just enclose them in an overall 'wrapper' function or of course a macro
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:24
Joined
May 7, 2009
Messages
19,247
just to remind the audience that the script will only run to db, mdb prior to a2k7.
 

Users who are viewing this thread

Top Bottom