Link to home
Start Free TrialLog in
Avatar of pcalabria
pcalabriaFlag for United States of America

asked on

Need help reading a command line parameter in MS Access MDE

I need help getting command line parameters working with MS Access mde files.

When I use a batch file to start MS Access using the /cmd switch all works fine when I start the mdb... however, when I compile the program the mde does not work.

The code I execute to read the parameter is:
strCommand=Command()

This is the line I use in the BAT file to start and test the MDB. Everything works fine.
"C:\Program Files\Microsoft Office\Office\MSAccess.exe" "c:\disti-master\database\Inventory_Program.mdb" /cmd start MAT

Once compiled to an MDE I tired adding this line to the BAT file.  This line does not work.  It does not return an error, it simply does not read the command line parameter.

"c:\disti-master\database\Inventory_Program.mde" /cmd start MAT

I also tried:

"c:\disti-master\database\Inventory_Program.mde" /cmd "start MAT"

Please help by providing me with a way to have access read the command line parameter "start MAT" when the mde is executed.

Thanks
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Try moving the mdb and mde to subfolder of a safe folder like %LocalAppData%.

It will resolve to something like: C:\Users\<UserName>\AppData\Local
The command should be:


"C:\<path to MSACCESS.EXE>\MSACCESS.EXE"  "c:\disti-master\database\Inventory_Program.mde" /cmd start MAT

Jim.
Avatar of pcalabria

ASKER

@Gustav  Thanks for your suggestion.  Due to the fact that we have Group Policies setup which completely restricts other directories, I have strong incentives to keep the program in the same directory on all the machines.

@JIM  Your solution works, however, this solution does not solve my problem.  

I created support for command line parameter to automatically start the program using different modules for different users, without these users first going through usual log-in and copyright screens.  For example, when MAT starts the program, the program should skip all the nonsense...load the form he uses... populate the form as MAT requires... and then start running automatically.

I hoped to achieve this by adding something like C:\ProgramName.mde /cmd start MAT to AD as a log-in script.  This way any computer MAT uses will yield the same results.  The problem with specifying the full path for MSACCESS.EXE is that XP and Win7 ( and perhaps Win10 and the Access 2016 runtime) us different paths.   Is there any way you know that will allows MAT to always get a special start up?
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<<It might be simpler to just let your initial code read the user name:>>

If this is just user based start-up, then that's the route I would take, but I would use the Windows API to get the user name.   Using environ() can allow to easily spoof another user.

<< C:\ProgramName.mde /cmd start MAT to AD as a log-in script.  >>

  You can't, unless you assign different scripts to different people as you must call the MSACCESS.EXE to get the command line options to work.

 By referencing the MDE, your relying on Windows to find the executable through the explorer shell, and the default there is to only accept the name of the file you want to open.  The rest is ignored.

Jim.
Thanks... I split the points as Jim answered the question and taught me how to use the /cmd option, however, Gustav gave me the solution I needed to solve my problems.

Thanks once AGAIN to BOTH of you!!!
Just be aware that if someone can get to the command box, they can by-pass your security.  

Jim.