0

I would like to run hostname on a remote machine CLIENT1. If I provide the hostname with a UNC path directly in the psexec command it works fine as you can see below.

psexec \\CLIENT1 -e cmd /c hostname

CLIENT1 
cmd exited on CLIENT1 with error code 0. 

If I choose to use the @file parameter of psexec to pass in a text file with the hostname, it doesn't run the hostname command. It simply drops me in the cmd on the remote machine and stops executing.

psexec @"c:\temp\hostname.txt" -e cmd /c hostname

I can manually run hostname once I'm in there, but that's not what I'm after. I either have to exit or Ctrl-C.

I've tried every combination of quotes that I can think of and nothing has worked. Is this a bug? Can anyone reproduce this behavior? I'm running psexec v2.2 on Windows 7 SP1 (both local and remote), but also saw the behavior in psexec v2.11 as well.

pk.
  • 6,413
  • 1
  • 41
  • 63

2 Answers2

1

Apparently the path to the file containing the hostnames absolutely cannot be quoted. This means your file of hostnames had better not have any spaces in the path. I'm not sure if this is intended or not, but I sure lost a lot of time chasing it down.

BAD

psexec @"c:\temp\hostname.txt" -e cmd /c hostname
psexec @"hostname.txt" -e cmd /c hostname

GOOD

psexec @c:\temp\hostname.txt -e cmd /c hostname
psexec @hostname.txt -e cmd /c hostname
psexec @..\..\..\Temp\hostname.txt cmd /c hostname
psexec @\Temp\hostname.txt`
pk.
  • 6,413
  • 1
  • 41
  • 63
-1

PsExec \@Filename.txt -s cmd -u user

  • 1
    Try to explain what you are doing and why you thinks this may help (Bonus: try to use formatting) – bjoster May 25 '20 at 14:27