0

I am just getting a blank file with the following command:

net use \\computername password /user:username > log.txt

How can I get this to work?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
tim.tub
  • 69
  • 2
  • 7
  • 1
    `> log.txt` catches only STDOUT (Stream 1). Errors are written to `STDERR` (Stream 2). `>log.txt 2>&1` redirects STDERR to wherever `STOUT` goes (`log.txt` in this case) – Stephan May 25 '19 at 11:32

2 Answers2

1

Capture stderr output and check ERRORLEVEL. A sharename is also needed. See the output of the NET HELP USE command.

net use \\computername\sharename password /user:username >"log.txt" 2>&1
if NOT ERRORLEVEL 1 goto NetUsePassed
echo ERROR: NET USE failed.

:NetUsePassed
lit
  • 14,456
  • 10
  • 65
  • 119
0

On my PC, which I am currently logged in, I can execute...

net use \\localhost user:Gwen > C:\TEMP\output.txt

Which produces the following text in the output file...

The command completed successfully

Note that I did not pass the password to the command.

Gwen
  • 23
  • 1
  • 7
  • Thank you Gwen. I am wanting to use this command as a means of verifying the password in a script. Is there an alternative way I can do this? – tim.tub May 24 '19 at 20:46
  • This redirection won't work when the output is an error. You can specifiy that you want the output from both ster and stoud with 2>&1 – Alex M.M. Nov 19 '19 at 18:17