Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

VBScript programming based on WSH

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I also used VBScript when I was in college, but it was all based on ASP. Recently, I tried to program under WSH (windows script host) to list the main information (TNSname, HOST, SID) of tnsnames.ora files under oracle client. The general idea is to judge the oracle path under the current system, read specific path from system variables, read files through file objects under Wscript, separate path, and intercept the need information in ora files. Here is the script for the implementation:

Option explicit'on error resume nextcall MainSub Main dim homes homes = ReadOracleHome call ReadTNS (homes) End Sub'Date:2014-10-15 'Author:AlanFunction ReadTNS (homes) dim iLECHERONE, strHost (100), strServiceName (100), contents,content (10), strTotal,txt set fs = WScript.CreateObject ("Scripting.FileSystemObject") For iMag0 to UBound (homes) If homes (I) "Then' determines whether If fs.FileExists exists in the tns file (Mid (homes (I), 1) Len (homes (I))-3) & "network\ admin\ tnsnames.ora") = true Then 'read tnsnames.ora file set f=fs.getfile (Mid (homes (I), 1 Len (homes (I))-3) & "network\ admin\ tnsnames.ora") set ts = f.OpenAsTextStream (1Magne0) do while ts.AtEndOfStream true For juni0 to 100if ts.AtEndOfStream = true then exit for End if txt= ts.ReadLine If InStr (StrReverse (Trim (txt)), "=") = 1 and InStr (Trim (txt), "(") = 0 Then strTSNname (j) = StrReverse (Mid (Trim (StrReverse (txt)), InStr (Trim (txt) "=") + 1)) 'msgbox strTSNname (j) ElseIf InStr (txt, "(HOST =") > 0 Then If InStr (txt, ") (PORT =") > 0 Then strHost (j) = Trim (SplitStr (txt, "(HOST =", ") (PORT =") Else strHost (j) = Trim (SplitStr (txt, "(HOST =", ")) End If' msgbox strHost (j) ElseIf InStr (txt) "(SERVICE_NAME=") > 0 or InStr (txt, "(SID =") > 0 Then IF InStr (txt, "(SERVICE_NAME=") > 0 Then strServiceName (j) = Trim (SplitStr (txt, "(SERVICE_NAME=", ")") ElseIf InStr (txt, "(SID =") > 0 Then strServiceName (j) = Trim (SplitStr (txt, "(SID =")) (")") End IF 'msgbox strServiceName (j) End If' msgbox "TNSName=" + strTSNname (j) + "HOST=" + strHost (j) + "SERVUCE_NAME/SID=" + strServiceName (j) + vbNewLine Next Loop 'remove null values in the array C) nstrHost= dropArrayNullValue (strHost,maxThree (arecedence bpenc)) nstrServiceName= dropArrayNullValue (strServiceName,maxThree (arecedicine bpenc)) 'organizational text display effect For khon0 to maxThree (arecalebpenc) IF nstrTSNname (k) "and nstrHost (k)"and nstrServiceName (k)"Then If contents="Then contents=" TNSName= "+ addSpaceToString (getMaxLength (nstrTSNname), nstrTSNname (k)) +" HOST= "+ addSpaceToString (getMaxLength (nstrHost)) NstrHost (k)) + "SERVUCE_NAME/SID=" + nstrServiceName (k) + vbNewLine 'contents= "TNSName=" + nstrTSNname (k) + "+" HOST= "+ nstrHost (k) +" + "SERVUCE_NAME/SID=" + nstrServiceName (k) + "+ vbNewLine Else contents=contents+" TNSName= "+ addSpaceToString (getMaxLength (nstrTSNname), nstrTSNname (k)) +" HOST= "+ addSpaceToString (nstrHost) NstrHost (k)) + "SERVUCE_NAME/SID=" + nstrServiceName (k) + vbNewLine 'contents=contents+ "TNSName=" + nstrTSNname (k) + "+" HOST= "+ nstrHost (k) +" + "SERVUCE_NAME/SID=" + nstrServiceName (k) + "" + vbNewLine End If End If Next' msgbox contents content (I) = Mid (homes (I), 1 Len (homes (I))-3) & "TNS information in network\ admin\ tnsnames.ora is as follows:" & vbNewLine+contents' sets the string variable for this loop It is convenient for the next loop to re-assign contents = "'close object set ts=nothing set f = nothing Else MsgBox" No tnsnames.ora file was found under "& Mid (homes (I), 1 Len (homes (I))-3) &" network\ admin\ path. " , "Information" End If End If Next set fs = nothing For item0 to UBound (content) IF content (I) "Then strTotal=strTotal+content (I) + vbNewLine End IF Next call PopupShowStr (strTotal) End Function' read ORACLE_HOME Returns an homes array (because there may be multiple oracle_home) Function ReadOracleHome dim WshShell,WshSysEnv,path,paths,i,oracle_homes,counter Set WshShell = WScript.CreateObject ("WScript.Shell") Set WshSysEnv=WshShell.Environment ("SYSTEM") path= WshSysEnv ("PATH") 'separate ORACLE_HOME paths = Split (path, ") from the system environment variable PATH ",-1 counter=0 For 0 to UBound (paths) If InStr (UCase (paths (I)),"\ APP\ ") > 0 Then If InStr (UCase (paths (I) "\ PRODUCT\") > 0 Then 'MsgBox "Found valid path:" & paths (I) oracle_homes = paths (I) paths (I) = "" paths (counter) = oracle_homes counter=counter+1 End If Else paths (I) = "" End If Next' function FilterOracleHome returns the paths array ReadOracleHome = pathsEnd Function' defines the function Function SplitStr (mainStr,findStartStr,findEndStr) dim strSplit,intStart,intLength If InStr (mainStr) to intercept strings between specified strings FindStartStr) > 0 Then intStart=InStr (mainStr,findStartStr) + Len (findStartStr) intLength= InStr (mainStr,findEndStr)-intStart strSplit = Mid (mainStr,intStart,intLength) End If SplitStr = strSplitEnd Function' define a pop-up box to display text content Function PopupShowStr (string) Dim WshShell Set WshShell = WScript.CreateObject ("WScript.Shell") 'display text content in pop-up box call WshShell.Popup (string,0, "TNS Lists:") End Function' defines a function Function dropArrayNullValue (array) that removes empty values in the array Counter) dim iMagin j Redim arrNew (CInt (counter))'if array (I) is empty Then the following value moves forward For item0 to UBound (array) IF array (I) "" Then arrNew (j) = array (I) j=j+1 End IF Next dropArrayNullValue=arrNewEnd Function' defines the number function Function sumArrayNotNullValue (array) dim iMagne0 to UBound (array) IF array (I) "Then j=j+1 End IF Next sumArrayNotNullValue=jEnd Function' calculates the maximum of the three numbers. C) dim max max=an if a > b then if b > c then max=an else if a > c then max=an else max=c end if end if else if b > c then max=b else max=c end if end if maxThree=maxEnd Function' gets the maximum length Function getMaxLength (array) dim I of the values in the string array Max max=Len (Trim (array (0)) For iTun0 to UBound (array) if Len (Trim (array (I) > max then max=Len (Trim (array (I) the length of each value in the unified string array Length is not enough to fill in the blanks Function addSpaceToString (max,str) if max-Len (str) > 0 then addSpaceToString=str + String (max-Len (str), ") 'Space (max-Len (str)) else addSpaceToString=str end ifEnd Function

Effect display:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report