Add to Favorites in Internet Explorer with batch file

5 pts.
Batch files
Browser bookmarks
Internet Explorer
I want to add an URL link to Internet Explorer by using batch commands in a batch file. For example, I want to add following link, ITKnowledgeExchange, using batch commands. Thanks!

Answer Wiki

Thanks. We'll let you know when a new response is added.

Save the following code to VBS extension

<pre>Set WshShell = CreateObject("WScript.Shell")
strDesktopPath = WshShell.SpecialFolders("Desktop")
Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\IT Answers.url")
objShortcutUrl.TargetPath = ""


A windows command script. Unwrap the FOR loops and robocopies.

REM This script assumes that the Windows Resource Kit tools are installed and in the path.
REM Remove the NOW command lines if not available.
REM This assumes running on the target machine.
REM Modify it to your needs.

if not exist %SystemRoot%\Debug\. md %SystemRoot%\Debug
Set log=%SystemRoot%\Debug\FavoritesUpdate.log

Now >>%LOG%
ECHO Process each profile directory to add shortcuts
ECHO Process each profile directory to add shortcuts >>%log%
REM Pull out the root of the profile path
REM If you have moved the profile directory, this may need to be modified.
FOR /F "tokens=1,2 delims=\ usebackq" %%a IN (`Echo %USERPROFILE%`) DO SET ProfilePathRoot=%%a\%%b
REM Process each profile directory
for /d %%B in ("%ProfilePathRoot%\*") do CALL :CopySC "%%B"
ECHO Completed processing profile directories
ECHO Completed processing profile directories >>%LOG%

goto :DONE

REM Strip double quotes
SET T101=%1
set T101=%T101:~1,-1%
REM Skip non-user profiles
IF /i "%T101%"=="D:\Documents and Settings\All Users" GOTO :EOF
IF /i "%T101%"=="D:\Documents and Settings\Default User" GOTO :EOF
IF /i "%T101%"=="D:\Documents and Settings\NetworkService" GOTO :EOF
IF /i "%T101%"=="D:\Documents and Settings\LocalService" GOTO :EOF

ECHO Processing directory %T101%
ECHO Processing directory %T101% >>%LOG%

ECHO Validate the favorites directory exists >>%LOG%
IF NOT EXIST "%T101%\Favorites" (
ECHO Directory "%T101%\Favorites" not found, skipping
ECHO Directory "%T101%\Favorites" not found, skipping >>%LOG%

REM Replace the dummy source path with the location of your shortcuts.
REM Ensure that the credentials you run this under have access to the files.
ECHO robocopy \\MySrvr\MyShare\Myfolder "%T101%\Favorites" *.lnk /R:5 /W:3 /NP /Z /XX /TEE /LOG+:%SystemRoot%\Debug\FavoritesUpdate_RC.log >>%LOG%
robocopy \\MySrvr\MyShare\Myfolder "%T101%\Favorites" *.lnk /R:5 /W:3 /NP /Z /XX /TEE /LOG+:%SystemRoot%\Debug\FavoritesUpdate_RC.log
if errorlevel 4 (
SET EL=%errorlevel%
GOTO :RCopyFail
ECHO Returned ErrorLevel - %errorlevel% >>%LOG%
SET T101=

%ECHO Returned ErrorLevel - %EL% >>%LOG%
ECHO Failed to copy files to directory %T101%
ECHO Failed to copy files to directory %T101% >>%LOG%
SET T101=

now >>%LOG%
Set log=

Discuss This Question: 6  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    Notice that the above script will create a shortcut in the desktop, not a favorite in Internet Explorer.
    84,975 pointsBadges:
  • carlosdl
    To create the shortcut in the Favorites folder just replace this line: strDesktopPath = WshShell.SpecialFolders("Desktop") with this one: strDesktopPath = WshShell.SpecialFolders("Favorites")
    84,975 pointsBadges:
  • Alessandro Panzetta
    You're right, that was copy&paste too quick :)
    0 pointsBadges:
  • Toggler
    I am actually attempting to do the same thing only I want mine to be added automatically to the links toolbar in IE.. can it be done at all via either the registry or batch file? thanks Dan
    80 pointsBadges:
  • Sliverme
    Thanks Carlosdl, works great. Is there a way to edit it so that I could run it as administrator and have it affect all users desktops? Thanks again...
    10 pointsBadges:
  • carlosdl
    I thought we could use the "AllUsersFavorites" special folder, but the SpecialFoders function does not find such a folder. So, we can use the "AllUsersDesktop" special folder, and then replace "Desktop" with "Favorites" in the returned path. I have not tested it, but I think this should work:
    Set WshShell = CreateObject("WScript.Shell")
    strPath = replace(WshShell.SpecialFolders("AllUsersDesktop"),"Desktop","Favorites")
    Set objShortcutUrl = WshShell.CreateShortcut(strPath  & "IT Answers.url")
    objShortcutUrl.TargetPath = ""
    84,975 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: