Solved

Batch Login Script - Update default homepage

Posted on 2016-11-17
8
41 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 83

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
 

Author Comment

by:holemania
ID: 41892195
Going to step through the script and see if i find anything.
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: 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 83

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now