Redirect text to a file (runas command result)
Moderator: DosItHelp
Redirect text to a file (runas command result)
Thank you for reading first.
------------------------------------------------------------------
I need runas result text.
But this redirect command does not work.
"echo .|runas /user:administrator echo %date% > test.txt"
------------------------------------------------------------------
This is the text data what I need.
Attempting to start echo 2020-01-14 as user "WIN2012\administrator" ...
RUNAS ERROR: Unable to run - echo 2020-01-14
1326: The user name or password is incorrect.
------------------------------------------------------------------
How can I redirect these text data to .txt file.
Thanks a lot
------------------------------------------------------------------
I need runas result text.
But this redirect command does not work.
"echo .|runas /user:administrator echo %date% > test.txt"
------------------------------------------------------------------
This is the text data what I need.
Attempting to start echo 2020-01-14 as user "WIN2012\administrator" ...
RUNAS ERROR: Unable to run - echo 2020-01-14
1326: The user name or password is incorrect.
------------------------------------------------------------------
How can I redirect these text data to .txt file.
Thanks a lot
Re: Redirect text to a file (runas command result)
I actually can't test if redirecting is possible with runas at all, but if it were then i assume you need both streams (stdio and stderr); untested:
penpen
Code: Select all
echo.|((runas /user:administrator echo %date%" 2>&1) >"test.txt")
Re: Redirect text to a file (runas command result)
Appreciate the quick response.
But it doesn't work.
echo .|((runas /user:nopasstest "echo %date%" 2>&1) > test.txt)
But it doesn't work.
echo .|((runas /user:nopasstest "echo %date%" 2>&1) > test.txt)
Re: Redirect text to a file (runas command result)
echo .|((runas /user:nopasstest "echo %date%" 2>&1) > "test.txt")
((echo .|runas /user:nopasstest "echo %date%" 2>&1) > "test.txt")
(echo .|(runas /user:nopasstest "echo %date%" 2>&1) > "test.txt")
echo .((|runas /user:nopasstest "echo %date%") > "test.txt" 2>&1)
((echo .|runas /user:nopasstest "echo %date%") > "test.txt" 2>&1)
(echo .|(runas /user:nopasstest "echo %date%") > "test.txt" 2>&1)
None of them work.
But thank you
((echo .|runas /user:nopasstest "echo %date%" 2>&1) > "test.txt")
(echo .|(runas /user:nopasstest "echo %date%" 2>&1) > "test.txt")
echo .((|runas /user:nopasstest "echo %date%") > "test.txt" 2>&1)
((echo .|runas /user:nopasstest "echo %date%") > "test.txt" 2>&1)
(echo .|(runas /user:nopasstest "echo %date%") > "test.txt" 2>&1)
None of them work.
But thank you
Re: Redirect text to a file (runas command result)
Some remarks:
- runas.exe does not support entering a password through a pipe ("|").
If you want to pass a password, look at utilities like sanur (runas spelled backwards; basically a wrapper around runas.exe that feeds the password) or CPAU (joeware.net).
(IIRC; must be at least 10 years since I used them the last time ..) - The command you give (echo %date%) is passed on to Explorer (the shell). That doesn't know how to handle the echo command.
Use cmd.exe /c echo %date% instead. Or somescript.cmd; Explorer can run that too if you got the right file associations in place. - If you run some program as a different user, you have no guarantees what the working directory of that program will be. And thus no idea where your text.txt will be written. Use a full path instaed: c:\test\test.txt.
Re: Redirect text to a file (runas command result)
Hi! Eureka!
1. I know '|' do not support entering password 'runas.exe' command
2. I only need 'runas.exe' error message ( 1326: The user name or password is incorrect. )
and does not work 'cmd /c' command
1. I know '|' do not support entering password 'runas.exe' command
2. I only need 'runas.exe' error message ( 1326: The user name or password is incorrect. )
and does not work 'cmd /c' command
Re: Redirect text to a file (runas command result)
Hi avizee,
I tested
It works, the complete text is in test.txt.
The only difference to your first example, is the enclosing of echo %date% into quotes
I tested
Code: Select all
echo( | runas /user:asdf "echo %date%" > test.txt
The only difference to your first example, is the enclosing of echo %date% into quotes
Re: Redirect text to a file (runas command result)
Thanks for the help
But this doesn't work either
But this doesn't work either
Re: Redirect text to a file (runas command result)
How it fails, what is the error message or the unexpected behavior?
Do you can write files in the current directory at all?
Did you test it on the command line or somewhere inside a batch file?
Which Wndows version do you use?
Do you can write files in the current directory at all?
Did you test it on the command line or somewhere inside a batch file?
Which Wndows version do you use?
Re: Redirect text to a file (runas command result)
I tested Windows 10, Windows Server 2012 R2, Windows Server 2016.
There are no error message.
Test results are this.
-------------------------------------------
Enter the password for nopasscheck:
Enter the password for asdf:
There are no error message.
Test results are this.
-------------------------------------------
Enter the password for nopasscheck:
Enter the password for asdf:
Re: Redirect text to a file (runas command result)
Please provide better feedback than "does not work" !!
When you provide no password or the wrong one, the program will not be started, of course.
When you enter (manually!) the password when entering this command:
Code: Select all
runas /user:administrator "cmd /c pause"
When that command was echo %date%, that separate CMD window would close right after executing that command.
So what exactly is not working? What is the output? What else happens on your screen? Did you get an error beep? Did your power supply explode?
It turns out I didn't fully get what you want to accomplish. You are solely interested in the error message:
Well, runas.exe doesn't write it's output to the standard stream or error stream, so it can't be redirected that way.avizee wrote: This is the text data what I need.
Attempting to start echo 2020-01-14 as user "WIN2012\administrator" ...
RUNAS ERROR: Unable to run - echo 2020-01-14
1326: The user name or password is incorrect.
There are probably (complicated!) ways around that, but there is an alternative:
PSEXEC (Sysinternals) uses the same errormessages and error codes. And this output can be redirected:
Code: Select all
+ T:\>psexec64 -nobanner -u administrator -p wrong cmd.exe
PsExec could not start cmd.exe:
The user name or password is incorrect.
+ T:\>echo %errorlevel%
1326
+ T:\>
Last edited by Eureka! on 16 Jan 2020 07:32, edited 1 time in total.
Re: Redirect text to a file (runas command result)
This can't be correct, I tested it with Win10 10.0.17134.1184 and I can redirect it without problems.
And also with Win7 6.1.7601 the redirection works.
In both cases the content of test.txt is
Code: Select all
C:\> echo( | runas /user:asdf "echo %date%" > test.txt
c:\> type test.txt
Enter the password for asdf:
Re: Redirect text to a file (runas command result)
This is what I making
I'm looking for a way by using psexec with vbs.
But I think the best way is use runas command.
---------------------------------------------------------------
Edited!
Code: Select all
net user | findstr /v /i "change profile Memberships User's \\ successfully -------------------------------------------------------------------------------" > [#####]_useracc_temp1.txt 2> nul
type [#####]_useracc_temp1.txt | findstr . > [#####]_useracc_temp2.txt 2> nul
for /f "tokens=1,2,3" %%a in ([#####]_useracc_temp2.txt) do (
net user %%a | findstr /v /i "ECHO.is" | findstr /i "Account.active.*Yes Account.active.*Locked" && echo %%a>> [#####]_active_acc_temp1.txt 2> nul
net user %%b | findstr /v /i "ECHO.is" | findstr /i "Account.active.*Yes Account.active.*Locked" && echo %%b>> [#####]_active_acc_temp1.txt 2> nul
net user %%c | findstr /v /i "ECHO.is" | findstr /i "Account.active.*Yes Account.active.*Locked" && echo %%c>> [#####]_active_acc_temp1.txt 2> nul
) > nul 2> nul
type [#####]_active_acc_temp1.txt | findstr . > [#####]_active_acc.txt 2> nul
for /f "delims=" %%a in ([#####]_active_acc.txt) do (
echo. Set WshShell = WScript.CreateObject^("WScript.Shell"^) > [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys ".\tools\psexec -u %%a cmd" >> [#####]_nopass_check.vbs 2> nul
echo. WScript.Sleep 500 >> [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys "{ENTER}" >> [#####]_nopass_check.vbs 2> nul
echo. WScript.Sleep 500 >> [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys "{ENTER}" >> [#####]_nopass_check.vbs 2> nul
echo. WScript.Sleep 500 >> [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys "if {%%}errorlevel{%%}==1327 echo %%a" >> [#####]_nopass_check.vbs 2> nul
echo. WScript.Sleep 500 >> [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys "{ENTER}" >> [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys "echo {%%}errorlevel{%%} %%a" >> [#####]_nopass_check.vbs 2> nul
echo. WScript.Sleep 500 >> [#####]_nopass_check.vbs 2> nul
echo. WshShell.SendKeys "{ENTER}" >> [#####]_nopass_check.vbs 2> nul
cscript [#####]_nopass_check.vbs
) > nul 2> nul
I'm looking for a way by using psexec with vbs.
But I think the best way is use runas command.
---------------------------------------------------------------
Edited!
Last edited by Squashman on 17 Jan 2020 08:53, edited 1 time in total.
Reason: MOD EDIT: Please use CODE TAGS.
Reason: MOD EDIT: Please use CODE TAGS.