Solved

Batch Login Script - Update default homepage

Posted on 2016-11-17
8
51 Views
Last Modified: 2016-11-18
Is it possible via some login script to look and see what the user have setup as their home page?  If the default homepage is as followed then replace it with as followed?

Example default homepage is.
http://intranet/
replace with if it matches to
http://intranet2/
If no match then add http://intranet2/

There could be multiple default home pages, so only want to look if it matches the url before updating and if does not match then add.

Could this be done via batch script?
0
Comment
Question by:holemania
  • 6
  • 2
8 Comments
 

Author Comment

by:holemania
ID: 41892056
BTW I am looking at adding this under the "Secondary Start Pages" under the user's registry.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 41892145
Try this; it's in test mode; remove the uppercase ECHO in line 29 to write the new value back to the registry.
@echo off
setlocal enabledelayedexpansion
set OldPage=http://intranet/
set NewPage=http://intranet2/

set Key=HKCU\Software\Microsoft\Internet Explorer\Main
set Value=Secondary Start Pages

reg.exe query "%Key%" /v "%Value%" >NUL 2>&1
if errorlevel 1 (echo No 'Secondary Start Pages', leaving ...&goto :eof)

for /f "tokens=5" %%a in ('reg.exe query "%Key%" /v "%Value%" /se ^, ^| find.exe /i "%Value%"') do set OldList=%%a
echo Old list: %Oldlist%
set NewList=
set ListUpdated=False
for %%a in (%OldList%) do (
	if /i "%%a"=="%OldPage%" (
		set NewList=!NewList!,%NewPage%
		set ListUpdated=True
	) else (
		set NewList=!NewList!,%%a
	)
)
if /i %ListUpdated%==False (
	set NewList=!NewList!,%NewPage%
)
set NewList=%NewList:~1%
echo New list: %NewList%
ECHO reg.exe add "%Key%" /v "%Value%" /t REG_MULTI_SZ /d %NewList% /s , /f

Open in new window

0
 

Author Comment

by:holemania
ID: 41892188
Thanks.  This is not writing to registry for some reason even after I removed the "ECHO" in line 29.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:holemania
ID: 41892195
Going to step through the script and see if i find anything.
0
 

Author Comment

by:holemania
ID: 41892200
Weird it didn't work at first, but seems to be working now.  So if there's no Secondary Start Pages, instead of going to end of file, can we create that key and continue?
0
 

Author Comment

by:holemania
ID: 41892202
The other issue is that it'll keep adding the new URL everytime I log in/out.  Is it possible to not added if it already exists?
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41892261
@echo off
setlocal enabledelayedexpansion
set OldPage=http://intranet/
set NewPage=http://intranet2/

set Key=HKCU\Software\Microsoft\Internet Explorer\Main
set Value=Secondary Start Pages

for /f "tokens=5" %%a in ('reg.exe query "%Key%" /v "%Value%" /se ^, ^| find.exe /i "%Value%"') do set OldList=%%a
echo Old list: %Oldlist%
set NewList=
set ListUpdated=False
set FoundNewPage=False
for %%a in (%OldList%) do (
	if /i "%%a"=="%OldPage%" (
		set NewList=!NewList!,%NewPage%
		set ListUpdated=True
	) else (
		if /i "%%a"=="%NewPage%" (
			set FoundNewPage=True
		)
		set NewList=!NewList!,%%a
	)
)
if /i %FoundNewPage%==True (
	echo List is current.
	goto :eof
)
if /i %ListUpdated%==False (
	set NewList=!NewList!,%NewPage%
)
set NewList=%NewList:~1%
echo New list: %NewList%
ECHO reg.exe add "%Key%" /v "%Value%" /t REG_MULTI_SZ /d %NewList% /s , /f

Open in new window

0
 

Author Closing Comment

by:holemania
ID: 41893078
Thank you.  This works beautifully.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question