脚本中心
计算机管理示例脚本
该页面里包含一些脚本,这些脚本通常适用于在Windows 2000, Windows XP, and Windows Server 2003中进行激活、配置、重命名等操作。可以更方便的帮助IT专业人员管理计算机。


更改计算机帐号属性

描述

演示如何通过脚本来更改 Active Directory 中的计算机帐号的位置属性。

脚本代码

  1. Set objComputer = GetObject _  
  2.     ("LDAP://CN=atl-dc-01,CN=Computers,DC=fabrikam,DC=com")  
  3. objComputer.Put "location""Building 37, Floor 2, Room 2133" 
  4. objComputer.SetInfo 



离线激活 Windows

描述

使用离线方法来激活 Windows。需要 Windows XP 或 Windows Server 2003、以及一个有效的激活编号。

脚本代码

  1. strComputer = "." 
  2. Set objWMIService = GetObject("winmgmts:" & _  
  3.     "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
  4. Set colWindowsProducts = objWMIService.ExecQuery _  
  5.     ("SELECT * FROM Win32_WindowsProductActivation")  
  6. For Each objWindowsProduct In colWindowsProducts  
  7.     objWindowsProduct.ActivateOffline("1234-1234")  
  8. Next 



在线激活 Windows

描述

使用在线方法来激活 Windows。需要 Windows XP 或 Windows Server 2003、以及活动的 Internet 连接。

脚本代码

  1. strComputer = "." 
  2. Set objWMIService = GetObject("winmgmts:" & _  
  3.     "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
  4. Set colWindowsProducts = objWMIService.ExecQuery _  
  5.     ("SELECT * FROM Win32_WindowsProductActivation")  
  6. For Each objWindowsProduct In colWindowsProducts  
  7.     objWindowsProduct.ActivateOnline()  
  8. Next 



配置系统启动延时

描述

将计算机配置为在启动时自动加载默认操作系统之前等待 10 秒钟(而不是默认的 30 秒钟)。

脚本代码

  1. strComputer = "." 
  2. Set objWMIService = GetObject("winmgmts:" & _  
  3.     "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
  4. Set colStartupCommands = objWMIService.ExecQuery _  
  5.     ("SELECT * FROM Win32_ComputerSystem")  
  6. For Each objStartupCommand In colStartupCommands  
  7.     objStartupCommand.SystemStartupDelay = 10  
  8.     objStartupCommand.Put_  
  9. Next 



配置 WMI 设置

描述

配置 WMI 备份时间间隔和日志记录级别。

脚本代码

  1. strComputer = "."   
  2. Set objWMIService = GetObject("winmgmts:" & _   
  3.     "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")   
  4. Set colWMISettings = objWMIService.ExecQuery _   
  5.     ("SELECT * FROM Win32_WMISetting")   
  6. For Each objWMISetting In colWMISettings   
  7.     objWMISetting.BackupInterval = 60   
  8.     objWMISetting.LoggingLevel = 2   
  9.     objWMISetting.Put_   
  10. Next 



获取操作系统属性

描述信息

获取有关计算机上所安装的操作系统信息,其中包括语言种类、加密级别和内建编号等。

脚本代码

  1. Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")  
  2. strComputer = "." 
  3. Set objWMIService = GetObject("winmgmts:" _  
  4.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
  5. Set colOperatingSystems = objWMIService.ExecQuery _  
  6.     ("Select * from Win32_OperatingSystem")  
  7. For Each objOperatingSystem in colOperatingSystems  
  8.     Wscript.Echo "Boot Device: " & objOperatingSystem.BootDevice  
  9.     Wscript.Echo "Build Number: " & objOperatingSystem.BuildNumber  
  10.     Wscript.Echo "Build Type: " & objOperatingSystem.BuildType  
  11.     Wscript.Echo "Caption: " & objOperatingSystem.Caption  
  12.     Wscript.Echo "Code Set: " & objOperatingSystem.CodeSet  
  13.     Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode  
  14.     Wscript.Echo "Debug: " & objOperatingSystem.Debug  
  15.     Wscript.Echo "Encryption Level: " & objOperatingSystem.EncryptionLevel  
  16.     dtmConvertedDate.Value = objOperatingSystem.InstallDate  
  17.     dtmInstallDate = dtmConvertedDate.GetVarDate  
  18.     Wscript.Echo "Install Date: " & dtmInstallDate   
  19.     Wscript.Echo "Licensed Users: " & _  
  20.         objOperatingSystem.NumberOfLicensedUsers  
  21.     Wscript.Echo "Organization: " & objOperatingSystem.Organization  
  22.     Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage  
  23.     Wscript.Echo "OS Product Suite: " & objOperatingSystem.OSProductSuite  
  24.     Wscript.Echo "OS Type: " & objOperatingSystem.OSType  
  25.     Wscript.Echo "Primary: " & objOperatingSystem.Primary  
  26.     Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser  
  27.     Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber  
  28.     Wscript.Echo "Version: " & objOperatingSystem.Version  
  29. Next 


复制Active Directory计算机帐号

描述信息

获取现有计算机对象属性,并将这些属性复制到通过脚本创建的新增计算机对象中。

脚本代码

  1. Set objCompt = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")  
  2. Set objComptCopy = objCompt.Create("computer""cn=SEA-SQL-01")  
  3. objComptCopy.Put "sAMAccountName""sea-sql-01" 
  4. objComptCopy.SetInfo  
  5. Set objComptTemplate = _  
  6.   GetObject("LDAP://cn=SEA-PM-01,cn=Computers,dc=NA,dc=fabrikam,dc=com")  
  7. arrAttributes = Array("description""location")  
  8. For Each strAttrib in arrAttributes  
  9.   strValue = objComptTemplate.Get(strAttrib)  
  10.   objComptCopy.Put strAttrib, strValue  
  11. Next 
  12. objComptCopy.SetInfo 



执行计算机对象的跨域迁移

描述信息

利用 IADsContainer 中的 MoveHere 方法将对象迁移到其他域中。

脚本代码

  1. Set objOU = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")  
  2. objOU.MoveHere "LDAP://cn=Computer01,cn=Users,dc=fabrikam,dc=com", _  
  3.  vbNullString 



执行系统还原

描述信息

在计算机上使用系统还原点 No. 20 来执行系统还原。要使用不同的系统还原点来执行系统还原,则只需更改 RESTORE_POINT 常量值即可。

有关在这段脚本中使用的 CreateRestorePoint 方法的更多信息,单击此处。

支持平台

Windows Server 2003
 否
 
Windows XP
 是
 
Windows 2000
 否
 
Windows NT 4.0
 否
 

脚本代码

  1. Const RESTORE_POINT = 20  
  2. strComputer = "." 
  3. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")  
  4. Set objItem = objWMIService.Get("SystemRestore")  
  5. errResults = objItem.Restore(RESTORE_POINT)  
  6. Wscript.Echo errResults 

本日志由 flyinweb 于 2009-06-18 19:29:18 发表到 Windows 中,目前已经被浏览 3806 次,评论 0 次;

作者添加了以下标签: 计算机管理脚本