6

I am using PsExec to defrag machines remotely on my network. This works fine in my c# code, but because it also does a bunch of other tasks and I want it to run continuously I have converted it into a windows service.

When the code gets to the PsExec portion it exits with the code 6 which seems to mean "The handle is invalid" I have tried entering a username and password with sufficient privileges without success, I have also tried adding -s to use the system account which did not help either.

Here is the line where I set my PsExec arguements...

psexec.StartInfo.Arguments = @" \\" + machine + "/accepteula -s defrag.exe " + volume + " -f";

I have also tried...

psexec.StartInfo.Arguments = @" \\" + machine + "/accepteula defrag.exe " + volume + " -f";
psexec.StartInfo.Arguments = @" \\" + machine + "/accepteula defrag.exe " + volume + "-u myuser -p mypass -f";

Any help would be greatly appreciated!! But nothing seems to fix my problem.

mgrenier
  • 1,409
  • 3
  • 21
  • 45
  • I also did connect to the machines in question from the server the code is running on directly via \\machine\c$ while logged into the myuser\mypass account to ensure I could access the administrative share and I was successful...please any help would be great I am stumped and getting very frustrated – mgrenier Jan 04 '13 at 14:31
  • I am also facing this issue :( – Deep Jan 16 '17 at 11:42

1 Answers1

1

I know this has been open a long time, but did you find a stuck psexec service on the remote machine?

What we found was the PsExec service entry was still in Services and PsExeSvc was still in C:\WINDOWS folder.

We deleted exe from C:\WINDOWS and ran “sc delete PsExec” from an elevated command prompt to get rid of service.

Ben Butzer
  • 915
  • 10
  • 24