Sign in to follow this  
Followers 0
sublimnl

Help With Stdoutread Inside Function

8 posts in this topic

I'm writing a script that our users can run after logging onto their VPN client from a remote site. This script will detect their logon script (it's different for many users), copy it to their machine from the netlogon share on one of our Domain Controllers, and then run the logon script for them and then give a report of the mapped drives.

The problem I am having is that StdoutRead is only returning the first line of the output from "net user /domain username" when the code is run from within a function. If I take this same exact code and run it as an independent script it returns all of the output! Code is below...thanks for the help!

Func Mapper()
        
    If DriveMapAdd("","\\activehouii\netlogon",0,"INTECENG\" & $INP_User,$INP_Pass) > 1 Then
        MsgBox(4096,"Error","Error connecting to remote server.  Bad Username or Password?")
        PassGui()
    EndIf
    
    $message = "Finding your logon script..."
    SplashTextOn("LogonStatus", @CR & $message, 400, 50,-1,-1,1,"Arial",10)
    
    $console = Run(@SystemDir & "\net user /domain " & $INP_User, @SystemDir, @SW_HIDE, 2)
    While ProcessExists($console)
        Sleep(500)
    WEnd

    $output = StdoutRead($console, -1)
    MsgBox(4096,"",$output)

;Parse the output for the logon script
    $position = StringInStr($output,"Logon Script")
    $logonscript = StringTrimLeft($output,$position+12)
    $position = StringInStr($logonscript,@CR)
    $logonscript = StringMid($logonscript,1,$position)
    $logonscript = StringStripWS($logonscript,1)
    $logonscript = StringStripCR($logonscript)

;Update the status message and copy the logonscript
    $message = "Copying logon script '" & $logonscript & "'"
    ControlSetText("LogonStatus","","Static1", @CR & $message)
    FileCopy("\\activehouii\netlogon\" & $logonscript, @UserProfileDir & "\" & $logonscript,1)

;Update the status message and RUN the logonscript
    $message = "Running logon script '" & $logonscript & "'"
    ControlSetText("LogonStatus","","Static1", @CR & $message)
    MsgBox(4096,"",@UserProfileDir & "\" & $logonscript)
    RunWait(@UserProfileDir & "\" & $logonscript,@SystemDir, @SW_HIDE)

;Display report of mapped drives
    $mapped = DriveGetDrive("network")
    $mapdisplay = ""

    For $i=1 to UBound($mapped,1)-1
        If DriveMapGet($mapped[$i]) = "" Then ContinueLoop
        $mapdisplay = $mapdisplay & "Mapped " & StringUpper($mapped[$i]) & " to " & DriveMapGet($mapped[$i]) & @CRLF
    Next

    SplashOff()
    MsgBox(4096,"Done", "The following drives have been mapped: " & @CRLF & @CRLF & $mapdisplay)
    
EndFunc

Share this post


Link to post
Share on other sites



need beta, try:

$console = Run(@SystemDir & "\net user /domain " & $INP_User, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
         $line = StdoutRead($console)
         If @error = -1 Then ExitLoop
         $output = $output & $line @CRLF
    Wend

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Not sure if you are saying that I need the beta or that you don't have it installed to test, but FYI I'm running the latest beta.

Tried that though and got the same result. :)

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Not sure if you are saying that I need the beta or that you don't have it installed to test, but FYI I'm running the latest beta.

Tried that though and got the same result. :)

I don't know by this if you've tried precisely the above code from gfrost's post or if you had just added the loop around StdoutRead. The ProcessExists/Sleep from the original function won't be necessary if you call StdoutRead repeatedly in a loop like that since StdoutRead will wait to return until there's output to be read, and the While loop will continue until End-Of-File(or data stream in this case) is read and StdoutRead sets @error to -1.

My concern is that you're waiting for the process to exit, THEN reading its output. While if seen this work OK in practice, I'd be concerned that all bets are off as far as Windows is concerned re: preserving a process's data once the main thread has exited.

[Edit: I had started composing this prior to the bump.]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

Yep, I tried the exact code from gafrost and get the same behavior. Just get the first line when called as a function. If I save this function with gafrost's code to its own script and run it I get the entire output.

Share this post


Link to post
Share on other sites

Yep, I tried the exact code from gafrost and get the same behavior. Just get the first line when called as a function. If I save this function with gafrost's code to its own script and run it I get the entire output.

without your whole script we could guess till we turn blue.

So I'm going to guess that another part of your script is causing the problem.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

If you are new to AutoIT and would like to get the basics down quicker, check out this awesome new coaching tool...

And if you find it useful ...vote :)

http://www.autoitscript.com/forum/index.php?showtopic=24117


~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Share this post


Link to post
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
Sign in to follow this  
Followers 0