问题
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.
回答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!
来源:https://stackoverflow.com/questions/14140826/using-psexec-in-a-windows-service