CQ-CSER

计算机爱好者

调用rundll32等实现各种功能:c#

Posted on | 三月 22, 2010 | No Comments

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using System.IO;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int iClose = 0;
private const int WM_SYSCOMMAND = 0×0112;
protected override void WndProc(ref Message SystemMessage)
{//处理系统消息
switch (SystemMessage.Msg)
{
case WM_SYSCOMMAND:
if (iClose == 0)
base.WndProc(ref SystemMessage);
break;
default:
base.WndProc(ref SystemMessage);
break;
}
}
private void button1_Click(object sender, EventArgs e)
{//禁止运行系统菜单按钮命令
this.iClose = 1;
MessageBox.Show(“已经禁止运行系统菜单按钮命令!”, “信息提示”,MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void button2_Click(object sender, EventArgs e)
{//允许运行系统菜单按钮命令
this.iClose = 0;
MessageBox.Show(“已经允许运行系统菜单按钮命令!”, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void button3_Click(object sender, EventArgs e)
{//获取当前计算机上的处理器数
string MyInfo = “当前计算机上的处理器数是:”;
MyInfo+=Environment.ProcessorCount.ToString();
MessageBox.Show(MyInfo, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

[DllImport("USER32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Ansi)]
private static extern int ShowWindow(int hWnd, int  nCmdShow);
[DllImport("USER32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Ansi)]
private static extern int FindWindow(string  lpClassName,string lpWindowName);
private const int SW_HIDE=0;
//private const int SW_SHOW = 5;
private void button4_Click(object sender, EventArgs e)
{//禁止显示操作系统任务栏
ShowWindow(FindWindow(“Shell_TrayWnd”,null ),SW_HIDE);
}
private void button5_Click(object sender, EventArgs e)
{//允许显示操作系统任务栏
ShowWindow(FindWindow(“Shell_TrayWnd”, null), SW_SHOW);
}

[DllImport("USER32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Ansi)]
private static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
private void button6_Click(object sender, EventArgs e)
{//禁止显示操作系统开始按钮
ShowWindow(FindWindowEx(FindWindow(“Shell_TrayWnd”, “”), 0, “Button”, null), SW_HIDE);
}
private void button7_Click(object sender, EventArgs e)
{//允许显示操作系统开始按钮
ShowWindow(FindWindowEx(FindWindow(“Shell_TrayWnd”,”"),0,”Button”,null),SW_SHOW);
}

//[DllImport("shell32.dll", EntryPoint = "ShellExecute")]
//private static extern int ShellExecute(int hwnd, String lpOperation, String lpFile, String lpParameters, String lpDirectory, int nShowCmd);
private void button8_Click(object sender, EventArgs e)
{//启动操作系统的搜索对话框
try
{
ShellExecute(0,”find”,”",”",”",0);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message ,”信息提示”,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}

private void button9_Click(object sender, EventArgs e)
{//启动操作系统的注册表编辑器
System.Diagnostics.Process.Start(“RegEdit.exe”);
}

[DllImport("shell32.dll", EntryPoint = "ShellExecute")]
private static extern int ShellExecute(int hwnd, String lpOperation, String lpFile, String lpParameters, String lpDirectory, int nShowCmd);
private const int SW_SHOW = 5;
private void button10_Click(object sender, EventArgs e)
{//启动操作系统的邮件发送程序
try
{
//ShellExecute(this.Handle.ToInt32(), “open”, “notepad.exe”, “c:\\boot.ini”, “”, SW_SHOW);
//ShellExecute(this.Handle.ToInt32(), “print”, “c:\\boot.ini”, “”, “”, SW_HIDE);
ShellExecute(0, “open”, “mailto:”, “”, “”, SW_SHOW);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
[DllImport("kernel32.dll")]
private static extern int WinExec(String CmdLine, int uCmdShow);
private void button11_Click(object sender, EventArgs e)
{//启动Internet选项的指定选项卡
//启动系统Internet属性\常规对话框
//WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,0 “, 0);
//启动系统Internet属性\安全对话框
//WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,1 “, 0);
//启动系统Internet属性\隐私对话框
//WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,2 “, 0);
//启动系统Internet属性\内容对话框
//WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,3 “,0);
//启动系统Internet属性\连接对话框
//WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,4 “,0);
//启动系统Internet属性\程序对话框
//WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,5 “,0);
//启动系统Internet属性\高级对话框
WinExec(“rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,6 “,0);
}

private void button12_Click(object sender, EventArgs e)
{//将网址加入Internet收藏夹
string MyFavoriteFolder= System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) ;
string MyTitle=”中国门户网:网易”;
string MyURL = “Http://www.163.com”;
StreamWriter MyWriter = File.CreateText(MyFavoriteFolder+”\\”+ MyTitle +”.url”) ;
MyWriter.WriteLine(“[InternetShortcut]“);
MyWriter.WriteLine(“URL=”+MyURL);
MyWriter.Close();
}

}
}

————————————————————————————-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using System.Diagnostics;

//#define SW_HIDE             0
//#define SW_SHOWNORMAL       1
//#define SW_NORMAL           1
//#define SW_SHOWMINIMIZED    2
//#define SW_SHOWMAXIMIZED    3
//#define SW_MAXIMIZE         3
//#define SW_SHOWNOACTIVATE   4
//#define SW_SHOW             5
//#define SW_MINIMIZE         6
//#define SW_SHOWMINNOACTIVE  7
//#define SW_SHOWNA           8
//#define SW_RESTORE          9
//#define SW_SHOWDEFAULT      10
//#define SW_FORCEMINIMIZE    11
//#define SW_MAX              11

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("USER32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Ansi)]
private static extern int ShowWindow(int hWnd, int nCmdShow);
[DllImport("USER32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Ansi)]
private static extern int FindWindow(string lpClassName, string lpWindowName);
private void button1_Click(object sender, EventArgs e)
{//禁止显示操作系统桌面图标
ShowWindow(FindWindow(“Progman”, null), 0);
}
private void button2_Click(object sender, EventArgs e)
{//允许显示操作系统桌面图标
ShowWindow(FindWindow(“Progman”, null), 5);
}
[DllImport("TAPI32.dll")]
public static extern int tapiRequestMakeCall(string DestAddress, string AppName, string CalledParty, string Comment);
private void button3_Click(object sender, EventArgs e)
{//启动电话拨号程序
string MyPhone = “40405690″;
string MyInfo = “”;
int MyReturn = tapiRequestMakeCall(MyPhone, “我的电话拨号”, “”, “”);
switch (MyReturn)
{
case 0:
MyInfo += “\n拨号已连接”;
break;
case -4:
MyInfo += “\n错误的目的地址”;
break;
case -2:
MyInfo += “\n没有电话接口程序运行”;
break;
case -16:
MyInfo += “\n拨号请求由于未知原因失败”;
break;
case -11:
MyInfo += “\n对方电话正忙”;
break;
case -15:
MyInfo += “\n没有这个电话号码”;
break;
case -1:
MyInfo += “\n对方已挂断”;
break;
}
MessageBox.Show(MyInfo, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SYSCOMMAND = 0×0112;
private const int SC_SCREENSAVE = 0xf140;
private void button4_Click(object sender, EventArgs e)
{//启动屏幕保护程序
SendMessage(this.Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
}

private void button5_Click(object sender, EventArgs e)
{//获取公共语言运行库的版本号
Version MyVer = Environment.Version;
string MyInfo = “公共语言运行库的版本号信息如下:”;
MyInfo += “\n主版本号:” + MyVer.Major;
MyInfo += “\n次版本号:” + MyVer.Minor;
MyInfo += “\n内部版本号:” + MyVer.Build;
MyInfo += “\n修订号:” + MyVer.Revision;
MessageBox.Show(MyInfo, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void button6_Click(object sender, EventArgs e)
{//获取性能计数器类别
PerformanceCounterCategory[] MyCategories = PerformanceCounterCategory.GetCategories();
string MyInfo = “本地计算机上注册的性能计数器类别包括:\n”;
foreach (PerformanceCounterCategory MyCategory in MyCategories)
{
MyInfo += MyCategory.CategoryName + “、”;
}
MessageBox.Show(MyInfo, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void button7_Click(object sender, EventArgs e)
{//获取性能计数器名称
try
{
string MyCategory = “Processor”;
System.Diagnostics.PerformanceCounterCategory MyKind =
new System.Diagnostics.PerformanceCounterCategory(MyCategory);
string[] MyInstanceNames = MyKind.GetInstanceNames();
string MyInfo = MyCategory+”类型的计数器包括:”;
if (MyInstanceNames.Length == 0)
{
foreach( PerformanceCounter MyCounter in MyKind.GetCounters())
{
MyInfo+=MyCounter.CounterName+”、”;
}
}
else
{
for (int i = 0; i < MyInstanceNames.Length; i++)
{
foreach(PerformanceCounter MyCounter in MyKind.GetCounters(MyInstanceNames[i]))
{
MyInfo += MyCounter.CounterName + “、”;
}
}
}
MessageBox.Show(MyInfo, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception Ex)
{
}
}

private int iClose = 0;
private const int WM_QUERYENDSESSION = 0×0011;
protected override void WndProc(ref Message SystemMessage)
{//处理系统消息问询
switch (SystemMessage.Msg)
{
case WM_QUERYENDSESSION:
SystemMessage.Result = (IntPtr)iClose;
break;
default:
base.WndProc(ref SystemMessage);
break;
}
}
private void button8_Click(object sender, EventArgs e)
{//禁止关闭操作系统
this.iClose = 0;
MessageBox.Show(“请选择“开始\\关闭计算机”菜单测试一下效果!”, “信息提示”,MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button9_Click(object sender, EventArgs e)
{//允许关闭操作系统
this.iClose = 1;
MessageBox.Show(“请选择“开始\\关闭计算机”菜单测试一下效果!”, “信息提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

}
}

相关文章:

  1. 读写WIN.INI配置文件:c#
  2. c#调用系统各参数
  3. wmi查询管理:c#
  4. VISUAL C#系列
  5. 启动控制面板各选项:c#

评论|Comments

留言|Leave a Reply





  • Archives

  • SUNSHINE

  • About

    本博客采用创作共用版权协议,要求署名、非商业用途和保持一致. 转载本博客内容也遵循“署名-非商业用途-保持一致”的创作共用协议.

    订阅

    Search

    Admin