C# API SHQUERYRECYCLEBIN

Posted: July 15, 2014 in C#
Tags: , ,

C# API fonksiyonlarından yararlanılarak geri dönüşüm kutusunda kac öge oldugu ve ne kadar boyutta oldugu hesaplanabilir.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication28
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

[DllImport(“shell32.dll”)]
static extern int SHQueryRecycleBin(string pszRootPath,ref SHQUERYRBINFO pSHQueryRBInfo);
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct SHQUERYRBINFO
{
public int size;
public long size1;
public long item;
}

[DllImport(“shell32.dll”)]
static extern int SHEmptyRecycleBin(IntPtr hWnd, string pszRootPath,uint dwFlags);
const int SHERB_NOCONFIRMATION = 0x00000001;
const int SHERB_NOPROGRESSUI = 0x00000002;
const int SHERB_NOSOUND = 0x00000004;

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

SHQUERYRBINFO shqrbin = new SHQUERYRBINFO();
shqrbin.size = Marshal.SizeOf(typeof(SHQUERYRBINFO));
int hresult = SHQueryRecycleBin(string.Empty, ref shqrbin);
label1.Text = label1.Text + ” ” +
(Convert.ToInt32(shqrbin.item).ToString());
label2.Text = label2.Text + ” ” +
(Convert.ToInt32(shqrbin.size1 /
(1024 * 1024)).ToString()) + ” mb”;
}

private void button2_Click(object sender, EventArgs e)
{
SHEmptyRecycleBin(IntPtr.Zero, “C:”,
SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND);
MessageBox.Show(“Geri dönüşüm kutusu boşaltıldı”);
}

private void lblSayi_Click(object sender, EventArgs e)
{

}
}
}

son

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s