Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exitcode 6 using PsExec in Windows Service

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.

like image 428
mgrenier Avatar asked Jan 03 '13 19:01

mgrenier


People also ask

How do I use PsExec on Windows?

Open the windows command prompt and switch to the pstools directory, then type psexec and press enter. You should see PsExec return the version and command syntax. In the screenshot below you can see I changed to the “c:\pstools” directory to run the psexec command.

What service does PsExec use?

PSExec has a Windows Service image inside of its executable. It takes this service and deploys it to the Admin$ share on the remote machine. It then uses the DCE/RPC interface over SMB to access the Windows Service Control Manager API.

How do I run PsExec on Windows 10?

In order to use the PsExec tool, simply download the PSTools. zip archive from Microsoft and extract the PsExec64.exe and PsExec.exe files to any folder on your computer (it is convenient to copy it to the default executable folder C:\Windows\System32). You can run PsExec from the command prompt or PowerShell console.


1 Answers

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.

like image 188
Ben Butzer Avatar answered Oct 05 '22 22:10

Ben Butzer