buymeapc Posted June 11, 2008 Posted June 11, 2008 I have created a script to read a source text file which has a list of IP addresses and map a drive to those IP's (the c$), then check first to see if a certain file exists, then if it does, log the version number. The results get spit out into a log file. The way I have written it takes literally all day since the source contains over 1,000 IP's. Also, there are PC's in this list that have different credentials and I currently test via trial and error to see which PC has which credentials.Could I ask for some help please and see what I could possibly do to improve this script?Also, a strange thing that occurs is sometimes I get a "Undefined / Other error" in the log for Windows 2000 PC's and I don't know why. Most PC's are XP, though and do not log this error.Thank you.expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=PatchCheck.exe #AutoIt3Wrapper_Res_Fileversion=1.0.0.2 #AutoIt3Wrapper_Res_Language=1033 #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** ;6/6/08 - Added basic support for version numbers #include <File.au3> #include <Array.au3> ;The ini file must always reside in the same folder with the executable... $iniPath = @ScriptDir & "\locations.ini" ;Ini file creation ;=================================================================== $iniFile = FileExists($iniPath) ;Check if ini file exists, if it does NOT, create one with default values ;If the ini file does not exist, after creating one with default values, the script will close so the user can adjust it to their liking If $iniFile = 0 Then _FileCreate($iniPath) IniWrite($iniPath, "Locations", "loc1", '"O:\SetUp Apps\Misc\Lsass.exe"') IniWrite($iniPath, "Locations", "loc2", '""') IniWrite($iniPath, "Locations", "loc3", '""') IniWrite($iniPath, "Locations", "loc4", '""') MsgBox(64, @ScriptName, "This appears to be the first time "& @ScriptName & " has been run."&@CRLF&"The ini file was just created in: "&@CRLF&@CRLF & @ScriptDir &@CRLF&@CRLF&@CRLF&@CRLF&"The script will now close so that you can adjust the ini file to your liking."&@CRLF&@CRLF&@CRLF&"The next time you double-click on "&@ScriptName&", it will run."&@CRLF&"No changes have been made to your system at this time.") Exit EndIf ;Grab all the variables from the ini file ;=================================================================== $loc1 = IniRead($iniPath, "Locations", "loc1", '""') $loc2 = IniRead($iniPath, "Locations", "loc2", '""') $loc3 = IniRead($iniPath, "Locations", "loc3", '""') $loc4 = IniRead($iniPath, "Locations", "loc4", '""') Dim $ip Global $File_Array Global $Results $sourcedoc = @ScriptDir&"\Source.txt" $log = @ScriptDir&"\Results_"&@MON&"-"&@MDAY&"-"&@YEAR&".txt" ;Look for the source doc first - if it can't find it, then exit If FileExists($sourcedoc) = 0 Then MsgBox(16, "Oops...", "Couldn't find 'Source.txt' in the '"&@ScriptDir&"' directory."&@CRLF&@CRLF&"Exiting Now.") Exit EndIf If FileExists($log) = 0 Then FileWrite($log, "") ;Read the entire doc into an array _FileReadToArray($sourcedoc, $File_Array) _ArraySort($File_Array, 0, 1) ;Go through each IP in the doc and map a drive to each PC and get the required info and then spit it into a log For $x = 1 To $File_Array[0] If $File_Array[$x] <> "" Then $Results = "" CheckIP($File_Array[$x]) If $Results <> "" Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&$Results) Else DriveMapDel("O:") DriveMapAdd("O:", "\\" & $File_Array[$x] & "\c$", 1, "user1", "pass1") $pass = "1" If @error Then DriveMapAdd("O:", "\\" & $File_Array[$x] & "\c$", 1, "user2", "pass2") $pass = "2" If @error Then DriveMapAdd("O:", "\\" & $File_Array[$x] & "\c$", 1, "user3", "pass3") $pass = "3" If @error Then Select Case @error = 1 $Results = "Undefined / Other error" Case @error = 2 $Results = "Access to the remote share was denied" Case @error = 3 $Results = "The device is already assigned" Case @error = 4 $Results = "Invalid device name" Case @error = 5 $Results = "Invalid remote share" Case @error = 6 $Results = "Invalid password" EndSelect EndIf EndIf EndIf If $Results <> "" Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&$Results & @TAB & @extended) Else If FileExists($loc1) = 1 Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&"File exists in " & StringReplace($loc1, "O:\", "C:\") & @TAB & FileGetVersion($loc1) & @TAB&@TAB & $pass) ElseIf FileExists($loc2) = 1 Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&"File exists in " & StringReplace($loc2, "O:\", "C:\") & @TAB & FileGetVersion($loc2) & @TAB&@TAB & $pass) ElseIf FileExists($loc3) = 1 Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&"File exists in " & StringReplace($loc3, "O:\", "C:\") & @TAB & FileGetVersion($loc3) & @TAB&@TAB & $pass) ElseIf FileExists($loc4) = 1 Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&"File exists in " & StringReplace($loc4, "O:\", "C:\") & @TAB & FileGetVersion($loc4) & @TAB&@TAB & $pass) ElseIf FileExists($loc1) = 0 And FileExists($loc2) = 0 And FileExists($loc3) = 0 And FileExists($loc4) = 0 Then FileWriteLine($log, $File_Array[$x]&@TAB&@TAB&"***File does NOT exist.***" & @TAB&@TAB & $pass) EndIf EndIf EndIf $percent = Round(($x / $File_Array[0])*100, 0) TrayTip("Percent Done", $percent&" %", 5) EndIf Next DriveMapDel("O:") Exit Func CheckIP($ip) $aIP = StringSplit($ip, ".") If $aIP[0] <> 4 Then $Results = "IP address is an incorrect length." Else For $i = 1 to 4 If Not StringIsDigit($aIP[$i]) Then $Results = $aIP[$i]&" is not a digit." EndIf If Number($aIP[$i]) < 0 Or Number($aIP[$i]) > 255 Then $Results = "Octet "&$aIP[$i]&" is not correct." EndIf Next If $ip = "0.0.0.0" Or $ip = "255.255.255.255" Then $Results = "IP is not valid." EndIf EndIf $Ping = Ping($ip) If @error Then Select Case @error = 1 $msg = "Host is offline" Case @error = 2 $msg = "Host is unreachable" Case @error = 3 $msg = "Bad destination" Case @error = 4 $msg = "Other errors" EndSelect $Results = "Ping Failed. Reason: "&$msg EndIf EndFunc
evilertoaster Posted June 11, 2008 Posted June 11, 2008 (edited) Could I ask for some help please and see what I could possibly do to improve this script?Programs that have a speed problem as a result of blocking functions (like ping) usaully benifit alot from using threads or co-proccessing, I would look into trying a virtual multi-thread UDF to launch several of ping and drivemap add sections in blocks.Also, a strange thing that occurs is sometimes I get a "Undefined / Other error" in the log for Windows 2000 PC's and I don't know why.Try having it log the @extended and look up the windows API code for it. Edited June 11, 2008 by evilertoaster
buymeapc Posted June 13, 2008 Author Posted June 13, 2008 I don't know how I'd have it miltithreaded. Would that be done through the same exe or a separate? I know there has to be a better way to code it other than what I have there. I mean, it takes around 8 hours or so....that's a bit too slow. If I could possibly cut that in half that'd be great...I just don't know how. Maybe there's a different way to connect to the computers to check for the file?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now