Jump to content

Problems using STD I/O


Zizzzzy
 Share

Recommended Posts

Hey Guys, gotta thank all of you for your problems and solutions to offer tons of sample code and "learn from your mistakes" knwoledge without having done somethign myself before.. I come to find out one thing and learn 5 things in the process :whistle:

I am quite new to AutoIt3, have programmed before though never extensively .. I was always the hardware guy. In short, my job is a technicial for a school board where I help support a very large network for the multiple computers in our schools. To keep things manageble and for obvious "kids curiosity" sake our images are frozen to prevent system changes. Since users log in to a central server, to help cut down on slower logins we wish to keep userprofiles off the machines. Generally due to the fact that they are frozen profiles are erased on reboot, however bugs happen and periodically they do not freeze correctly.. profiles are then frozen on these machines, and eventually build up over time. Consequently as well, since our environment and images have been created with the intention that user profiels will always be default and not customised, when such profiles on a machines can cause those users to have bugs, or unwanted settings, for example printer mapings. We have a daily maintenace where the machines thaw to allow updates such as antivirus. I wish to write a script that will remove all but the default profiles. In past we (as far as I know) have removed these by just deleting the profile directory, however there are registry entries as well, and regardless of if that matters or not, i'd rather have all traces removed. Microsoft has its Delprof.exe which will do the job, however they seemed to not program in any ability to use it in my environment. Options include to delete all profiles, specific profiles (not by syntax but by program prompt), or ones inactive for a given time which would not work for me.

The general concept of the script is, since I cant specify by command syntax what I want delprof to do, I will need to read the output and give a responce based on it. As far as I understand, I cant do this in one step due to Autoit limitations with threading. So I have chosen to take the /P (prompt per user) option, send default No (dont delete profile) until delprof exits, take that output to capture the order and accounts found on that machine, I can then step that through cases and create another array of the desired output. A second execution of Delprof with my input array as the STDin will entre the correct answer and remove the profiles I want. The script I am going to post is half of what I have writen thus far, I striped the end off as it is the second execution and array building code which isnt needed yet at the point in the script I am having problems with. I can post the whole thing but I feel this should be all thats needed. I will appologise if I use 3 functions to do what 1 functions I havent discovered yet does, or if I have 3 lines of code that coudl have been one, new to autoit ;) The multiple msgbox are so I can track my output.

My problem: this code works fine on my laptop (toshiba A70).. as well as 4 other techs that have that model.. it does not however work on any other computer I have tried it on (dells). Besides a possible timing issue i am not really sure what could cause this. but I have tried it on several different models of dells and all run it buggy. It will work speradically, however most of the time my STDread doesnt give my output, and I highly suspect its the way I have it setup in my code.. I had a hell of a time getting anything from it, this end result worked.. at least I thought. STD I/O seems like somehting I havent 100% comprehended. Anotehr note is that upon compiling or test runing my script autoit gives me an error on my Run() statement saying "built in called with wrong number of args" and points to the optional I/O flags, which are in both Run() function syntax, sample code, include files.. I dont see why there is an error in my syntax, though it apears to work as it should.

Edit: Anothing thing, peridically after my script has finnished I notice a delprof process still running, using 100% cpu time. Id ont see how this logically makes sence since i shoud lnever get out of my While loop if the process hasnt finished and closed.

Finally, my code:

#include <Constants.au3>
#include <array.au3>

Dim $Accounts
Dim $Counter = 0
Dim $_Input[50]

; Launches Delprof and enters (n)o for all found profiles, output directed to string
$CMD_PID = Run('"' & @WorkingDir & '\delprof.exe" /P', @WorkingDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
While ProcessExists($CMD_PID)
    StdinWrite($CMD_PID, "n" & @CRLF)
    $Accounts = StdoutRead($CMD_PID,-1,1)
WEnd
    StdinWrite($CMD_PID)
    
;----Test Boxes------------------   
    MsgBox(0, "PID", $CMD_PID)
    MsgBox(0, "String", $Accounts)
;----Test Boxes------------------   

; Formating on the output string to capture the users and thier order.  Output to Array
$Accounts = StringStripWS($Accounts, 8)
$Accounts = StringReplace($Accounts, "DeleteC:\DocumentsandSettings\", "")
$Accounts = StringTrimRight($Accounts, 13)
MsgBox(0, "String", $Accounts)
$Users = StringSplit($Accounts, "?(Yes/No/All)", 1)

;----Test Boxes------------------
DO
MsgBox(0, "Array Values", $Users[$Counter])
$Counter = $Counter + 1
Until $Counter = $Users[0] + 1
;----Test Boxes------------------

your experience and insight is appreciated

Edited by Zizzzzy
Link to comment
Share on other sites

In past we (as far as I know) have removed these by just deleting the profile directory, however there are registry entries as well, and regardless of if that matters or not, i'd rather have all traces removed.

Hey mate,

Welcome to the forums :whistle:

I don't think i can help you specifically with what your asking with the STDIN & OUT stuff but unless I am mistaken each user's settings (HKCU reg keys anyway) are stored in the user's profile directory (as the ntuser.dat file). In the past deleting this folder has always been enough for me in regards to clearing a specific users profile (im unsure if Windows keeps other things elsewhere related to user profiles) but an alternative might be to load the C:\Documents and Settings\ folder structure into an array, and from there you could decide what profiles to delete (or not in the case of the default profiles).

To get you started here's a slightly modified example from the helpfile.

#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray("C:\Documents and Settings", "*", 2)
If (Not IsArray($FileList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
_ArrayDisplay($FileList,"$FileList")

From here you would have to do some kind of loop through each element of the array deleting where necessary.

Good luck

Link to comment
Share on other sites

Hey mate,

Welcome to the forums :P

I don't think i can help you specifically with what your asking with the STDIN & OUT stuff but unless I am mistaken each user's settings (HKCU reg keys anyway) are stored in the user's profile directory (as the ntuser.dat file). In the past deleting this folder has always been enough for me in regards to clearing a specific users profile (im unsure if Windows keeps other things elsewhere related to user profiles) but an alternative might be to load the C:\Documents and Settings\ folder structure into an array, and from there you could decide what profiles to delete (or not in the case of the default profiles).

Hey Fu2m8t,

Thanks for taking the time to read my long long post. yes I am aware or how HKCU is stored, and understand that shoudl be enough wihtout complications, however more out of determination i'd like to see this program work :whistle: I do know there are a few entries pertaining to the users of the machines stored in HKLM\soft\microsoft\winNT\currentver\profilelist and I dont believe these removed themselves once i deleted the user dir. This project is as much for me to learn some coding as much as it is to get a task done ;)

I had initially thought of using a method similar to what you suggested, however that wont work as a way of getting input to pass to Delprof as delprof detects and lists the profiles in an unknown order, ie.. doesnt seem to be date created, alphabetical, last accessed, ect.. so I have no way to know which users delprof wil detect and what order, which is why i need to run it once and capture that order. this code works fine on my laptop, regardless of if it is bugged or poorly written, when it does work, the rest of my code (the part that runs delprof again and removes) works as intended. if i can get over or work around why it doesnt work on the Dell systems then the rest is set... i am not an experienced enough programmer to have many more ideas on why it woudlnt work on otehr systems....

Thanks

Link to comment
Share on other sites

Followup,

I seem to have resolved my problem. Error was in when I called STDoutRead as I wasnt fully understanding how it worked. I was calling it in my loop, basically causing the value to be overwritten each time it looped. I guess on some systems final loop was blank, overwriting anything previously captured. Moving mt read statement outside of my loop works as needed.

; Launches Delprof and enters (n)o for all found profiles, output directed to string
$CMD_PID = Run('"' & @WorkingDir & '\delprof.exe" /P', @WorkingDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
While ProcessExists($CMD_PID)
    StdinWrite($CMD_PID, "n" & @CRLF)
WEnd
    StdinWrite($CMD_PID)
    $Accounts = StdoutRead($CMD_PID,-1,1)

Look forward to posting my next problem for you :whistle:

Edited by Zizzzzy
Link to comment
Share on other sites

keep it in your loop and do...

$Accounts &= StdoutRead($CMD_PID,-1,1)

Really? I at one point did have it in my loop with the &= and I found that i got duplicate results, and instead of finding 2 accounts I would get 6, each account 3 times for example. I figured that STDoutRead was buffered, therefor each time I apended it was giving the previous results as well? unsure.. however that way didnt seem to give the result I wished.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...