VBScript to run MS Access form as admin

Jul 5, 2011
Reaction score
First of all, hello to everyone. Long time lurker, just registered.
I have a database (MS Access front end & MS Excel backend)
located on a shared network drive. Each user connected to the
network (which happen to be on the same domain), require to run
a VBScript which I had modified in order to copy a local version of the
said MS Access front end in their 'My Documents' folder, then open
the said front end session with admin privilages (since the user requires
to write/read on the shared Excel backend, which is located on a
restricted folder on the network drive due to the domain users

So far, while running the VBScript on a few user's PCs I've noticed
that the code copies the MS Access database into the user's
'My Documents' folder correctly, and even opens MS Access
with the admin account, but then Access throws in an error
saying that the database path couldn't be found (when in fact
the MS Access front end is there!). This problem is only experienced
by some of the users, not everyone. Any help would be greatly
appreciated as I've been running in circles these last couple of days.

Thanks in advance for any help!

'Date:  2008-05-27
'Author: Daniel Pineault / CARDA Consultants Inc.
'Purpose: This script should be located on a network share in the same
'  directory as the Front-End which it will automatically copy
'  to each user's MyDoc\Subfolder\ and then launch
'  Give your users a link to this script and it will do the rest
'Copyright: You are free to use the following code as you please so long as
'  this header remains unaltered.
'Revision: 2008-05-27   Initial Release
'Modified by nokiaowner to log on using the program as admin
'Date: 30/06/2011  Second Release
 Const MY_DOCUMENTS = &H5&
 Const PROGRAM_FILES = &H26&
 Dim objShell
 Dim objFolder
 Dim objFolderItem
 Dim objNetwork
 Dim objFSO
 Dim objShellDb
 Dim DelFoldr
 Dim sMyDocPath
 Dim sProgPath
 Dim sVBSPath
 Dim sAccPath
 Dim sFrontEnd
 Dim sFolder
 Dim sSec
 Dim sUser
 Dim sPath
 Dim sComTxt
 Dim oEnv
'Specify the Fullpath and filename of the database to launch
 sFrontEnd = "MyDatabase.mdb" 'Database name to open
 sFolder = "Databases"  'MyDoc subfolder where the
      'front-end will be copied to
 'If your database is secured by an mdw file specify it below, otherwise
 'leave its value blank
 sSec = ""
'Determine the location/path of the user's MyDocuments folder
 Set objShell = CreateObject("Shell.Application")
 Set objFolder = objShell.Namespace(MY_DOCUMENTS)
 Set objFolderItem = objFolder.Self
 sMyDocPath = objFolderItem.Path  'My Documents path
 sPath = sMyDocPath & "\" & sFolder & "\"'Path to front-end
 Set objFolder = objShell.Namespace(PROGRAM_FILES)
 Set objFolderItem = objFolder.Self
 sProgPath = objFolderItem.Path  'Program Files Path
'Determine path of this VBScript
 sVBSPath = Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName) _
       - (Len(WScript.ScriptName) + 1)))
 'Ensure lastest version of front-end is installed
 Set objNetwork = CreateObject("Wscript.Network")
 sUser = objNetwork.UserName   'User's network username
 Set objFSO = CreateObject("Scripting.FileSystemObject")
'Copy a network version of the Front-end to the MyDocs/SubFolder
    If objFSO.FolderExists(sPath) then
       'Delete folder to perform cleanup of old version(s)
       Set DelFoldr = objFSO.GetFolder(sPath)
    End if
    'Create folder and then copy required file(s)
    Set objFolderCreate = objFSO.CreateFolder(sPath)
    objFSO.CopyFile sVBSPath & "\" & sFrontEnd, sPath & sFrontEnd, OverWriteExisting
'Determine the location of the MS Access executable
 Set objShellDb = Wscript.CreateObject("WScript.Shell")
 'Determine in which folder the Access executable is located
 If objFSO.FileExists(sProgPath &_
                           "\Microsoft Office\OFFICE11\msaccess.exe") Then
  sAccPath = sProgPath & "\Microsoft Office\OFFICE11"
 Elseif objFSO.FileExists(sProgPath &_
                                 "\Microsoft Office\OFFICE10\msaccess.exe") Then
    sAccPath = sProgPath & "\Microsoft Office\OFFICE10"
 Elseif objFSO.FileExists(sProgPath &_
                                 "\Microsoft Office\OFFICE12\msaccess.exe") Then
    sAccPath = sProgPath & "\Microsoft Office\OFFICE12"
 End if
'Launch database
 'Build the command to launch the database
 sComTxt = chr(34) & sAccPath & "\" & "MSAccess.exe " & "\" & chr(34) & sPath & sFrontEnd & chr(34) & "\" & chr(34)
 if isNull(sSec)=False AND sSec<>"" Then
  sComTxt = sComTxt & " /wrkgrp " & chr(34) & sVBSPath &_
     "\" & sSec & chr(34)
  if isNull(sUser)=False AND sUser<>"" Then
   sComTxt = sComTxt & " /user " & sUser
  End if
 End if
objShellDb.Run "runas /profile /user:domainName\joeDoe " & sComTxt
WScript.Sleep 100
'Replace the string yourpassword~ below with
'the password used on your system. Include tilde 
objShellDb.Sendkeys "mypassword~"
objShellDb.AppActivate("Microsoft Access")
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question