Page 1 of 1 1
Topic Options
#143836 - 2005-07-19 06:03 PM Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
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
#143837 - 2005-07-19 06:20 PM Re: Help with lots of loops -- how to loop with ReadLine()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Instead of using an unformatted text file, you should use an INI formatted file. Then you would not have to loop through it, nor would you have duplicates.

I believe I posted my LUser Administrator password changer that uses this method.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#143838 - 2005-07-19 06:21 PM Re: Help with lots of loops -- how to loop with ReadLine()
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
You cannot open a file for both reading and writing. In your code, you open the file for writing, therefore you cannot read it. And that's why $line2 does not contain any data...
Top
#143839 - 2005-07-19 06:36 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
I was going to run this in GPO startup but realized that looping through a single file on computer startup out on a network drive would send all computers' local admin passwords across the network every day.
Top
#143840 - 2005-07-19 07:00 PM Re: Help with lots of loops -- how to loop with ReadLine()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I use an admin script that changes the LUser admin password once a month.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#143841 - 2005-07-19 07:42 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
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
#143842 - 2005-07-19 08:10 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
nm... I just moved :RepeatLoop above $server and it works fine.
Top
#143843 - 2005-07-19 09:43 PM Re: Help with lots of loops -- how to loop with ReadLine()
Howard Bullock Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#143844 - 2005-07-19 09:50 PM Re: Help with lots of loops -- how to loop with ReadLine()
Bryce Offline
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 Offline
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
#143846 - 2005-07-19 10:45 PM Re: Help with lots of loops -- how to loop with ReadLine()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Startup GPO scripts run with localsystem rights.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#143847 - 2005-07-19 10:53 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Yeah... I just realized that so I changed the "Authenticated Users" part of my explanation to "Everyone" and it still didn't work. Any thoughts?

** Also moved the batch file to the StartUp Folder under SysVol of our DCs instead of using a UNC pathname to our netlogon folder if that helps...


Edited by thepip3r (2005-07-19 10:55 PM)

Top
#143848 - 2005-07-19 10:59 PM Re: Help with lots of loops -- how to loop with ReadLine()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
This has been discussed before. The NetLogon share has been said to be available. Perms elsewhere are tricky and YMMV.

There is a fundamental flaw in your plan wherby everyone can open your logfile and read the passwords! My central admin script keeps the passwords secure.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#143849 - 2005-07-19 11:01 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
What is "Perms elsewhere are tricky and YMMV"??? and I've only given Everyone the ability to write to the folder, they can't read the contents.
Top
#143850 - 2005-07-19 11:52 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
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
#143851 - 2005-07-20 05:19 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
what am I missing? I've got the batch file in my startup scripts. I've run RSoP to ensure my computer sees the script being applied to it. I've gone to that DC and ran the batch file to ensure that it kicks off my script correctly and sets the password, yet when I restart my computer it doesn't log anything OR even reset the pw in the first place.
Top
#143852 - 2005-07-20 07:17 PM Re: Help with lots of loops -- how to loop with ReadLine()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Throw some code in to log to a local file or eventlog so you can see what is happening where.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#143853 - 2005-07-20 08:28 PM Re: Help with lots of loops -- how to loop with ReadLine()
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Yeah I did that. I made my batch file append a text file to my C drive if it ran and then had my kix script do the same. I ended up using that method to figure out that my batch file was running but the kix file wasn't so i moved kix32.exe and my kix file to the sysvol/shutdown directory and everything worked fine. I also changed my paths in my batch file to relative instead of full unc paths... thank you for the help all...
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.072 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org