Deployment Solution
239
Deploying Scripts
LOGEVENT -c:2 -l:3 -ss:”Bad command or file not found.”
GOTO END
:ONE
LOGEVENT -c:1 -l:1 -ss:”Error 1.”
:END
Visual Basic Error Handling
By including the
'
vbscript server command in a script deployed to a Windows or DOS
environment, DS executes the script using Visual Basic.
Visual Basic has a powerful, integrated method to handle errors. In these scripts, use
WLogevent.exe to report script status to the server after you have used the built-in
mechanisms to retrieve errors.
The following script contains an example of error handling in Visual Basic script:
On Error Resume Next
Set WSHShell = Wscript.CreateObject("Wscript.shell")
' look on the local computer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
ErrNum = Err.Number
If ErrNum = 0 Then
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where
IPEnabled = True")
'cycle through all of the nics
For Each objNetCard in colNetCards
' if it is the nic we are looking for change the dns
For Each objAddress in objNetCard.IPAddress
If objAddress = "%NIC1IPADDR%" Then
' Set up the array of DNS entries for the NIC
arrDNSServers = Array("172.17.0.202", "172.17.0.201")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
WSHShell.Run ".\WLogevent.exe -c:0 -l:1 -ss:""Changing DNS
for NIC1""", 1, true