怎样用脚本更改法律警告消息?

来源:百度文库 编辑:神马文学网 时间:2024/05/01 01:15:24

怎样用脚本更改法律警告消息?

问:

嗨,Scripting Guy!在计算机上怎样才能使用脚本来更改法律警告消息?

-- RB

答:

您好,RB。想必大家都知道,当您按下“Ctrl-Alt-Delete”登录 Windows 时,一般会弹出一个登录框。在登录框中键入用户名、域和密码,单击“确定”,您就可以进入了。

但是,Windows 有个预备措施,可以在按下“Ctrl-Alt-Delete”后出现登录框之前显示一个法律消息对话框。这样,您就有机会向用户显示一条某方面的法律声明。如果用户单击“确定”继续登录,那么表示他们已经同意遵守您在声明中指定的任何规则和规定。这样至少给您带来某种程度的法律保护,防止用户在登录到您的计算机时带来任何损害。

通常,法律警告对话框的标题和消息文本使用“组策略”进行控制;采用“组策略”很容易就可以将该条警告消息应用到您所在域的每台计算机。另一方面,您可能不希望使用“组策略”;或不能使用“组策略”(毕竟,“组策略”需要 Active Directory 的运行);或者您希望对不同的计算机使用不同的消息。这些情况下,脚本应该让医生诊断。

好,当然这里假设医生就是 Scripto。

经证实,“LegalNoticeCaption”和“LegalNoticeText”是注册表中 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 下的一对注册值。要想在计算机上启用警告消息,您需要做的就是为这两项配置值。您可以使用与以下脚本非常类似的脚本来完成:

 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,strValuestrKeyPath = "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 

上述脚本将警告消息对话框标题 (LegalNoticeCaption) 设置为“Fabrikam, Inc. Legal Notice”。然后,脚本将实际消息自身 (LegalNoticeText) 设置为:

“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.

您可能注意到,在这个脚本中,我们使用了几行代码来配置消息。其实并非必须这样做;相反,我们可以使用跨多屏的一长行代码。但是,阅读和修改这样的代码比较困难,因此我们采用多步而非一大步来配置消息。首先,使用下面一行代码为名为 strValue 的变量赋值:

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

现在,看一看脚本中紧接下来的一行:

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

如您所见,现在我们用 strValue 的当前值 (By logging on to this computer you agree to abide by the) 加上“computer usage rules and regulations of Fabrikam, Inc.Fabrikam, Inc.”为 strValue 赋值。此时,变量 strValue 就等于:

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

然后加上几个回车换行符(使用 VBScript 常量 vbCrLf),再加上消息的最后一行。现在,整条消息置于变量 strName 下,即可准备调用 SetStringValue 方法并将此新值写入注册表。

此时,如果您改变主意,决定完全不使用警告消息,会怎么样?如果是这样,只需使用脚本将 LegalNoticeCaption 和 LegalNoticeText 都设置为空字符串即可。这样:

 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,strValuestrKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" strValueName = "LegalNoticeText" strValue = "" objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue 

顺便提醒您,如果您对学习使用脚本操作注册表值颇感兴趣,可以注册参加脚本专家永远不会讲给您听的知识 网络广播,它作为“第 2 周脚本编写”的内容于 2005 年 1 月 27 日开始。我们期待您的参与!