Jump to content
Sign in to follow this  
JerichoJones

RunAS BROKEN in 3.2.12.1

Recommended Posts

JerichoJones

Ok I think I have nailed down the issue (at least for me in 3.2.12.1). I cannot get the code below to execute properly. If I remove the $STDERR_CHILD it runs properly but I can't get back the result. :-(

#include <Constants.au3>

; Fill in the username and password appropriate for your system.

Local $sUserName = "Username"

Local $sPassword = "password"

; Run a command prompt as the other user.

$rc = RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c XCOPY.EXE /?&pause", @SystemDir, @SW_MAXIMIZE, $STDERR_CHILD)

;):D

Share this post


Link to post
Share on other sites
PsaltyDS

Ok I think I have nailed down the issue (at least for me in 3.2.12.1). I cannot get the code below to execute properly. If I remove the $STDERR_CHILD it runs properly but I can't get back the result. :-(

#include <Constants.au3>

; Fill in the username and password appropriate for your system.

Local $sUserName = "Username"

Local $sPassword = "password"

; Run a command prompt as the other user.

$rc = RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c XCOPY.EXE /?&pause", @SystemDir, @SW_MAXIMIZE, $STDERR_CHILD)

The RunAs() stuff is irrelevant. The behavior looks the same to me with just Run(), and it looks the same with 3.2.13.7 Beta:
#include <Constants.au3>
$rc = Run(@ComSpec & " /k XCOPY.EXE /?&pause", @SystemDir, @SW_MAXIMIZE, $STDERR_CHILD)
Sleep(3000)
ConsoleWrite(@LF & @LF); Blank lines so output is easier to see

The output is strange, because some of the output seems to be redirected to SciTE's console:

>Running:(3.2.13.7):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3" 
Press any key to continue . . . 

C:\WINDOWS\system32>

+>11:19:25 AutoIT3.exe ended.rc:0
+>11:19:27 AutoIt3Wrapper Finished
>Exit code: 0   Time: 5.607

That seems odd... the console doesn't stay open ("/k" switch) either...

Running it without the stream parameter makes it behave as expected:

#include <Constants.au3>
$rc = Run(@ComSpec & " /k XCOPY.EXE /?&pause", @SystemDir, @SW_MAXIMIZE)
Sleep(3000)
ConsoleWrite(@LF & @LF); Blank lines so output is easier to see

The console stays open after it's done, as it should, and nothing stray goes to the SciTE console:

>Running:(3.2.13.7):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3" 


+>11:24:50 AutoIT3.exe ended.rc:0
+>11:24:50 AutoIt3Wrapper Finished
>Exit code: 0   Time: 6.394

Weird.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
JerichoJones

The RunAs() stuff is irrelevant. The behavior looks the same to me with just Run(), and it looks the same with 3.2.13.7 Beta:

#include <Constants.au3>
$rc = Run(@ComSpec & " /k XCOPY.EXE /?&pause", @SystemDir, @SW_MAXIMIZE, $STDERR_CHILD)
Sleep(3000)
ConsoleWrite(@LF & @LF); Blank lines so output is easier to see

The output is strange, because some of the output seems to be redirected to SciTE's console:

>Running:(3.2.13.7):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3" 
Press any key to continue . . . 

C:\WINDOWS\system32>

+>11:19:25 AutoIT3.exe ended.rc:0
+>11:19:27 AutoIt3Wrapper Finished
>Exit code: 0   Time: 5.607

That seems odd... the console doesn't stay open ("/k" switch) either...

Running it without the stream parameter makes it behave as expected:

#include <Constants.au3>
$rc = Run(@ComSpec & " /k XCOPY.EXE /?&pause", @SystemDir, @SW_MAXIMIZE)
Sleep(3000)
ConsoleWrite(@LF & @LF); Blank lines so output is easier to see

The console stays open after it's done, as it should, and nothing stray goes to the SciTE console:

>Running:(3.2.13.7):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3" 


+>11:24:50 AutoIT3.exe ended.rc:0
+>11:24:50 AutoIt3Wrapper Finished
>Exit code: 0   Time: 6.394

Weird.

;)

More fun... Replace the XCOPY.EXE with REG.EXE. and use STDOUT. It works. :-0

@extended always returns 0 in this case

I really wanted this to work. I was hoping to have this done before Monday. :-(

I guess i'll pipe the output to a file...... ew!

Thanks for confirming that I am not completely senile. :-)

Edited by JerichoJones

Share this post


Link to post
Share on other sites
JerichoJones

More fun... Replace the XCOPY.EXE with REG.EXE. and use STDOUT. It works. :-0

@extended always returns 0 in this case

I really wanted this to work. I was hoping to have this done before Monday. :-(

I guess i'll pipe the output to a file...... ew!

Thanks for confirming that I am not completely senile. :-)

No piping either. I guess it is back to an older version....

Share this post


Link to post
Share on other sites
Valik

This is not an AutoIt issue, this is a SciTE issue. Don't run the script in SciTE and it should work correctly.

Share this post


Link to post
Share on other sites
JerichoJones

This is not an AutoIt issue, this is a SciTE issue. Don't run the script in SciTE and it should work correctly.

It does the same thing compiled.

Share this post


Link to post
Share on other sites
Valik

You haven't really said what's not working because as far as I can tell it's working perfectly fine - when I fix the code to prove it's actually working.

#include <Constants.au3>

; Run a command prompt as the other user.
Local $rc = Run(@ComSpec & " /c XCOPY.EXE /? & Pause", @SystemDir, @SW_MAXIMIZE, $STDOUT_CHILD)
ProcessWaitClose($rc)
MsgBox(4096, "", "Read: " & StdoutRead($rc) & @CRLF)

I removed the RunAs() because it's irrelevant. I changed to $STDERR_CHILD to prove that data is being read. So, explain what happens and what you expect to happen. You haven't really said anything useful other than "it doesn't execute properly".

Edit: Removed a line of code I accidentally left in there.

Edited by Valik

Share this post


Link to post
Share on other sites
JerichoJones

You haven't really said what's not working because as far as I can tell it's working perfectly fine - when I fix the code to prove it's actually working.

#include <Constants.au3>

; Run a command prompt as the other user.
Local $rc = Run(@ComSpec & " /c XCOPY.EXE /? & Pause", @SystemDir, @SW_MAXIMIZE, $STDOUT_CHILD)
ProcessWaitClose($rc)
MsgBox(4096, "", "Read: " & StdoutRead($rc) & @CRLF)

I removed the RunAs() because it's irrelevant. I changed to $STDERR_CHILD to prove that data is being read. So, explain what happens and what you expect to happen. You haven't really said anything useful other than "it doesn't execute properly".

Edit: Removed a line of code I accidentally left in there.

If you read my first message you would see the problem indicted in the first sentence. I'll give you a minute to review...... Did you see it?

If I remove the $STDERR_CHILD it runs properly but I can't get back the result. :-(

I am trying to copy a file using RunAs. I want to get the result of the copy operation. Simple.

I don't think you tested your code since it would never return anything as the process will never end. >_<

Now let's start over.

Hi my name is Jericho, nice to meet you.

:)

Share this post


Link to post
Share on other sites
Valik

If you read my first message you would see the problem indicted in the first sentence. I'll give you a minute to review...... Did you see it?

Well, my argument would be, of course it doesn't work because you don't even try to read anything. There are no calls to any StdXXXRead() functions in your code.

If I remove the $STDERR_CHILD it runs properly but I can't get back the result. :-(

Well, I don't really think it's going to return the result on STDERR. Even if it does, I can virtually guarantee it's not going to return anything if you don't actually wait for the process to terminate. It's called a race condition. You try to read before the child process writes anything. My code synchronizes the events by blocking until the script terminates. Of course, I'm just speculating about potential issues. Based on your sample the issue is you don't try to read at all but I'm giving you the benefit of the doubt that you do an immediate StdErrRead() in there. Also, in your example script, nothing is actually ouput on STDERR, which is why I used STDOUT in my example.

I don't think you tested your code since it would never return anything as the process will never end. :)

I don't think you tested my code but are rather making a rather large assumption. The code runs to completion and shows the output from xcopy /? and the Pause command. I copied this from the MsgBox using ctrl+c:

   ---------------------------
     
     ---------------------------
     Read: Copies files and directory trees.
     
     
     
     XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
     
                                [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
     
                                [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
     
                                [/EXCLUDE:file1[+file2][+file3]...]
     
     
     
       source      Specifies the file(s) to copy.
     
       destination  Specifies the location and/or name of new files.
     
       /A          Copies only files with the archive attribute set,
     
                    doesn't change the attribute.
     
       /M          Copies only files with the archive attribute set,
     
                    turns off the archive attribute.
     
       /D:m-d-y  Copies files changed on or after the specified date.
     
                    If no date is given, copies only those files whose
     
                    source time is newer than the destination time.
     
       /EXCLUDE:file1[+file2][+file3]...
     
                    Specifies a list of files containing strings.  Each string
     
                    should be in a separate line in the files.  When any of the
     
                    strings match any part of the absolute path of the file to be
     
                    copied, that file will be excluded from being copied.  For
     
                    example, specifying a string like \obj\ or .obj will exclude
     
                    all files underneath the directory obj or all files with the
     
                    .obj extension respectively.
     
       /P          Prompts you before creating each destination file.
     
       /S          Copies directories and subdirectories except empty ones.
     
       /E          Copies directories and subdirectories, including empty ones.
     
                    Same as /S /E. May be used to modify /T.
     
       /V          Verifies each new file.
     
       /W          Prompts you to press a key before copying.
     
       /C          Continues copying even if errors occur.
     
       /I          If destination does not exist and copying more than one file,
     
                    assumes that destination must be a directory.
     
       /Q          Does not display file names while copying.
     
       /F          Displays full source and destination file names while copying.
     
       /L          Displays files that would be copied.
     
       /G          Allows the copying of encrypted files to destination that does
     
                    not support encryption.
     
       /H          Copies hidden and system files also.
     
       /R          Overwrites read-only files.
     
       /T          Creates directory structure, but does not copy files. Does not
     
                    include empty directories or subdirectories. /T /E includes
     
                    empty directories and subdirectories.
     
       /U          Copies only files that already exist in destination.
     
       /K          Copies attributes. Normal Xcopy will reset read-only attributes.
     
       /N          Copies using the generated short names.
     
       /O          Copies file ownership and ACL information.
     
       /X          Copies file audit settings (implies /O).
     
       /Y          Suppresses prompting to confirm you want to overwrite an
     
                    existing destination file.
     
       /-Y        Causes prompting to confirm you want to overwrite an
     
                    existing destination file.
     
       /Z          Copies networked files in restartable mode.
     
     
     
     The switch /Y may be preset in the COPYCMD environment variable.
     
     This may be overridden with /-Y on the command line.
     
     Press any key to continue . . . 
     
     
     
     
     ---------------------------
     OK   
     ---------------------------

Share this post


Link to post
Share on other sites
JerichoJones

Well, my argument would be, of course it doesn't work because you don't even try to read anything. There are no calls to any StdXXXRead() functions in your code.

Well, I don't really think it's going to return the result on STDERR. Even if it does, I can virtually guarantee it's not going to return anything if you don't actually wait for the process to terminate. It's called a race condition. You try to read before the child process writes anything. My code synchronizes the events by blocking until the script terminates. Of course, I'm just speculating about potential issues. Based on your sample the issue is you don't try to read at all but I'm giving you the benefit of the doubt that you do an immediate StdErrRead() in there. Also, in your example script, nothing is actually ouput on STDERR, which is why I used STDOUT in my example.

I don't think you tested my code but are rather making a rather large assumption. The code runs to completion and shows the output from xcopy /? and the Pause command.

Run it compiled and observe the seemingly magical results. The input stream, since it is not explicitly requested, is configured in such a way that programs that normally block waiting on user input (Like the "Pause" command) won't because they detect that input is never going to arrive.

Hi, my name is Valik and I wrote the features you're trying to use which means chances are I know how to use them.

I got to the simple example you saw because even when I run that I get nothing. The process hangs with a blinking cursor in the console window. If I use another program that does not copy files like REG.EXE (I tried COPY, XXCOPY.EXE) I see the output in the window as expected. Maybe it has to do with my specific machine (XPSP3). I have no idea at this point.

I just want to copy a file as another user and know if the copy was successful or not. The help file seems to indicate this will work:

Providing the Standard I/O parameter with the proper values permits interaction with the child process through the StderrRead, StdinWrite and StdoutRead functions. Combine the flag values (or use $STDERR_CHILD, $STDIN_CHILD & $STDOUT_CHILD, defined in Constants.au3) to manage more than one stream.

XCOPY returns an errorlevel. I want to capture that.

Below is what I am trying to do based on your post and the help file (ProcessWaitClose is not shown in the examples):

#include <Constants.au3>

; Fill in the username and password appropriate for your system.

Local $sUserName = "Username"

Local $sPassword = "Password"

; Run a command prompt as the other user.

Local $rc = RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c XCOPY.EXE C:\Test.fil c:\Test /y", @SystemDir, @SW_HIDE, $STDERR_CHILD)

ProcessWaitClose($rc)

While 1

$line = StderrRead($rc)

If @error Then ExitLoop

MsgBox(0, "STDERR read:", $rc)

Wend

Share this post


Link to post
Share on other sites
Valik

XCOPY returns an errorlevel. I want to capture that.

Then you need to use Run[As]Wait(). The error level is just another term for exit code. If that is all you need then the Run[As]Wait() function is what you want.

Below is what I am trying to do based on your post and the help file (ProcessWaitClose is not shown in the examples):

#include <Constants.au3>

; Fill in the username and password appropriate for your system.

Local $sUserName = "Username"

Local $sPassword = "Password"

; Run a command prompt as the other user.

Local $rc = RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c XCOPY.EXE C:\Test.fil c:\Test /y", @SystemDir, @SW_HIDE, $STDERR_CHILD)

ProcessWaitClose($rc)

While 1

$line = StderrRead($rc)

If @error Then ExitLoop

MsgBox(0, "STDERR read:", $rc)

Wend

As I said before, I really doubt xcopy is actually going to return anything on STDERR unless it's an actual error. Even then I don't know, it's application dependent. Also, why are you running the code through @ComSpec? It's not necessary to do that at all.

At any rate, you seem to only care about the exit code from xcopy and not actually any of the data. If that is the case you just need to use Run[As]Wait() and store it's return value. It doesn't sound to me like you need to be using STDIO streams at all.

Share this post


Link to post
Share on other sites
JerichoJones

Then you need to use Run[As]Wait(). The error level is just another term for exit code. If that is all you need then the Run[As]Wait() function is what you want.

As I said before, I really doubt xcopy is actually going to return anything on STDERR unless it's an actual error. Even then I don't know, it's application dependent. Also, why are you running the code through @ComSpec? It's not necessary to do that at all.

At any rate, you seem to only care about the exit code from xcopy and not actually any of the data. If that is the case you just need to use Run[As]Wait() and store it's return value. It doesn't sound to me like you need to be using STDIO streams at all.

I must be over complicating it. I will look at your suggestion and try it again. Thanks for help and clearing it up for me.

I am not a programmer which is probably obvious by now. I am trying to cobble this stuff together using the help file but it can't provide the training/experience.

I will crawl under a rock now.

Share this post


Link to post
Share on other sites
PsaltyDS

No piping either. I guess it is back to an older version....

As a possible work-around for you, did you really "pipe" or did you "redirect"? You can only pipe to a process, but you can redirect to a file.

This is a pipe because Find is executable that can receive piped data:

xcopy /? | Find /i "/D"

This is a redirect to a file:

xcopy /?  >> C:\Temp\XcopyOptions.txt

The "& pause" you added didn't make sense to me unless you just wanted to see the output. The redirection should do that for you, but if you had mixed them up it wouldn't work, like this would fail: xcopy /? | C:\Temp\BackupLog.txt

What was the command line you tried for that?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.