例1 DisplayAdminTools.vbs
Set bjshell = CreateObject("Shell.Application")
Set bjNS = objshell.namespace(&h2f)
Set colitems = objNS.items
For Each objitem In colitems
WScript.Echo objitem.name
Next
Table 1-1. Useful registry keys for script. writers
Information | Location |
---|
Service information | HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services |
User name used to log on to the domain | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name |
Microsoft Exchange 2000 domain information | HKEY_CURRENT_USER\Software\Microsoft\Exchange\LogonDomain |
Exchange 2000 domain user information | HKEY_CURRENT_USER\Software\Microsoft\Exchange\UserName |
Group Policy server | HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy\History\DCName |
User's home directory | HKEY_CURRENT_USER\Volatile Environment\HomeShare |
The server that authenticated the currently logged-on user | HKEY_CURRENT_USER\Volatile Environment\LOGONSERVER |
The DNS domain name of the currently logged-on user | HKEY_CURRENT_USER\Volatile Environment\USERDNSDOMAIN |
例2 DisplayComputerNamesWithComments.vbs
'This script. displays various Computer Names by reading the registry
Option Explicit 'forces the scripter to declare variables
On Error Resume Next 'tells VBScript. to go to the next line
'instead of exiting when an error occurs
'Dim is used to declare variable names that are used in the script
Dim objShell
Dim regActiveComputerName, regComputerName, regHostname
Dim ActiveComputerName, ComputerName, Hostname
'When you use a variable name and then an equal sign (=)
'you're saying the variable contains the information on the right.
'The registry keys are quite long, so make them easier to read on
'a single screen by splitting the line in two.
regActiveComputerName = "HKLM\SYSTEM\CurrentControlSet" & _
"\Control\ComputerName\ActiveComputerName\ComputerName"
regComputerName = "HKLM\SYSTEM\CurrentControlSet\Control" & _
"\ComputerName\ComputerName\ComputerName"
regHostname = "HKLM\SYSTEM\CurrentControlSet\Services" & _
"\Tcpip\Parameters\Hostname"
Set bjShell = CreateObject("WScript.Shell")
ActiveComputerName = objShell.RegRead(regActiveComputerName)
ComputerName = objShell.RegRead(regComputerName)
Hostname = objShell.RegRead(regHostname)
'To make dialog boxes you can use WScript.Echo
'and then tell it what you want it to say.
WScript.Echo activecomputername & " is active computer name"
WScript.Echo ComputerName & " is computer name"
WScript.Echo Hostname & " is host name"
例3 registry keys Information.VBS
Option Explicit
On Error Resume Next
Dim objShell
Dim regLogonUserName, regServiceInformation, regGPServer
Dim regLogonServer, regDNSdomain
Dim LogonUserName, ServiceInformation, GPServer
Dim LogonServer, DNSdomain
regLogonUserName = "HKEY_CURRENT_USER\Software\Microsoft\" & _
"Windows\CurrentVersion\Explorer\Logon User Name"
regServiceInformation = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ServiceCurrent"
regGPServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\" & _
"CurrentVersion\Group Policy\History\DCName"
regLogonServer = "HKEY_CURRENT_USER\Volatile Environment\" & _
"LOGONSERVER"
regDNSdomain = "HKEY_CURRENT_USER\Volatile Environment\" & _
"USERDNSDOMAIN"
Set bjShell = CreateObject("WScript.Shell")
LogonUserName = objShell.RegRead(regLogonUserName)
ServiceInformation = objShell.RegRead(regServiceInformation)
GPServer = objShell.RegRead(regGPServer)
LogonServer = objShell.RegRead(regLogonServer)
DNSdomain = objShell.RegRead(regDNSdomain)
WScript.Echo LogonUserName & " is currently Logged on"
WScript.Echo ServiceInformation & " is the current service current"
WScript.Echo GPServer & " is the current Group Policy Server"
WScript.Echo LogonServer & " is the current logon server"
WScript.Echo DNSdomain & " is the current DNS domain"
例4 Crash Recovery Information.VBS
Option Explicit
On Error Resume Next
Dim objShell
Dim regLogonUserName, regServiceInformation, regGPServer
Dim regLogonServer, regDNSdomain
Dim LogonUserName, ServiceInformation, GPServer
Dim LogonServer, DNSdomain
regLogonUserName = "HKEY_CURRENT_USER\Software\Microsoft\" & _
"Windows\CurrentVersion\Explorer\Logon User Name"
regServiceInformation = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ServiceCurrent"
regGPServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\" & _
"CurrentVersion\Group Policy\History\DCName"
regLogonServer = "HKEY_CURRENT_USER\Volatile Environment\" & _
"LOGONSERVER"
regDNSdomain = "HKEY_CURRENT_USER\Volatile Environment\" & _
"USERDNSDOMAIN"
Set bjShell = CreateObject("WScript.Shell")
LogonUserName = objShell.RegRead(regLogonUserName)
ServiceInformation = objShell.RegRead(regServiceInformation)
GPServer = objShell.RegRead(regGPServer)
LogonServer = objShell.RegRead(regLogonServer)
DNSdomain = objShell.RegRead(regDNSdomain)
WScript.Echo LogonUserName & " is currently Logged on"
WScript.Echo ServiceInformation & " is the current service current"
WScript.Echo GPServer & " is the current Group Policy Server"
WScript.Echo LogonServer & " is the current logon server"
WScript.Echo DNSdomain & " is the current DNS domain"
From
Microsoft® VBScript. Step by Step
By Ed Wilson