|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Help on WSH - Script is skipping over an instruction
My script makes a call to a function and returns, but on the return it skips the next instruction and continue to complete execution.
Line 77 executes and calls the function. The function should complete and continue to line 81 Instead it skips 81-84 and jumps to 87. Can someone help me - why is my script skipping an instruction set? ============================ Option Explicit 'Stop at all errors by default On Error Goto 0 'AddToHome: If sAdd is not in the string sPath, append sAdd to sPath and return the result; ' otherwise, return sPath unchanged. Function AddToHome ( sAdd, sPath ) If InStr( 1, sPath, sAdd, 1 ) = 0 Then AddToHome = sPath & "\" & sAdd WScript.Echo sAdd & " Has been added to Active Directory Migration registry key." Else AddToHome = sPath End If End Function 'AddToPath: If sAdd is not in the string sPath, append sAdd to sPath and return the result; ' otherwise, return sPath unchanged. Function AddToPath ( sAdd, sPath ) If InStr( 1, sPath, sAdd, 1 ) = 0 Then AddToPath = sPath & ";" & sAdd WScript.Echo sAdd & " added to path." Else AddToPath = sPath End If End Function 'DoScript: The main script procedure. Sub DoScript Dim WshShell, path1, path1a, path2, path2b, strPath, strPathA, strOrigPath, strAppPath, strAppPath1, strPath1, strAppPath2, strPath2 Set WshShell = WScript.CreateObject("WScript.Shell") On Error Resume Next 'Each of these declarations need to be added to the end of the ProductHome value seperately. path1a = "etc\utils" path2b = "etc" 'Write these as a RegKey so that we can read from them later. WshShell.RegWrite "HKLM\Software\Active Directory Migration\path1", path1a, "REG_SZ" WshShell.RegWrite "HKLM\Software\Active Directory Migration\path2", path2b, "REG_SZ" 'Read the ClearCase Install path known as "ProductHome". Exit on errors. strPathA = WshShell.RegRead("HKLM\Software\Atria\ClearCase\CurrentVersion\ProductHome") If Err.Number <> 0 Then Exit Sub 'Read the first path to be added and call the AddToHome function. strAppPath1 = WshShell.RegRead("HKLM\SOFTWARE\Active Directory Migration\path1") If Err.Number = 0 Then strPath1 = AddToHome(strAppPath1, strPathA) End If 'Write a new RegKey that combines ProductHome and Path1. WshShell.RegWrite "HKLM\SOFTWARE\Active Directory Migration\NewPath2bAdded1", strPath1, "REG_SZ" 'Read the second path to be added and call the AddToHome function. strAppPath2 = WshShell.RegRead("HKLM\SOFTWARE\Active Directory Migration\path2") If Err.Number = 0 Then strPath2 = AddToHome(strAppPath2, strPathA) End If 'Write a new RegKey that combines ProductHome and Path2. WshShell.RegWrite "HKLM\SOFTWARE\Active Directory Migration\NewPath2bAdded2", strPath2, "REG_SZ" 'So far, we have searched the Registry to find the correct installation path for ClearCase. We do this because we cannot rely on ClearCase 'always being installed to the default location. Then we create 2 Seperate RegKey's that have the exact path's that we want to add to the 'SYSTEM Path Environment Variable. Now we are going to read the SYSTEM path and add the two individual path's we have created, to it. 'Read the system path. Exit on errors. strPath = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path") If Err.Number <> 0 Then Exit Sub strOrigPath = strPath 'Read the first ClearCase Path and call AddToPath. strAppPath = WshShell.RegRead("HKLM\SOFTWARE\Active Directory Migration\NewPath2bAdded1") If Err.Number = 0 Then strPath = AddToPath(strAppPath, strPath) End If 'Read the second ClearCase Path and call AddToPath. strAppPath = WshShell.RegRead("HKLM\SOFTWARE\Active Directory Migration\NewPath2bAdded2") If Err.Number = 0 Then strPath = AddToPath(strAppPath, strPath) End If 'Update the system path if it's changed. If strPath <> strOrigPath Then WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path", strPath, "REG_EXPAND_SZ" If Err.Number <> 0 Then Exit Sub WScript.Echo "System path updated to:" & vbCrLf & strPath Else WScript.Echo "Path not updated - no updates necessary." End If End Sub Call DoScript() |
|
#2
|
||||
|
||||
|
Why are you using On Error Goto 0 and On Error Resume Next in the same script?
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Help on WSH - Script is skipping over an instruction |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|