Reputation: 34
below is my code
public void working()
{
while (true)
{
// Get text from clipboard
string clipboardtext = System.Windows.Forms.Clipboard.GetText();
string path = "c:\\sample.txt";
using (StreamWriter writer = new StreamWriter(path, true))
{
writer.WriteLine(string.Format("Clip Board Test " + "-" + " " + "Windows Service is called on " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss") + ""));
writer.Close();
System.Windows.Forms.Clipboard.SetDataObject("Hello ClipBoard");
}
Thread.Sleep(ScheduleTime * 6000);
}
}
Upvotes: 0
Views: 580
Reputation: 318
Windows service is not running in same "scope" as your user GUI, it cannot access to your clipboard or key stroke or anything you do. Services are useful, because they can run without logged user or under different user.
Services are not allowed to access your keystrokes or clipboard also for security reasons.
Upvotes: 2