在严格的网络管理环境中,最终用户的权限被限制得比较严格,被禁止随意改变系统的行为。在我们的网络环境中,学生是被禁止添加/删除QuickLaunch上的图标的,不仅如此,无线网络,打印机等等,都受到严格的权限控制,这些限制不仅是为了满足教育局的管理目标,同时也是为了能够保证电脑系统能提供持续的而一致的服务,并降低服务需求的措施之一。本文就是在这样的环境需求下书写的。

 

在系统部署的过程中,操作系统和软件等安装和基本配置可以被定制,之后还需要为用户环境进行定制,QuickLaunch的定制就是在实际工作中遇到的一个方面。通过查找资料,其实这个过程还是比较简单的。主要步骤是,在一台电脑上先定制好用户的图标,然后把Shortcuts目录和相关Registry复制下来,再把他们复制到Default用户目录中,这样每个新登陆用户就会自动拥有定制好的图标。

 

在现实中,还有两个问题,一是:对于已经有好多用户使用的电脑上,要部署QuickLaunch图标,需要或者把所有已经存在的本地用户目录删除,当下次登陆时,系统按照新用户处理,或者直接变更这些用户的图标。二是:在模板的基础上,如何把这个过程尽量的自动化一些。这个过程对于我本人来说是熟悉的,如何操作和以后的维护都好办。不过,在一个广域网络环境中,我们有200多所地处本市各地的学校,还有很多基层技术支持人员,他们会面对不同的学校需求,他们需要根据需求定制适合该学校软件环境和教师期望的电脑系统,虽然我们可以有文档辅助大家使用,甚至是培训,但是手动过程应该尽量减少,以减少各个技术人员的个人因素导致的额外问题。所以,定制模板并尽量自动化是一个需要考虑的技术问题。

 

下面,我们来看看我建议的实施过程,并包括所有的脚本/命令文件。

 

手动步骤:

1.备份定制

首先,找到一台试验机,最好是刚刚被重新镜像过的全新系统,所有的软件都已经安装完毕。使用一个至少可以定制QuickLaunch图标以及运行Regisrter的用户登录(最好是本地的 system administrator,后面解释原因),把使用的图标拖拽到QuickLaunch条上,并排列好顺序。然后备份该用户目录中的下列目录:

[html] view plaincopy

"%USERPROFLIE%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

之后使用RegEdit把下面的路径的注册表目录输出到一个文件中

[html] view plaincopy

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband

然后,为了可以方便地部署,需要修改注册表文件的一个部分,需要把HKEY_CURRENT_USER改变为可用的,我给他改为HKEY_USERS\TempHive,见图。其实不一定是TempHive,只要是一个前后使用相同名字的有效Registry键名即可。

 

1.测试

之后,登陆到本地系统管理员帐户,运行RegEdit程序,选择HKEY_USERS,在菜单中选择Load Hive,在文件打开窗中,选择一个用户的NTUSER.DAT文件,并给它一个名字,我们叫它TempHive。然后,在菜单中选择Import...,并选择刚才被修改了的Registry文件,并选择菜单Unload Hive,并保存。见下图:

如果看不见NTUSER.DAT需要在Folder Options中取消Hide protected operating system files(Recommended)。取消它之后,在Windows浏览器中,所有的文件都可见,比较令人烦,所以完成本操作后,最好重新选上。见下图:

 

把先前备份的那个TaskBar目录的所有文件都复制到该用户下面的对应目录中。

登陆到刚才修改了的该用户中,看看图标是不是都改过来了,如果修改的是Default用户,那么用一个新用户登录测试。

自动部署:

如果上面的测试结果有效,那么就可以使用下面的命令文件来自动化这个部署过程。

建立一个目录QuickLanuch_Win7,并建立子目录,Shortcuts和TempRegs。假定我们把TaskBar里的文件复制到Shortcuts中,把那个Registry文件复制到TemRegs中。再把下面的两个命令文件复制到QuickLaunch_Win7目录中。

下面的文件名是Install.cmd

[html] view plaincopy

ECHO OFF


:: ---------------------------------------------------------------------------------------

:: Add QuickLaunch icons for all users

:: History:

:: Initial: Oct 24, 2012 Tony Liu

::

:: Description: Install.cmd.

::

:: How TO:

:: Put all the program shortcuts in Shortcuts folders.

::

:: Copyright (c) 2012, Tony Liu'

::

:: This program is free software; you can redistribute it and/or

:: modify it under the terms of the GNU General Public License

:: as published by the Free Software Foundation; either version 2

:: of the License, or (at your option) any later version.

::

:: This program is distributed in the hope that it will be useful,

:: but WITHOUT ANY WARRANTY; without even the implied warranty of

:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

:: GNU General Public License for more details.

::

:: You should have received a copy of the GNU General Public License

:: along with this program; if not, write to the Free Software

:: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

::

:: Contact: Tonyliu2ca@gmail.com

:: ---------------------------------------------------------------------------------------


cd %~d0

cd %~d0%~p0


Echo ---------------------------------------------------------------------------- >> History.log

Echo : Add QuickLaunch icons for all users : >> History.log

Echo Start: %time%, %date% >> History.log

systeminfo | find "Host Name" >> History.log

Echo Windows Version: >> History.log

systeminfo | find "OS Name" | find "Windows 7" >> History.log

if %ERRORLEVEL% NEQ 0 goto End


for /F "delims=*" %%i in ('dir /A /B %SystemDrive%\Users') do @Putin.cmd "%%i" Shortcuts "History.log"


:End

Echo End: %time%, %date% >> History.log

下面的文件名是putin.cmd

[html] view plaincopy

echo off

:: ---------------------------------------------------------------------------------------

:: Process files in place for one user.

:: History:

:: Initial: Oct 24, 2012 Tony Liu

::

:: Description: Putin.cmd.

::

:: How TO:

:: Put all the program shortcuts in Shortcuts folders and import registry entry.

::

:: Copyright (c) 2012, Tony Liu'

::

:: This program is free software; you can redistribute it and/or

:: modify it under the terms of the GNU General Public License

:: as published by the Free Software Foundation; either version 2

:: of the License, or (at your option) any later version.

::

:: This program is distributed in the hope that it will be useful,

:: but WITHOUT ANY WARRANTY; without even the implied warranty of

:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

:: GNU General Public License for more details.

::

:: You should have received a copy of the GNU General Public License

:: along with this program; if not, write to the Free Software

:: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

::

:: Contact: Tonyliu2ca@gmail.com

:: ---------------------------------------------------------------------------------------


IF NOT Exist %~2 Exit /B 0


IF "%USERNAME%" == "%~1" (

Echo - %1 is Current user. >> %~3

) ELSE (

IF EXIST "%SystemDrive%\Users\%~1\NTUSER.DAT" (

IF EXIST "%SystemDrive%\Users\%~1\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" (

Del /F "%SystemDrive%\Users\%~1\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.lnk"

xcopy %2\*.* "%SystemDrive%\Users\%~1\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\" /Y /I /E /R /H /Q /C


REG load HKU\TempHive "%SystemDrive%\Users\%~1\NTUSER.DAT"

:: for /F "delims=*" %%i in ('dir /A /B ^"%~d0%~p0TempRegs\*.reg^"') do echo ..."%~d0%~p0TempRegs\%%i"

for /F "delims=*" %%i in ('dir /A /B ^"%~d0%~p0TempRegs\*.reg^"') do REG import "%~d0%~p0TempRegs\\%%i"

REG unload HKU\TempHive

Echo - %1 is done. >> %~3

)

) ELSE (

Echo - %1 isn't a user. >> %~3

)

)

如果没有错误,在这个目录中运行Install.cmd就可以在任何一台Win7中为所有用户定制QuickLaunch图标了。

 

自动获取:

通过对自己系统的研究和经验,每个管理员对自己系统都有一个了解,什么是基本的配置,比如我们,MS Word和Internet Explorer是两个所有系统都必备常用的图标,那么我可以做一个基本图标的模板为他人以后添加新图标使用;也可以根据情况作一个最大图标的模板,这样其他人只要是根据自己的情况把无需的删除即可。总之,模板好办。

前面说了,不仅要有模板还有尽量避免人为错误,那么上面的人为错误最容易犯的就是定制图标之后的那些人工步骤,我们通过下面的命令文件和一个VBS脚本,就可以轻松解决了。

把下面的命令文件保存在QuickLaunch_Win7目录中,叫做Make.cmd

[html] view plaincopy

:: ---------------------------------------------------------------------------------------

::

:: Make.cmd for Quicklaunch Win7

::

:: Description:

:: After admin make quick launch icons done in current user, this cmd will copy all the nessary info

:: to correct folder to be ready for deployment.

:: This cmd must be run on the user who make all the icons ready and map to local drive if it is saved

:: on network share folder.

::

:: History:

:: Oct 25, 2012

::

:: Copyright (c) 2012, Tony Liu'

::

:: This program is free software; you can redistribute it and/or

:: modify it under the terms of the GNU General Public License

:: as published by the Free Software Foundation; either version 2

:: of the License, or (at your option) any later version.

::

:: This program is distributed in the hope that it will be useful,

:: but WITHOUT ANY WARRANTY; without even the implied warranty of

:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

:: GNU General Public License for more details.

::

:: You should have received a copy of the GNU General Public License

:: along with this program; if not, write to the Free Software

:: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

::

:: Contact: Tonyliu2ca@gmail.com

:: ---------------------------------------------------------------------------------------



%~d0

cd %~d0%~p0


del Shortcuts\*.*

del TempRegs\*.*


xcopy "%USERPROFLIE%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.*" .\Shortcuts\ /Y /I /E /R /H /Q /C

reg export HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband .\TempRegs\Taskband.reg /y


cscript Replace.vbs .\TempRegs\Taskband.reg "[HKEY_CURRENT_USER\" "[HKEY_USERS\TempHive\"

把下面的文件保存为Replace.vbs(这个VBScript是网上免费找到的)

[html] view plaincopy

Const ForReading = 1

Const ForWriting = 2


strFileName = Wscript.Arguments(0)

strOldText = Wscript.Arguments(1)

strNewText = Wscript.Arguments(2)


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

strText = objFile.ReadAll

objFile.Close


strNewText = Replace(strText, strOldText, strNewText)

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)

objFile.Write strNewText 'WriteLine adds extra CR/LF

objFile.Close

在其他技术人员定制完所有图标后,只要运行该Make.cmd,就可以完成上面手动的各个复制和修改步骤。

 

Tony L.

2012