网上现在有Delphi的例子和C++的吧?
谁在C#中实现过?VB.NET也行.或者谁在.NET下使用过ICopyHook::CopyCallback
如何使用,给段代码也行.下面是一个例子-但不是.NET的.
http://dev.csdn.net/develop/article/22/22347.shtm
谁在C#中实现过?VB.NET也行.或者谁在.NET下使用过ICopyHook::CopyCallback
如何使用,给段代码也行.下面是一个例子-但不是.NET的.
http://dev.csdn.net/develop/article/22/22347.shtm
解决方案 »
- 如何使用C#把一些bmp图像连接成avi视频
- 请教一个.net方面页面数据获取的问题的
- C#如何实现播放视频
- 关于在asp.net中将数据导出到excel。急!!
- 给高分找如何生成bin目录下的dll文件以及如何调用的实例?
- 急,请saucer大哥帮忙,求你了, Updater application block 2.0使用的问题
- 关于用C#设计KWIC(KEY WORD IN CONTEXT)系统设计模块,看不懂:(在线等注释,非常感谢!HELP!!给分答谢哦:)
- 请教个关于窗口坐标的问题。
- DriveInfo 类的属性
- 怎么只生成一个类的实例
- C#里面对方法的定义可以使用中文,不知道有没有什么不好的地方?
- 请问在c#里,如果将字符从unicode转成gb2312 ??????
{
FileSystemWatcher p = new FileSystemWatcher("d:\\");
p.EnableRaisingEvents = true;
p.IncludeSubdirectories = true;
p.Changed+=new FileSystemEventHandler(p_Changed);
p.Created+=new FileSystemEventHandler(p_Created);
p.Deleted+=new FileSystemEventHandler(p_Deleted);
} private void p_Changed(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被更改于 "+DateTime.Now);
} private void p_Created(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被创建于 "+DateTime.Now);
} private void p_Deleted(object sender, FileSystemEventArgs e)
{
string s = e.Name;
this.listBox1.Items.Add(s+"文件被删除于 "+DateTime.Now);
}
至于如何判断正在修改和已经修改完成,这个FileSystemWatcher做不到
一般是开始修改前随便设置一个属性,修改完再设置回来,用这个属性作为标志位判断
问题是,我用这个函数监控其他程序生产的文件,
所以没法设置标志,有没有其他方法?
如果外部程序还没写完,那文件必然还被占用,那么你的打开文件的代码会抛出异常
用try/catch对判断以前看到过一个列举占用某个文件的所有进程的例子,巨复杂,我也忘了~
http://www.gxgl.com/?action=soft&module=show&id=52
using System.IO ;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace FileSystemWatcher
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.IO.FileSystemWatcher fileSystemWatcher1;
private System.Windows.Forms.TextBox txtDir;
private System.Windows.Forms.Button btnSetPath;
private System.Windows.Forms.TextBox txtInfo;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
this.txtDir = new System.Windows.Forms.TextBox();
this.btnSetPath = new System.Windows.Forms.Button();
this.txtInfo = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).BeginInit();
this.SuspendLayout();
//
// fileSystemWatcher1
//
this.fileSystemWatcher1.EnableRaisingEvents = true;
this.fileSystemWatcher1.SynchronizingObject = this;
this.fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Changed);
this.fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Created);
this.fileSystemWatcher1.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcher1_Renamed);
this.fileSystemWatcher1.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Deleted);
//
// txtDir
//
this.txtDir.Location = new System.Drawing.Point(40, 24);
this.txtDir.Name = "txtDir";
this.txtDir.Size = new System.Drawing.Size(208, 21);
this.txtDir.TabIndex = 0;
this.txtDir.Text = "";
//
// btnSetPath
//
this.btnSetPath.Location = new System.Drawing.Point(112, 64);
this.btnSetPath.Name = "btnSetPath";
this.btnSetPath.TabIndex = 1;
this.btnSetPath.Text = "设置路径";
this.btnSetPath.Click += new System.EventHandler(this.btnSetPath_Click);
//
// txtInfo
//
this.txtInfo.Location = new System.Drawing.Point(40, 104);
this.txtInfo.Multiline = true;
this.txtInfo.Name = "txtInfo";
this.txtInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtInfo.Size = new System.Drawing.Size(208, 176);
this.txtInfo.TabIndex = 2;
this.txtInfo.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 293);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtInfo,
this.btnSetPath,
this.txtDir});
this.Name = "Form1";
this.Text = "文件系统监视器";
((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void btnSetPath_Click(object sender, System.EventArgs e)
{
fileSystemWatcher1.Path=txtDir.Text;
} private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\n\n"; } protected void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\n\n";
}
protected void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
{
txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\n\n";
}
protected void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
{
txtInfo.Text += "ChangeType :: " + e.ChangeType.ToString() + "\nFullPath ::" + e.FullPath.ToString() + "\nOld FileName :: "+ e.OldName.ToString() + "\n\n";
} }
}
看了一个CSDN的例子,结果照做还是不行。
网上到有些好用的例子,可惜我想要的那部分他们都给省略了。
谁知道如何写服务的安装文件???
哪写类或者事件,需要单独安装注册?
//
在初始化安装时发生异常:
System.IO.FileNotFoundException:找不到文件或程序集名称“Documents”,或找不到它
的一个依赖项。。
//
谁遇到过,怎么解决?大家别急,等我把服务写完了,就过来结贴。还希望大家多多帮忙啊?
System.IO.FileNotFoundException:找不到文件或程序集名称“Documents”,或找不到它
的一个依赖项。。
安装文件也做了,该设置的也设置了,里面没用什么东西,只在Start时用了上面提到的文件监控,其他都没有用。
我用空项目做了一个服务,什么代码也没写。安装也做了,还是提示上面的问题。
?????????????????
在做一个Windows服务程序?还是安装程序?和你这个帖子的问题有什么关系?
如果你写过Windows服务的话应该很清楚吧?
我当初问这个问题就是想写这个文件监控的服务....我把文件监控的代码加入到 服务的的 Onstart 过程中。网上有有个监控文件夹的例子,他是把文件夹使用的(删除,添加,修改)频率记下来
我用InstallUtil.exe 安装服务成功了, 但是我稍修改一下就不行了,
我又自己写了一个,里面没了一点代码,然后再安装就出现上面的问题了。
生成exe文件后,用InstallUtil注册不就可以了么你把示例的代码改错了,又提供不了详细的错误信息,又看不到你的代码,别人如何知道错在哪里?
还不如先好好研究一下Windows服务程序的结构(用VS.NET的模版新建个程序),再加入自己的代码,出错了再来问
http://dev.csdn.net/article/20/20794.shtm
http://www.gotdotnet.com/Community/UserSamples/Download.aspx?SampleGuid=ACC5EAD1-10C5-4526-ADA3-7C7B7D64E25D