#143836 - 2005-07-19 06:03 PM
Help with lots of loops -- how to loop with ReadLine()
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Here's my script right now:
Code:
Break ON $ = SetOption("WrapAtEOL","ON") $ = SetOption("ASCII","On")
$server = "\\SERVER\Logging\" $folder = "Local_Admin_Password_Log\" $file = "PasswordLog.log" $comp = @WKSTA $rc = WshPipe("%COMSPEC% /e:1024 /c net user wsadmin /random /passwordchg:yes") $y = 0
while @ERROR = 0 ;1 for each $line in $rc ;2 if instr($line, "Password for") ;3 while $y = 0 ;4 if Open(5,$server+$folder+$file,5) = 0 $line2 = ReadLine(5) do ;5 ? "$line2" if instr($line2,"$comp") ? "evals true" endif ; $line = substr($line,26,len($line)) ; $temp = WriteLine(5,"$comp,$line,"+@TIME+","+@DATE+@CRLF) ; $ = Close(5) ; $y = 1 until @ERROR = -1 else $y = 0 Sleep 1 endif loop endif next loop
1: My attempt to loop through the password reset command if it doesn't meet our network's password complexity constraints. 2: Get the information from the command line password change 3: Check to see if the password change was successful 4: My attempt at looping through opening a file to make sure that it's not locked 5: My attempt to loop through reading the password log file to see if the computer running the script already has an entry and if it does, replace it. -- This is where I'm having my problems. Right now, $line2 never holds a value and my conditional in the last loop that uses instr() never evals to true. Please feel free to critique/destroy the rest of my script it it needs to be. Thanx in advance guys!
|
|
Top
|
|
|
|
#143841 - 2005-07-19 07:42 PM
Re: Help with lots of loops -- how to loop with ReadLine()
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Yeah well, our parent org. in all of it's infinite wisdom says that each LAdmin password must be unique so to make this easy, dynamic, and constantly secure, we're going to run the script in GPO startup to change every the computer reboots, it resets it's LAdmin pw. I'm having a slight problem though with my new implementation; sometimes the password generated by "net user" doesn't meet our password complexity requirements. To try and account for this, I'd like to be able to re-run the loop that sets the password but am having problems doing so. Anyone have any ideas?
Code:
$server = "\\GJLK2W3DS101\Logging\" $folder = "Local_Admin_Password_Log\" $comp = @WKSTA $rc = WshPipe("%COMSPEC% /e:1024 /c net user wsadmin /random /passwordchg:yes") $y = 0
:RepeatLoop for each $line in $rc if instr($line, "Password for") while $y = 0 if exist($server+$folder+$comp+".log") = 1 del $server+$folder+$comp+".log" endif if Open(5,$server+$folder+$comp+".log",5) = 0 $line = substr($line,26,len($line)) $temp = WriteLine(5,"$comp,$line,"+@TIME+","+@DATE+@CRLF) $ = Close(5) $y = 1 else $y = 0 Sleep 1 endif loop endif if instr($line, "The password does not meet the password policy requirements") GoTo RepeatLoop endif next
|
|
Top
|
|
|
|
#143843 - 2005-07-19 09:43 PM
Re: Help with lots of loops -- how to loop with ReadLine()
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
My approach: http://home.comcast.net/~habullock/SetAdminPW.html
This is somewhat dated and some program improvements have been made to insure complex passwords and such.
Edited by Howard Bullock (2005-07-19 09:45 PM)
|
|
Top
|
|
|
|
#143844 - 2005-07-19 09:50 PM
Re: Help with lots of loops -- how to loop with ReadLine()
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Quote:
nm... I just moved :RepeatLoop above $server and it works fine.
ACK! a goto! quick, run and hide befor the goto police find YOU!!
Code:
While not $RepeatLoop $server = "\\GJLK2W3DS101\Logging\" $folder = "Local_Admin_Password_Log\" $comp = @WKSTA $rc = WshPipe("%COMSPEC% /e:1024 /c net user wsadmin /random /passwordchg:yes") $y = 0 for each $line in $rc If InSTR($line, "Password for") While $y = 0 If Exist($server+$folder+$comp+".log") = 1 DEL $server+$folder+$comp+".log" EndIf If Open(5,$server+$folder+$comp+".log",5) = 0 $line = SubSTR($line,26,Len($line)) $temp = WriteLine(5,"$comp,$line,"+@TIME+","+@DATE+@CRLF) $ = Close(5) $y = 1 Else $y = 0 Sleep 1 EndIf Loop EndIf If InSTR($line, "The password does not meet the password policy requirements") $RepeatLoop = 0 Else $repeatloop = 1 EndIf next Loop
|
|
Top
|
|
|
|
#143845 - 2005-07-19 10:09 PM
Re: Help with lots of loops -- how to loop with ReadLine()
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Thanx Bryce. I used similar methods before and don't know what that didn't dawn on me before. I recognize that the mods here despise GoTo but I couldn't think of another way to do it for some reason...
I'm having a new problem with implementation of the script though. I applied my batch file as a startup script for my office's OU for testing. The batch file just has a simple CALL command in it that uses UNC path names to call kix32.exe and then my file.kix. I had a couple of the guys in the office reboot but their passwords didn't show up in my network logging directory. On that directory, our office has full control and authenticated users have write access with special permissions: Create Files/Write Data, Create Folders/Append Data, Write Attributes, Write Extended Attributes. All network locations in the scripts use UNC pathnames. Can anyone see a problem with my implementation?? I also had them run gpudate prior to rebooting...
**The file does work when i drag the file over kix32 while logged on... and i did read:
http://www.kixtart.org/ubbthreads/showfl...amp;Forum=UBB14
Edited by thepip3r (2005-07-19 10:11 PM)
|
|
Top
|
|
|
|
#143850 - 2005-07-19 11:52 PM
Re: Help with lots of loops -- how to loop with ReadLine()
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
UPDATE: I've verified that the script isn't working through GPO. I checked to see what the local admin password was by running the script manually, logging off, and logging in with local admin. then restarted the computer to see if it'd at least reset the pw if not make the entry in the logging folder; it didn't do either...
Here's my batch file:
Code:
call \\dc1\NetLogon\kix\KIX32.EXE \\dc1\NetLogon\kix\pwReset.kix
Again, this works fine when running manually with my credentials.
** Also generated RSoP data to ensure that the start-up script was being applied by my computer...
Edited by thepip3r (2005-07-19 11:55 PM)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|