日期:2014-05-16 浏览次数:20779 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.IO;
namespace Service_Windows
{
public partial class Service_Windows : ServiceBase
{
public Service_Windows()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
huanbizhi hbz = new huanbizhi();
hbz.huan(@"H:\3号机备分\bak\照片", 5, 0);
}
protected override void OnStop()
{
}
}
public class huanbizhi
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
[DllImport("user32.dll")]
public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
public void huan(string path, int time, int yangshi)
{
string[] filename = Directory.GetFiles(path);
Random rd = new Random();
bool b = true;
while (b)
{
ChangeWallPaper(filename[rd.Next(0, filename.Length - 1)], yangshi);
System.Threading.Thread.Sleep(time * 1000);
}
}
public void ChangeWallPaper(string picturePath, int style)