Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This one is kind of tough..
I'm sure everyone is familiar with LegalNoticeCaption and LegalNoticeText. (If not a quick Google will fill you in).Here's the deal. My LegalNoticeText contains carriage returns. In fact, when i export it to a .reg file and then go to re-import it, it ignores the entry.
The way I write the entry is to use the following VBS file (I'll get to what I am looking to try to do immediately after, I promise!)
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "LegalNoticeCaption"
strValue = "Legal Notice - PLEASE READ!!"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "LegalNoticeText"
strValue = "****************************************************************************** "
strValue = strValue & vbCrLf & vbCrLf
strValue = strValue & "This system is for the use of authorized users only."
strValue = strValue & vbCrLf & vbCrLfstrValue = strValue & "My second line of text."
strValue = strValue & vbCrLf & vbCrLfstrValue = strValue & "My third line of text."
strValue = strValue & vbCrLf & vbCrLfstrValue = strValue & "My fourth line of text."
strValue = strValue & vbCrLf & vbCrLf
strValue = strValue & "****************************************************************************** "
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValueEND OF CODE
Now that I helped any tester achieve the registry entry in question, I need to EVALUATE each reg string value above (LegalNoticeText and LegalNoticeCaption). I need to do this in a batch file (Novell login script) QUICKLY and silently each time the user logs in. This is to verify the EXACT text strings exist in those two locations. If they don't it assumes either the system never had it installed or the user tampered with the registry.
The issue here is that because this is a legal disclaimer, I need to evaluate the exact text strings exist in these two keys, this includes the exclamation points, spacing, etc.
I stopped when I could not set the first variable and include the two exclamation points. I would also guess that our legal folks would accept other stringent evaluation of the existance of these keys even if it is not "exact", per se. (multiple text string searches in the LegalText key)
Any thoughts?

Here's how I'm doing it so far. I am sure it can be simplified. I am a beginner so if there any suggestions to neated up this redundant code, they will be much appreciated.
I'm only searching for parts of strings. It seems to work. I am searching for "so many" parts of the overall text string that I am certain it will meet any requirements to verify that the text does exist.
--------------
@echo offsetlocal EnableExtensions
set RegKeyToSearch="HKLM\Software\Microsoft\Windows NT\CurrentVersion\WinLogon"
set RegVal1ToSearch=LegalNoticeCaption
set RegVal2ToSearch=LegalNoticeText
set RegStringCaption="Legal Notice - PLEASE READ!!"
set RegStringText1="This system is for the use of authorized users only."
set RegStringText2="My second text string"
set RegStringText3="My third text string"
set RegStringText4="My fourth text string"
set RegStringText5="And finally my fifth text string":: Check for LegalNoticeCaption to exist.
:: If exist go to next step, if not goto end.
reg query %RegKeyToSearch% /v %RegVal1ToSearch% | findstr /i /C:%RegStringCaption% >nul
if %errorlevel% == 0 goto :CaptionExists
goto :Failure
:CaptionExists
:: Check for LegalNoticeText line1 to exist.
:: If exist go to next step, if not goto end.
reg query %RegKeyToSearch% /v %RegVal2ToSearch% | findstr /i /C:%RegStringText1% >nul
if %errorlevel% == 0 goto :Text1Exists
goto :Failure:Text1Exists
:: Check for LegalNoticeText line2 to exist.
:: If exist go to next step, if not goto end.
reg query %RegKeyToSearch% /v %RegVal2ToSearch% | findstr /i /C:%RegStringText2% >nul
if %errorlevel% == 0 goto :Text2Exists
goto :Failure:Text2Exists
:: Check for LegalNoticeText line3 to exist.
:: If exist go to next step, if not goto end.
reg query %RegKeyToSearch% /v %RegVal2ToSearch% | findstr /i /C:%RegStringText3% >nul
if %errorlevel% == 0 goto :Text3Exists
goto :Failure:Text3Exists
:: Check for LegalNoticeText line4 to exist.
:: If exist go to next step, if not goto end.
reg query %RegKeyToSearch% /v %RegVal2ToSearch% | findstr /i /C:%RegStringText4% >nul
if %errorlevel% == 0 goto :Text4Exists
goto :Failure:Text4Exists
:: Check for LegalNoticeText line5 to exist.
:: If exist go to next step, if not goto end.
reg query %RegKeyToSearch% /v %RegVal2ToSearch% | findstr /i /C:%RegStringText5% >nul
if %errorlevel% == 0 goto :Text5Exists
goto :Failure:Text5Exists
:: All tests passed.
echo All tests passed.
goto :eof:Failure
echo One or more tests failed. We will log a reinstllation of the new entries...:eof
::exit

Yay for Script-o-matic! Or something.
I don't like to use WMI if I don't have to; the older versions died too easily. As long as you're not running it on a remote computer, WMI will just add to complexity and debug time; Windows Script Host has its own registry methods.
My version of your script does the same thing (in fewer lines, line wrapping aside), but it will only write the keys if it needs to. (Not that there's a reason it can't be written every time.)
Const sCapLoc = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeCaption"
Const sTextLoc = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeText"
Const sCap = "Legal Notice - PLEASE READ!!"
sText = String(78, "*") & vbNewLine _
& "This system is for the use of authorized users only." & vbNewLine _
& "My second line of text." & vbNewLine _
& "My third line of text." & vbNewLine _
& "My fourth line of text." & vbNewLine & String(78, "*")With CreateObject("WScript.Shell")
On Error Resume Next
If .RegRead(sCapLoc) <> sCap _
Or .RegRed(sTextLoc) <> sText _
Or err.Number Then
.RegWrite sCapLoc, sCap, "REG_SZ"
.RegWrite sTextLoc, sText, "REG_SZ"
End If
End WithEDIT: Obviously, you'd stick any logging into that If statement.

![]() |
Parsing HTML with batch
|
Transfer a folder using F...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |