Solved

Batch Login Script - Update default homepage

Posted on 2016-11-17
8
72 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 85

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 85

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…

627 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