Solved

Batch Login Script - Update default homepage

Posted on 2016-11-17
8
61 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

751 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