1

I have created a Windows Service using C# which performs variance network maintenance tasks for me. One of the tasks is defraging machines remotely and for some of my older boxes I found the only way to do this was using psexec with defrag.exe. The code works fine when I simply run my C# code, however when I covert it into a Windows Service it does the defraging using the Win32_Volume table fine but it seems to get hung up when attempting to use PsExec to defrag the XP machines.

I guess my questions is, are there any known errors with using PsExec within a Windows Service? If so are there any suggestions for a different method I can use?

Thank you.

mgrenier
  • 1,409
  • 3
  • 21
  • 45

1 Answers1

1

psexec issues a software licence agreement dialog the first time it is run as a given user, so that could be your problem if the service is running as some other user.

You can suppress this by adding the parameter

/accepteula

This could be your problem, though obviously I can't be sure!

Fergus Bown
  • 1,666
  • 9
  • 16
  • I am still having a problem with this, I get farther along in the code now but it appear there is some sort of permissions problem running defrag.exe on a remote machine with PsExec. I have tried entering the username and password of an account with sufficient privileges but it doesn't seem to help. Any ideas?? – mgrenier Jan 03 '13 at 17:01
  • It seems like my continued problems are less to do with PsExec and more to do with the Windows Service because the task works in my C# code but gives me an exit code of 6 (handle is invalid) in my windows service...I am running the process with an account that does have admin rights on the machines in question...any ideas?? – mgrenier Jan 08 '13 at 15:49