NTDOC
Administrator
Registered: 2000-07-28
Posts: 11625
Loc: CA
Comments on Gargoyles code. Reminder that these are "my opinions" and may not be 100% in line with ideas / recommendations of other experienced scripters. If other Admins, Moderators, or experienced scripters see something that I've commented on that is just plain wrong please join in, however if it is just your own personal preferences or method then please don't do so at this time. As always there are many ways, methods, styles of scripting and one can not always say that one way is always better than another. ;:: My fault, as I was wanting to demonstrate UCase and LCase but I did not specify it ;:: adequately in my instructions. ;:: (imho) These should go after the SETOPTION directives Dim $Bitmap ,$BitMapComp [2 ,1 ],$Count ,$TimeOutComp [4 ],$element ,$String1 ,$String2 ,$String3 ;:: Okay to have here Global $SO ;my throwaway variable to supress any screen output If NOT @LOGONMODE Break On EndIf $SO =SETOPTION ("Explicit" , "ON" )$SO =SETOPTION ("NoMacrosInStrings" , "ON" )$SO =SETOPTION ("NoVarsInStrings" , "ON" )$SO =SETOPTION ("WrapAtEOL" , "ON" );************************************************************************* ;:: Interesting method of setting up for the data $BitMapComp [0 ,0 ] = "\\.\" $BitMapComp [0 ,1 ] = "LOCAL_SYSTEM_Bitmap" $BitMapComp [1 ,0 ] = "\\sacs\" $BitMapComp [1 ,1 ] = "REMOTE_SYSTEM_2K_Bitmap" $BitMapComp [2 ,0 ] = "\\srdc\" $BitMapComp [2 ,1 ] = "REMOTE_SYSTEM_XP_2K3_Bitmap" $TimeOutComp = "srdc" ,"sacs" ,"sutil" ,"svhost04" ,"x019678" $String1 = "The quick or was it now slow fox ran in the snow" $String2 = "The snow in France is now gone but will return again next Winter" $String3 = "There is now a slow return on investments at the bank" ;************************************************************************* $SO = WriteProfileString (@scriptdir +"\KiX-Lesson03.ini" ,"LESSON_03" ,"LOCAL_SYSTEM_MAIN_PID" ,@PID ) ;Launch a second instance of KiX and get the PID for it ;The Second script contains this line ;Exit @PID ;:: Though this method does work it could easily return invalid data if the ;:: shell had some other error or some network error ;:: A more robust method would be to create a temporary file or registry entry with the second script ;:: have the first script read it and do some type of validation check then delete the ;:: temporary file or registry entry. Shell "..\kix32 Round3_2.Kix" $SO = WriteProfileString (@scriptdir +"\KiX-Lesson03.ini" ,"LESSON_03" ,"LOCAL_SYSTEM_SECOND_PID" ,@Error ) ;:: Interesting and good idea for gathering the values. ;:: One could probably expand it though to a 2 dimensional array ;:: but that is way beyond the scope of this Lesson series. ;Get the BitMap Entries For $count = 0 to Ubound ($BitMapComp ) $SO = Bitmap ($BitMapComp [$Count ,0 ],$BitMapComp [$Count ,1 ])Next ;Get the timeout values $Count = 1 For each $element in $TimeOutComp Timeouts ($Element ,$Count ) $Count = $Count + 1 Next ;Get the requested String info ;:: Though the UDF is handling the updates one normally would use the UDF to obtain the data ;:: and then feed it back to the call into a variable. That way the data could easily ;:: be used in other places. As you have it now the data can not be used in other places ;:: if wanted. FindInString ($String1 ,"Now" ,1 )FindInString ($String2 ,"Now" ,2 )FindInString ($String3 ,"Now" ,3 ) ;:: Similar to above comment ;:: Also - the script example I provided above shows why the EXPANDENVIRONMENTVARS ;:: can not be used against a remote system, thus this UDF would not be functional for the task ;:: if I had used another key as shown in that example. ;:: Also - though a bit beyond the scope of this Learning series, since you've used UDFs please ;:: read the UDF Guidlines and How to Create UDFs ;:: Basically there should be error checking and as best as possible they should be very ;:: portable - meaning that someone else could copy them and use them as is without any alteration ;:: of the code. It should provide back either error codes or data (para phrasing...) ;:: Please see FAQ for more information Function Bitmap($Comp , $Value );Now we need the Bitmap value to add to the INI file $Bitmap = Readvalue ($Comp +"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder" ,"Bitmap" ) ;And since we can not include any variables in the output ;Not sure about this part for the remote systems.... It appears to be working correctly ;However how does one know for sure? $Bitmap = ExpandEnvironmentVars ($Bitmap ) ;And write it to the ini $SO = WriteProfileString (@scriptdir +"\KiX-Lesson03.ini" ,"LESSON_03" ,$Value ,$Bitmap ) EndFunction Function Timeouts($Comp ,$Count ) Dim $Time ,$Date ,$DateSplit ;Get the Timeout Value from specified computer ;:: Though KiXtart will allow/handle the "C$\Boot.ini" ;:: I often will over-emphasize by coding it like this 'C'+'$'+'\'+'Boot.ini' ;:: This type of coding also allows you to easily use a VAR instead which allows ;:: you to modify one entry that can then alter for all the other places where used $Time = ReadProfileString ("\\" +$Comp +"\" +"C$\Boot.ini" ,"Boot Loader" ,"TimeOut" ) ;Get the last Modified time of the Boot.ini file ;:: Since you're using a bit more advanced items then I'd expect from a new ;:: KiXtart scripter - you could also use one var instead of hard coding paths or file names ;:: within the code, you could also probably perform the GetFileTime and Split/Join in one line ;:: Again, way beyond the scope of this Lesson, but thought I would point it out ;:: It doesn't have to be "Golfed" down, but does allow for a single more distinct operation ;:: at times if warranted $Date = GetFileTime ("\\" +$comp +"\" +"C$\Boot.ini" ) ;Split the string in half so we can rearrange to specifications $Date = Split ($Date ," " ) ;Split the date apart so that it can be rearranged $DateSplit = Split ($Date [0 ],"/" ) ;Rearrange the date and write it back to the same variable $DateSplit = $DateSplit [1 ] + $DateSplit [2 ]+$DateSplit [0 ] ;Now make a single variable from the 2 in the specified format $Date = $DateSplit + "-" + Join (Split ($Date [1 ],":" ),"" ) ;Write the information to the INI file $SO = WriteProfileString (@scriptdir +"\KiX-Lesson03.ini" ,"LESSON_03" ,"REMOTE_" +$Comp +"_0" +$Count +"_TIMEOUT" ,$Time +" " +$date ) EndFunction ;:: Again, well done, but was hoping to see normal InStr, InStrRev, SubStr, Left, Right style coding ;:: which would be more along the lines of new KiXtart scripters. This is a good intermediate style ;:: that provides good information for new scripters to see and think of as they progress in their understanding ;:: and scripting skill level. Function FindInString($StringToRead ,$SearchPhrase ,$Count )Dim $Array [],$Position ,$ActualValue ;Split up the string $Array = Split ($StringToRead ," " ) ;Look For the phrase that was passed $Position = Ascan ($Array ,$SearchPhrase ) ;Now that we know where the phrase is, Get the requested info $ActualValue = Right ($Array [$Position -1 ],1 ) + Left ($Array [$Position +1 ],1 ) ;Write the information to the INI file $SO = WriteProfileString (@scriptdir +"\KiX-Lesson03.ini" ,"LESSON_03" ,"RANDOM_STRING" +$Count ,$ActualValue ) EndFunction -------------------------------------------------------------------------------- The INI file contents Code: -------------------------------------------------------------------------------- [LESSON_03 ]LOCAL_SYSTEM_MAIN_PID =3824 LOCAL_SYSTEM_SECOND_PID =3356 LOCAL_SYSTEM_Bitmap =C:\WINDOWS\system32\SHELL32.dll ,4 REMOTE_SYSTEM_2K_Bitmap =C:\WINNT\system32\shell32.dll ,4 REMOTE_SYSTEM_XP_2K3_Bitmap =C:\WINDOWS\system32\SHELL32.dll ,4 REMOTE_srdc_01_TIMEOUT =5 03142006 -142913 REMOTE_sacs_02_TIMEOUT =30 11102004 -091359 REMOTE_sutil_03_TIMEOUT =7 10262004 -152634 REMOTE_svhost04_04_TIMEOUT =30 04172006 -144216 REMOTE_x019678_05_TIMEOUT =30 07262006 -134701 RANDOM_STRING1 =ts RANDOM_STRING2 =sg RANDOM_STRING3 =sa