Bilal Ahmad
Bilal Ahmad

Reputation: 301

cmd exited with error code 1

I am trying to search a file on remote PC using PSEXEC, however I am getting the above mentioned error.

Can any please suggest any change in the command or some thing else, that can assist in making it work. Online search suggests that this isn't the issue of PSEXEC, instead is caused by explorer.exe on remote host.

I have added picture of my result. I have tried the command with quotes on file name and without. both have same error.

enter image description here

Upvotes: 2

Views: 19722

Answers (3)

HarishKalva
HarishKalva

Reputation: 31

Open Registry Editor by pressing windows+r then type regedit and press enter now in the search bar paste the below line

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\

If you can see in the picture using the link Underlined mark is important don't insert any other value in the data of that particular registry.

Here if you filed many registry values then delete all of them except the default one as they are the main reason for the error code 1 shown by the command prompt. So after removing all of them.

Edit the default registry value and in 'data' insert cmd and save it

Your problem is solved!! if not then clear the data of the default registry.

Upvotes: 3

lit
lit

Reputation: 16236

It is also easy to use PowerShell and not need psexec.

Invoke-Command HOST01 { & cmd.exe /C dir D:\Users\lit\d.txt }

It should be written in .ps1 scripts with parameter names specified.

Invoke-Command -ComputerName HOST01 -ScriptBlock { & cmd.exe /C dir D:\Users\lit\d.txt }

See also:

help Enable-PSRemoting
help about_Remote
help about_Remote_FAQ

Upvotes: 0

knst
knst

Reputation: 533

This command dir exists with code 1 and message "File Not Found". Because you run cmd with param /c than it return same error code like dir and it is equal 1.

It is correct behaviour.

If you want to find a file, than use command where /r c:\ d.txt. This command was added in Windows 7.

Or use dir /S /P "d.txt" for older OS

Upvotes: 3

Related Questions