想编写程序,,,,判断某文件是否被使用~~并找到使用该文件的程序....(进程啊,,,窗口名之类的信息..)语言C++...可以动用API之类的~~~如何实现????
è¿æ¯æå¨å
¶ä»ç«ç¹æ¾çï¼ä¸ç¥éè½ä¸è½å¸®ä¸å¿ã
using System.IO;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern IntPtr _lopen(string lpPathName, int iReadWrite);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr hObject);
public const int OF_READWRITE = 2;
public const int OF_SHARE_DENY_NONE = 0x40;
public readonly IntPtr HFILE_ERROR = new IntPtr(-1);
private void button1_Click(object sender, EventArgs e)
{
string vFileName = @"c:\temp\temp.bmp";
if (!File.Exists(vFileName))
{
MessageBox.Show("æ件é½ä¸åå¨ï¼ä½ å°±ä¸è¦æ¿æ¥èäº");
return;
}
IntPtr vHandle = _lopen(vFileName, OF_READWRITE | OF_SHARE_DENY_NONE);
if (vHandle == HFILE_ERROR)
{
MessageBox.Show("æ件被å ç¨ï¼");
return;
}
CloseHandle(vHandle);
MessageBox.Show("没æ被å ç¨ï¼");
}
using System.IO;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern IntPtr _lopen(string lpPathName, int iReadWrite);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr hObject);
public const int OF_READWRITE = 2;
public const int OF_SHARE_DENY_NONE = 0x40;
public readonly IntPtr HFILE_ERROR = new IntPtr(-1);
private void button1_Click(object sender, EventArgs e)
{
string vFileName = @"c:\temp\temp.bmp";
if (!File.Exists(vFileName))
{
MessageBox.Show("æ件é½ä¸åå¨ï¼ä½ å°±ä¸è¦æ¿æ¥èäº");
return;
}
IntPtr vHandle = _lopen(vFileName, OF_READWRITE | OF_SHARE_DENY_NONE);
if (vHandle == HFILE_ERROR)
{
MessageBox.Show("æ件被å ç¨ï¼");
return;
}
CloseHandle(vHandle);
MessageBox.Show("没æ被å ç¨ï¼");
}
温馨提示:答案为网友推荐,仅供参考