Add to Favorites in Internet Explorer with batch file

5 pts.
Tags:
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 = "http://itknowledgeexchange.techtarget.com/itanswers/"
objShortcutUrl.Save</pre>

++++++++++++++

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

==============
@ECHO OFF
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

ECHO. >>%LOG%
Now >>%LOG%
ECHO. >>%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. >>%LOG%
ECHO Completed processing profile directories
ECHO Completed processing profile directories >>%LOG%
ECHO. >>%LOG%

goto :DONE

:CopySC
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. >>%LOG%
ECHO Processing directory %T101%
ECHO Processing directory %T101% >>%LOG%
ECHO. >>%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%
GOTO :EOF
)

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%
ECHO. >>%LOG%
SET T101=
GOTO :EOF

:RCopyFail
ECHO. >>%LOG
%ECHO Returned ErrorLevel - %EL% >>%LOG%
ECHO Failed to copy files to directory %T101%
ECHO Failed to copy files to directory %T101% >>%LOG%
ECHO. >>%LOG%
SET T101=
SET EL=
GOTO :EOF

:DONE
ECHO. >>%LOG%
now >>%LOG%
ECHO. >>%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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    Notice that the above script will create a shortcut in the desktop, not a favorite in Internet Explorer.
    69,510 pointsBadges:
    report
  • carlosdl
    To create the shortcut in the Favorites folder just replace this line: strDesktopPath = WshShell.SpecialFolders("Desktop") with this one: strDesktopPath = WshShell.SpecialFolders("Favorites")
    69,510 pointsBadges:
    report
  • Shkimran
    You're right, that was copy&paste too quick :)
    0 pointsBadges:
    report
  • 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:
    report
  • 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:
    report
  • 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 = "http://itknowledgeexchange.techtarget.com/itanswers/"
    objShortcutUrl.Save
    69,510 pointsBadges:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following