
daishi5
Members-
Posts
14 -
Joined
-
Last visited
daishi5's Achievements

Seeker (1/7)
0
Reputation
-
I am new to AutoIT, but I am almost certain that you cannot do what you want to do without encryption or writing your own file system. When you insert the flash drive, the computer, not your flash drive, determines whether or not your script will run. If you want to prevent access to your flash drive if it is stolen or any other form of unauthorized access, you need encryption.
-
I found a fix, although I am not sure if I should have needed to do this. I placed the StringRegExp in a loop, and broke the output from the AT command into separate lines so that I could check them one at a time. I thought I could run the StringRegExp on the whole set of text, and output each of the matches, but this seemed to work. I am guessing the way I ran it, I was only getting the first match. For my own education, is there a way to return all of the matches, or is looping the best way? Thank you for all the help. I am sure Mison's code could work, but the answer was so close there was no point in switching methods. The finalized "test" code. $cmdresult = Run('at \\lteis007', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Processwaitclose($cmdresult) $line = string(StdoutRead($cmdresult)) ;check the output from the AT command msgbox(1,"test",$line) ;split the AT command results into individual lines to be parsed $test=stringsplit($line,@lf) ;check for errors in the string split, if everything seems to have worked, begin parsing the output if isarray($test) and @error=0 Then for $count=0 to ubound($test)-1 msgbox(1,"string value",$test[$count]) ;check each line for the targeted script $task=stringregexp($test[$count],'([0-9]{1,2})(?i)(?:\s+Each [A-Z]{1,2}\s+[0-9]{1,2}:[0-9]{1,2} [A-Z]{2}\s+c:\\reboot.exe)',1) if isarray($task) and @error=0 Then for $innercount=0 to ubound($task)-1 msgbox(1,"regexp output",$task[$innercount]) Next EndIf Next EndIf
-
Ok, that seems to have helped, it at least helped me figure out what was happening and what was not happening. Not an error, it just matches the first line, but not the second line. I took what you gave me and changed it to make the second part non-capturing, because I am just interested in that first number. However that helps because now I know my error checking was actually working, and the 1 is an actual match. When I tried your suggestion exactly as it was, I got a match on "1" and "Each W 5:30 AM c:\reboot.exe" but I did not get any matches on the second part, which I think should also match. So far my code looks like this: #include <Constants.au3> #include <Array.au3> AutoItSetOption("MustDeclareVars", 1) dim $cmdresult dim $line dim $count dim $test dim $task dim $arraylimit ;retrieve the scheduled tasks from the target machine $cmdresult = Run('at \\lteis007', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Processwaitclose($cmdresult) $line = string(StdoutRead($cmdresult)) ;check the output from the AT command msgbox(1,"test",$line) $task=stringregexp($line,'([0-9]{1,2})(?i)(?:\s+Each [A-Z]{1,2}\s+[0-9]{1,2}:[0-9]{1,2} [A-Z]{2}\s+c:\\reboot.exe)',1) if isarray($task) then Else msgbox(1,"error","No matches found") ;Exit EndIf if @error>0 Then msgbox(1,"array error","no matches, array is invalid") EndIf $arraylimit=ubound($task) msgbox(1,"array limit",$arraylimit) $count=0 while $count<$arraylimit msgbox(1,"regular expression output",$task[$count]) $count=$count+1 WEnd Exit I was running the Ifarray() and @error because I was not sure I was doing either right, so there is a lot of extra crap in there. As I look at your example and my code, and I see how your code outputs the matches from the regular expression, I think I have a few ideas of what I might be able to do to fix it. I am headed home for the day, but I think I will continue to play with this at home, it feels like I am making some simple mistake in my implementation, and that I am a simple fix away at this point.
-
Ok, from the help section "(?i: ... ) Case-insensitive non-capturing group." I thought that meant that I could put the ?i: at the front of the group, and it would not match case and would not capture that group. Also, how do I test @error and isarray()? I found a few instances of @error in example code, but the help file does not say anything other than I should check seterror. I tried what I had seen which was if @error then but it went straight to the else portion of the code. However, I also tried If Isarray($task) Then which returns true, and executes the "Then" statement. I assume this means this is an array, but I don't know if I am testing @error properly, and I can't find how I should test it in the help files. Is there some reference I could read on basic validation such as testing @error and Isarray()? Oh, and thanks for the ubound suggestion, I have used that before and completely forgot.
-
Didn't take me long. Matching string looks like this: Status ID Day Time Command Line ------------------------------------------------------------------------------- 1 Each W 5:30 AM c:\reboot.exe 2 Each W 5:30 AM c:\reboot.exe The expression is $task=stringregexp($line, '([0-9]{1,2})(?i: Each [A-Z]{1,2} [0-9]:[0-9]{1,2} [A-Z]{1,2} c:\\reboot.exe)', 1) After this, I do a series of message boxes, $task[0] returns 1 like I expect, but $task[1] gives me an "Array variable has incorrect number of subscripts or subscript dimension range exceeded" error. I tried the regular expression tester that I found in the help file, the test string works in there, but I assume I broke something in my array. Now for my new questions: Not sure what I am doing wrong, when I did this using stringsplit I did not have to declare the size of the array, should I be doing that here? Is there a way to output the number of matches stored in the array, or do I have to go through the array till I stop finding information stored in them when I use the output? Is there an easier way to ignore all the text between the first number and "c:\reboot.exe" I managed to make it work, but I bet I am missing a much easier method. Edit: Ok, I think I may have found why I am getting only the 1 back. Reading the help file, it seems that I am probably getting the "1" as an error rather than an actual match. This is a problem, because I actually expect to receive "1" back fairly often, so I need to figure out how to tell the difference between a "1" as an error and a "1" as a valid result. So, I will do some more help file digging.
-
That will help, I had really hit a wall because I have never worked with strings and did not even know how to start looking at this. I will read the help file and see if I can get what I need.
-
I have a scheduled task that was deployed using AT, and I have a script that I want to use to check that the scheduled task is installed on the correct domain machines. My only problem is, I have no experience working with strings. The output from AT is always formatted the same, so I just need to match a text string of c:\reboot.exe and if that is present in the string, I want to capture the number at the start of the line. Status ID Day Time Command Line ------------------------------------------------------------------------------- 1 Each W 5:30 AM c:\reboot.exe 2 Each W 5:30 AM c:\reboot.exe So, for this, I would want to output 1 and 2 to variables or an array (I assume I want an array) so that I can then feed them back into more commands. This is what I have so far for grabbing the AT output. It is very basic, and I split it into several strings of 1 line each, because I think it reduces my chance of grabbing the wrong ID number. #include <Constants.au3> AutoItSetOption("MustDeclareVars", 1) dim $foo dim $line dim $count dim $test ;retrieve the scheduled tasks from the target machine $foo = Run('at \\lteis007', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Processwaitclose($foo) $line = string(StdoutRead($foo)) ;check the output from the AT command msgbox(1,"test",$line) ;split the output into seperate lines, and then double check the number of lines after the split $test = stringsplit($line,@LF) msgbox(1,"testcount",$test[0]) ;display each line one by one, just one more check $count=0 while $count<$test[0] $count=$count+1 msgbox(1,"test lines",$test[$count]) WEnd Exit If it is necessary, I can also post the full script code, if there is a better way to go about scanning a batch of computers in the domain.
-
I have an autoit script compiled and set to run as a scheduled task using the credentials of a domain account we use for scheduled tasks. When the logged in user runs the task they get the msgbox, when the scheduled task runs the msgbox never appears for the user to interact with. However, the msgbox does seem to be timing out properly. I don't know if it is a problem with my scheduled task, or with my autoit script, so here is the code if that helps: #include <Array.au3> #Include <date.au3> ;declare variables $rebootanswer=0 $systemuptime=0 $uptimetest=iniread("\scripts\rebootscript\Reboot.ini", "options", "rebootdays","7") $rebootmessage=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "message","Error")) $timeout=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "timeout","Error")) dim $ADlocation Dim $list[1] $ADlocation=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "ADlocation","Error")) $systemuptime=_uptime() ;check for system uptime and exit if less then the number of days specified in the ini file. if($systemuptime < $uptimetest) then ;msgbox(0,"test","system does not need a reboot" & $uptimetest) Exit EndIf If Processexists("Explorer.exe")==0 Then Shutdown(6) Else ;display a dialogue box, return the value of their response to the variable, 17 declares that the user can say ok, or cancel, second section is the box title ;third variable is the message that is displayed, 4th variable is the number of seconds before the msgbox times out, if it times out it acts as if they said ok $rebootanswer = msgbox ( 17, "Reboot Warning", $rebootmessage, $timeout) ;if the user says yes, or does not answer within a minute, reboot the machine. Otherwise, end script if ($rebootanswer = 1 or $rebootanswer = -1) Then shutdown (6) Else Exit EndIf func _uptime(); convert system uptime into days. $time=_gettime();set variable time to equal the uptime of the system in milliseconds, ;then divide by 86,400,000 which makes the value equal to the number of days since a reboot $time=($time/86400000) Return $time EndFunc Func _GetTime();retrieve system uptime $Dll = DllCall("WinMM.dll", "long", "timeGetTime") Return $Dll[0] EndFunc EDIT: just talked with someone else in the office, he said his work around was to use AT to schedule the task, but he had a lot of problems getting the response from the message box back into his script (he was using VB I do not know if that applies to this). Would it be best to use AT with the /interactive flag, or is there a better way using schtask? I cannot find anything on how to make scheduled tasks made with schtask interactive in the microsoft technet information.
-
Sorry, active directory.
-
I have a script that I was helped with that retrieved a list of machines from a location in AD, and then did some other stuff that is not important. Now, I want to have a second script that when it runs, it double checks to make sure that the machine is still in that part of the AD, and if it is not the script exits. I have no experience working with AD, so I was going to take the script that I had, get a list of all the machines and then see if the machine's name is in that list. However, I am pretty sure I am trying to use a hammer on screws. Surely there must be a better way to do this? This is what I was going to use, but again I am pretty certain this is not the best way to go about this. #include <Array.au3> #Include <date.au3> ;declare variables Opt("MustDeclareVars", 1) dim $ADlocation Dim $list[1] Dim $fail ;retrieve the AD ou container from the network INI file $ADlocation=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "ADlocation","Error")) $fail=string(iniread("\scripts\rebootscript\Reboot.ini", "options", "failurefile", "Error")) _getADComputer() _checkOnline($list) ;_ArrayDisplay($list) Func _getADComputer() Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") ;open the connection to AD $objConnection.Provider = "ADsDSOObject" $objConnection.Open("Active Directory Provider") $objCommand.ActiveConnection = $objConnection ;combine the inifile setting into an LDAP query, and then query Active directory for the computer list Local $strBase = "<LDAP://" & $ADlocation & ">";combine the location Local $strFilter = "(objectCategory=computer)";filter for only computers Local $strAttributes = "cn" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree";combine all the previous parts into a full LDAP query ;create the command to be run, and set properties to prevent it from running amok $objCommand.CommandText = $strQuery $objCommand.Properties("Page Size") = 100 $objCommand.Properties("Timeout") = 30 $objCommand.Properties("Cache Results") = False Local $ADS_SCOPE_SUBTREE = 5 $objCommand.Properties("searchscope") = $ADS_SCOPE_SUBTREE ;run the command Local $objRecordSet = $objCommand.Execute ;populate the results into the list array While Not $objRecordSet.EOF If $list[UBound($list) - 1] <> '' Then ReDim $list[UBound($list) + 1] EndIf $list[UBound($list) - 1] = $objRecordSet.Fields("cn" ).Value $objRecordSet.MoveNext WEnd ;close the connection $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" EndFunc
-
Reboot a group of remote machines on a schedule
daishi5 replied to daishi5's topic in AutoIt General Help and Support
Ok, I am pretty sure I get what everything is doing, but where do I get _ArrayDisplay($list) from? I hope this isn't a stupid question that I overlooked the obvious on. Edit: nevermind, my copy paste skills failed me, I see that I did not get the include in there. -
Reboot a group of remote machines on a schedule
daishi5 replied to daishi5's topic in AutoIt General Help and Support
Yep, a lot of that goes over my head, I am gonna dig through those examples to make sure I know what it is doing, and I am sure I will have some questions for you in a bit. Thank you for the help. -
Reboot a group of remote machines on a schedule
daishi5 replied to daishi5's topic in AutoIt General Help and Support
Those are some good points, I just got this project handed to me because one of the other admins was not able to get what he wanted with VB script. I went over the meeting minutes, and it looks like we want to reboot the computers because of performance problems, a lot of computers throughout the hospital are not being rebooted until the users have problems. Making the reboot happen only if the computer has not been rebooted for a while would be good. I wanted to use the AD info because it would prevent me from needing to maintain a seperate list of computers, which I think is very important because lists like that always fail to get maintained. Also, our AD structure is already setup according to the types of computers, so things that should never go down are already in special OUs where I could make sure the script ignores them. I also just had a thought going over what I have read here, could I make a local script, run it as a service, and if the system has been up more than a week, reboot the computer if no one has been logged on for 5 minutes? The only thing that seems hard about that is determining if no one has been logged on for 5 minutes, but I don't want the computer to reboot if one user logs off and another one wants to log on. -
I am an administrator with several hundred machines that we want to start rebooting on a weekly basis. I have created a reboot script that works well on the local machine, but I forgot that I cannot schedule services with group policy. Now, I am looking at a way to remotely reboot computers based on their location in the AD, and that has a dialogue box to let the user abort the reboot. I have a local script, I could run a script that runs through AD, copies the script down to all the machines and then uses psexect to start the autoit script. I am not sure if that would be the best way, are there some best practices for something like this, am I overthinking this, forgetting something important, or just going down the wrong road entirely?