stop service, Archive directory using C# on windows server 2008, start service, email notification

StackOverflow https://stackoverflow.com/questions/19799012

سؤال

I need to write a c# console application that through a sequence of events copies a directory.(will be scheduled to be ran off a windows 2008 server @ regular intervals)

  1. Check to see if serviceName is running on serverName
  2. If status is "Running", then attempt to stop the service.
  3. Wait until service is "Stopped" then
  4. Copy directory from serverName to differentServerName.
    • (overwrite old Directory in differentServerName completely)
  5. Check to see if service is still "Stopped" on serverName
  6. If status is "Stopped" then attempt to start the serviceName
  7. Once status is verified "running"
  8. Email a notification to someUser@someDomain.com

I have never worked with services and servers before so as I look through the info I am finding on the web I am feeling a bit lost. I am not sure where to start. The whole process seems extremely simple and I am sure I am over complicating it in my head.

Any help would be GREATLY appreciated!!!

هل كانت مفيدة؟

المحلول

http://code.msdn.microsoft.com/windowsdesktop/Interacting-With-a-Windows-d241f745 will help you learn to interact with the services

http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx will help with copying the directory/files

And googleing "C# send emails" will bring up lots of posts with many ways to send emails.

Once you get up and running, if you still need help, please post code and problem information for more detailed help.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top