Suman Rout
Suman Rout

Reputation: 11

Psexec can't execute remote batch file

I am using PSEXEC to get registry key value. The below is my code.

PowerShell:

Set-Alias psexec "e:\test\psexec.exe"

psexec \\172.20.118.74 -i -d -s -u xsumrouadm -p Welkom01 /c "E:\test\DeviceHealthRegistry.bat"

Batch file:

@echo off &setlocal
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0011 /v "IEEE11nmode"
@echo >> \\esessmw2395\c$\test\QueryDeviceHealth-Registry.csv

I am getting error as below:

psexec :  At line:3 char:1
+ psexec \\in00121324 e:\test\DeviceHealthRegistry.bat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

The system cannot find the path specified.

Connecting to in00121324...
Starting PSEXESVC service on in00121324...
Connecting with PsExec service on in00121324...
Starting e:\test\DeviceHealthRegistry.bat on in00121324...
PsExec could not start e:\test\DeviceHealthRegistry.bat on in00121324:

Computer name modified to IPaddress

psexec :  At line:3 char:1
psexec \\172.20.118.74 -i -d -s -u xsumrouadm -p Welkom01 /c "E:\test\DeviceHeal ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

The file exists.

Connecting to 172.20.118.74...
Starting PSEXESVC service on 172.20.118.74...
Connecting with PsExec service on 172.20.118.74...
Copying E:\test\DeviceHealthRegistry.bat to 172.20.118.74...
Error copying E:\test\DeviceHealthRegistry.bat to remote system:

Upvotes: 0

Views: 3034

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

You have two different errors from two different commands there:

  • The system cannot find the path specified.
    This error occurred, because you ran PsExec like this:

    psexec \\in00121324 e:\test\DeviceHealthRegistry.bat
    

    Without the option -c the local file E:\test\DeviceHealthRegistry.bat is not copied to the remote host, and there was no remote file E:\test\DeviceHealthRegistry.bat available for execution.

  • The file exists.
    This error occurred when you ran PsExec with the options -c and -d (the command accepts both / and - notation for parameters):

    psexec \\172.20.118.74 -i -d -s -u xsumrouadm -p Welkom01 /c "E:\test\DeviceHealthRegistry.bat"
    

    When you instruct PsExec to immediately detach from the remote process (-d) the file copied to the remote host is not removed after execution, so you probably have an artifact from a previous attempt in C:\Windows on the remote host. Remove that file (and the option -d) and the command should run as expected.

    psexec \\172.20.118.74 -i -s -u xsumrouadm -p Welkom01 -c "E:\test\DeviceHealthRegistry.bat"
    

    If you know that the file is already present on the remote host, you could also omit copying it again and run the command like this:

    psexec \\172.20.118.74 -i -d -s -u xsumrouadm -p Welkom01 DeviceHealthRegistry.bat
    

Upvotes: 2

Related Questions