How Can I Change the Legal Warning Message Using a Script?

ScriptingGuy1

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I use a script to change the legal warning message on a computer?

— RB

SpacerHey, Scripting Guy! AnswerScript Center

Hey, RB. As you all probably know, when you press Ctrl-Alt-Delete to log on to Windows, you’re typically presented with a logon box. You type your user name, domain, and password in the box, click OK, and away you go.

However, Windows includes a provision for displaying a legal message dialog box after you press Ctrl-Alt-Delete but before you’re presented with the logon box. This gives you an opportunity to present users with a legal disclaimer of some kind. If these users click OK and proceed to logon, then they’ve agreed to abide by whatever rules and regulations you specified in your disclaimer. In turn, that gives you at least some legal protection against any kind of … mischief … the user might engage in while logged-on to your computer.

Typically the caption and message text for the legal warning dialog box is controlled using Group Policy; that makes it easy to apply that warning message to every computer in your domain. On the other hand, you might not want to use Group Policy; you might not be able to use Group Policy (after all, Group Policy works only if you’re running Active Directory); or you might want to use different messages for different computers. In cases such as those, scripts might be just what the doctor ordered.

Well, assuming the doctor is Dr. Scripto, of course.

As it turns out, LegalNoticeCaption and LegalNoticeText are a pair of registry values found in the HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon portion of the registry. To enable a legal warning message on a computer, all you have to do is configure values for these two items. And you can do that using a script very similar to this:

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”

Set objReg=GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” strValueName = “LegalNoticeCaption” strValue = “Fabrikam, Inc. Legal Notice” objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = “SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” strValueName = “LegalNoticeText” strValue = “By logging on to this computer you agree to abide by the ” strValue = strValue & “computer usage rules and regulations of Fabrikam, Inc.” strValue = strValue & vbCrLf & vbCrLf strValue = strValue & “For more information, phone (425)-555-1289.” objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

The preceding script sets the caption (LegalNoticeCaption) of the warning message dialog box to Fabrikam, Inc. Legal Notice. It then sets the actual message itself (LegalNoticeText) to this:

By logging on to this computer you agree to abide by the computer usage rules and regulations of Fabrikam, Inc.

For more information, phone (425)-555-1289.

You might notice in the script that we use several lines of code to configure the message. We don’t necessarily have to do that; we could instead use one sprawling line of code that spanned several screens. Code like that is difficult to read and to modify, however, so we configured our message in several steps as opposed to one big step. To begin with, we set the value of a variable named strValue using this line of code:

strValue = “By logging on to this computer you agree to abide by the ”

Now, take a look at the very next line of code in the script:

strValue = strValue & “computer usage rules and regulations of Fabrikam, Inc.”

As you can see, we now assign strValue the existing value of strValue (By logging on to this computer you agree to abide by the) plus this: computer usage rules and regulations of Fabrikam, Inc. Our variable strValue now equals to this:

By logging on to this computer you agree to abide by the computer usage rules and regulations of Fabrikam, Inc.

We then tack on a couple of carriage return-linefeeds (using the VBScript constant vbCrLf) and then the last line of the message. With the entire message now stashed in the variable strName, we’re ready to call the SetStringValue method and write this new value to the registry.

Now, what if you change your mind and decide you don’t want to use a warning message after all? If that happens just use a script and set both LegalNoticeCaption and LegalNoticeText to empty strings. Thus:

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”

Set objReg=GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” strValueName = “LegalNoticeCaption” strValue = “” objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = “SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon” strValueName = “LegalNoticeText” strValue = “” objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

By the way, if you’re interested in learning a bit more about manipulating registry values using scripts, watch the Things the Scripting Guys Never Told You webcast.

0 comments

Discussion is closed.

Feedback usabilla icon