using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
// Remember to add a reference to the System.Management assembly
using System.Management;
namespace ShutDown
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnShutDown_Click(object sender, EventArgs e)
{
ManagementBaseObject mboShutdown = null;
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
mcWin32.Get();
// You can't shutdown without security privileges
mcWin32.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");
// Flag 1 means we want to shut down the system
mboShutdownParams["Flags"] = "1";
mboShutdownParams["Reserved"] = "0";
foreach (ManagementObject manObj in mcWin32.GetInstances())
{
mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
}
}
}
}
Thursday, April 16, 2009
Generate random password
private string GenerateRandomPassword(int Length)
{
// We want all popular characters except for the ones that can easily be confused (e.g., l and 1)
string[] Characters = new string[56];
Characters[0] = "a";
Characters[1] = "b";
Characters[2] = "c";
Characters[3] = "d";
Characters[4] = "e";
Characters[5] = "f";
Characters[6] = "g";
Characters[7] = "h";
Characters[8] = "j";
Characters[9] = "k";
Characters[10] = "m";
Characters[11] = "n";
Characters[12] = "p";
Characters[13] = "q";
Characters[14] = "r";
Characters[15] = "s";
Characters[16] = "t";
Characters[17] = "u";
Characters[18] = "v";
Characters[19] = "w";
Characters[20] = "x";
Characters[21] = "y";
Characters[22] = "z";
Characters[23] = "A";
Characters[24] = "B";
Characters[25] = "C";
Characters[26] = "D";
Characters[27] = "E";
Characters[28] = "F";
Characters[29] = "G";
Characters[30] = "H";
Characters[31] = "J";
Characters[32] = "K";
Characters[33] = "L";
Characters[34] = "M";
Characters[35] = "N";
Characters[36] = "P";
Characters[37] = "Q";
Characters[38] = "R";
Characters[39] = "S";
Characters[40] = "T";
Characters[41] = "U";
Characters[42] = "V";
Characters[43] = "W";
Characters[44] = "X";
Characters[45] = "Y";
Characters[46] = "Z";
Characters[47] = "2";
Characters[48] = "3";
Characters[49] = "4";
Characters[50] = "5";
Characters[51] = "6";
Characters[52] = "7";
Characters[53] = "8";
Characters[54] = "9";
Random RandChar = new Random();
string Password = "";
for (int i = 0; i < Length; i++)
{
Password += Characters[RandChar.Next(0, 55)];
}
return Password;
}
{
// We want all popular characters except for the ones that can easily be confused (e.g., l and 1)
string[] Characters = new string[56];
Characters[0] = "a";
Characters[1] = "b";
Characters[2] = "c";
Characters[3] = "d";
Characters[4] = "e";
Characters[5] = "f";
Characters[6] = "g";
Characters[7] = "h";
Characters[8] = "j";
Characters[9] = "k";
Characters[10] = "m";
Characters[11] = "n";
Characters[12] = "p";
Characters[13] = "q";
Characters[14] = "r";
Characters[15] = "s";
Characters[16] = "t";
Characters[17] = "u";
Characters[18] = "v";
Characters[19] = "w";
Characters[20] = "x";
Characters[21] = "y";
Characters[22] = "z";
Characters[23] = "A";
Characters[24] = "B";
Characters[25] = "C";
Characters[26] = "D";
Characters[27] = "E";
Characters[28] = "F";
Characters[29] = "G";
Characters[30] = "H";
Characters[31] = "J";
Characters[32] = "K";
Characters[33] = "L";
Characters[34] = "M";
Characters[35] = "N";
Characters[36] = "P";
Characters[37] = "Q";
Characters[38] = "R";
Characters[39] = "S";
Characters[40] = "T";
Characters[41] = "U";
Characters[42] = "V";
Characters[43] = "W";
Characters[44] = "X";
Characters[45] = "Y";
Characters[46] = "Z";
Characters[47] = "2";
Characters[48] = "3";
Characters[49] = "4";
Characters[50] = "5";
Characters[51] = "6";
Characters[52] = "7";
Characters[53] = "8";
Characters[54] = "9";
Random RandChar = new Random();
string Password = "";
for (int i = 0; i < Length; i++)
{
Password += Characters[RandChar.Next(0, 55)];
}
return Password;
}
Delete all temparary file of Internet explorer
using System.IO;
public static void Main()
#
{
ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))); // Execute ClearFolder() on the IE's cache folder
}
void ClearFolder(DirectoryInfo diPath)
{
foreach (FileInfo fiCurrFile in diPath.GetFiles())
{
fiCurrFile.Delete();
}
foreach (DirectoryInfo diSubFolder in diPath.GetDirectories())
{
ClearFolder(diSubFolder); // Call recursively for all subfolders
}
public static void Main()
#
{
ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))); // Execute ClearFolder() on the IE's cache folder
}
void ClearFolder(DirectoryInfo diPath)
{
foreach (FileInfo fiCurrFile in diPath.GetFiles())
{
fiCurrFile.Delete();
}
foreach (DirectoryInfo diSubFolder in diPath.GetDirectories())
{
ClearFolder(diSubFolder); // Call recursively for all subfolders
}
Subscribe to:
Posts (Atom)