Visual Basic / DOS – Add to Favorites in Internet Explorer with batch file

--> (Word) --> (PDF) --> (Epub)
This article has been published [fromdate]

SCENARIO

I want to add url link to internet explorer by using batch commands in a batch file.For example, i want to add follwoing link:

http://itknowledgeexchange.techtarget.com/itanswers/

using batch commands.

SOLUTION

[tab:VBS Version]

Save the following code from .txt (Notepad flat file) to VBS extension (.vbs):

 
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

To create the shortcut in the Favorites folder just replace this line:

strDesktopPath = WshShell.SpecialFolders(”Desktop”)

with this one:

strDesktopPath = WshShell.SpecialFolders(”Favorites“)

[tab:Batch Version]

A windows command script (.bat file). 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 :FINISH
: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
:FINISH
ECHO. >>%LOG%
now >>%LOG%
ECHO. >>%LOG%
Set log=
==============

[tab:END]

SOURCE

LINK (Techtarget.com)

LANGUAGE
ENGLISH