Reputation: 57
I'm limited to using a .bat file for this function.
I want to be able to create a Desktop Shortcut (with my own icon) to run MS Access Database, but I want "My Icon" to show-up in the Windows TaskBar and not the default MS Access Icon.
To accomplish this, the Target for the Shortcut must be the following:
"C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE" "C:\Users\lmffwp\Downloads\MyDatabase.accdb"
I need the .bat
file to be able to write this line into the "Target" of the Shortcut.
I've googled like crazy, but could not find a solution to this problem. This does not work:
echo oLink.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE" "%USERPROFILE%\Downloads\MyDatabase.accdb" >> %SCRIPT%
Here's my code:
set SCRIPT="%TEMP%\LinkMaker-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%PUBLIC%\Desktop\MyDatabase.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE" "%USERPROFILE%\Downloads\MyDatabase.accdb" >> %SCRIPT%
echo oLink.IconLocation = "J:\Everyone\Operator Assistant\Images\MyDatabaseLOGO.ico" >> %SCRIPT%
echo oLink.WorkingDirectory = "%USERPROFILE%\Downloads\"
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
There must be a way to be able to add the 2 parts of the following line that are enclosed in quotes to the Target of the Shortcut:
echo oLink.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE" "%USERPROFILE%\Downloads\MyDatabase.accdb" >> %SCRIPT%
I believe this is the breakdown of my actual problem.
SIDE NOTE: The Shortcut works perfectly if I manually change the target line of the shortcut. I need the .bat file to do this for me as it's the installation file that each person uses to install the front end of the database to their local PC.
Upvotes: 1
Views: 3686
Reputation: 38579
What you want to do, I think is to add arguments to your TargetPath
. Without the arguments, the script will, as already stated in my 'since deleted' comment, not give you the icon for the MyDatabase.accdb
in the taskbar, only for MSAccess.exe
which is the program you are running.
Here's a modification of your code for further perusal:
@Set "SCRIPT=%TEMP%\LinkMaker-%RANDOM%-%RANDOM%.vbs"
@( echo Set oWS = WScript.CreateObject("WScript.Shell"^)
echo sLinkFile = "%PUBLIC%\Desktop\MyDatabase.lnk"
echo Set oLink = oWS.CreateShortcut(sLinkFile^)
echo oLink.TargetPath = "C:\Program Files (x86^)\Microsoft Office\Office15\MSACCESS.EXE"
echo oLink.Arguments = """%USERPROFILE%\Downloads\MyDatabase.accdb"""
echo oLink.IconLocation = "J:\Everyone\Operator Assistant\Images\MyDatabaseLOGO.ico"
echo oLink.WorkingDirectory = "%USERPROFILE%\Downloads"
echo oLink.Save
)>"%SCRIPT%"
@"%__AppDir__%cscript.exe" //NoLogo "%SCRIPT%"
@Del "%SCRIPT%"
Side note: You appear to have missed appending >> %SCRIPT%
to your working directory line in your version.
Upvotes: 0
Reputation: 57
COMPO....thank you for all of your help. While you didn't get the final answer, you were way beyond helpful.
Here is the Code that absolutely works!!!!
@echo off
@Set "SCRIPT=%TEMP%\LinkMaker-%RANDOM%-%RANDOM%.vbs"
@( echo Set oWS = WScript.CreateObject("WScript.Shell"^)
echo sLinkFile = "%PUBLIC%\Desktop\MyDatabase.lnk"
echo Set oLink = oWS.CreateShortcut(sLinkFile^)
echo oLink.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE"
echo oLink.Arguments = """%USERPROFILE%\Downloads\MyDatabase.accdb"""
echo oLink.IconLocation = "J:\Everyone\MyDatabase\Images\MyDatabaseLOGO.ico"
echo oLink.WorkingDirectory = "%USERPROFILE%\Downloads"
echo oLink.Save
)>"%SCRIPT%"
@"%__AppDir__%cscript.exe" //NoLogo "%SCRIPT%"
@Del "%SCRIPT%"
Notice that there are 3 Quote Marks on each side of the oLink.Argument line. This did the trick and allowed for a smooth run of the .bat file that not only created the Desktop Shortcut, but also uses my Custom Made Icon for my database on the Windows Taskbar (bottom of screen).
Once again...a huge thanks to COMPO for his efforts! Thanks for hanging in there for me!
Upvotes: 1