发新话题
打印

[原创]系统工具(学习之用)

[原创]系统工具(学习之用)

软件作者:kebin
信息来源:邪恶八进制信息安全团队(www.eviloctal.com

以下是源码 c#编写

小的菜 也玩把开源精神 哈哈
复制内容到剪贴板
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Management;
namespace WindowsApplication8
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
      textBox1.Clear();
      RegistryKey i;
      i = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion"); //读取注册表
      string s = "当前操作系统版本:" + i.GetValue("ProductName").ToString();
      s = s + "\r\n" + i.GetValue("CurrentBuildNumber").ToString();
      s = s + "\r\n当前操作系统安装序列号:\r\n" + i.GetValue("ProductId").ToString();
      s = s + "\r\n当前系统版本号:" + i.GetValue("CurrentBuildNumber").ToString();
      i.Close();
      textBox1.Text = textBox1.Text + "\r\n" + s;

    }
    private void Form1_Load(object sender, EventArgs e)
    {
      label1.Text = "东方不败3:" + DateTime.Now.ToString();
      RegistryKey i;
      i = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion");
      string s = i.GetValue("ProductName").ToString();
      if (System.Text.RegularExpressions.Regex.IsMatch(s, "Windows XP"))
      {
        textBox2.Text = "您的操作系统:Windows XP";
      }
      if (System.Text.RegularExpressions.Regex.IsMatch(s, "Windows 2000"))
      {
        textBox2.Text = "您的操作系统:Windows Server 2000";
      }
      if (System.Text.RegularExpressions.Regex.IsMatch(s, "Windows Server 2003"))
      {
        textBox2.Text = "您的操作系统:Windows Server 2003";
      }
      i.Close();
    }
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct USER_INFO_0
    {
      public string Username;
    }
    [DllImport("Netapi32.dll")]
    extern static int NetUserEnum(
      [MarshalAs(UnmanagedType.LPWStr)]
  string servername,
      int level,
      int filter,
      out IntPtr bufptr,
      int prefmaxlen,
      out int entriesread,
      out int totalentries,
      out int resume_handle);
    [DllImport("Netapi32.dll")]
    extern static int NetApiBufferFree(IntPtr Buffer);
    private void button2_Click(object sender, EventArgs e)
    {
      textBox1.Clear();
      int EntriesRead;
      int TotalEntries;
      int Resume;
      IntPtr bufPtr;
      NetUserEnum(null, 0, 2, out bufPtr, -1, out EntriesRead,
        out TotalEntries, out Resume);
      if (EntriesRead > 0)
      {
        USER_INFO_0[] Users = new USER_INFO_0[EntriesRead];
        IntPtr iter = bufPtr;
        for (int i = 0; i < EntriesRead; i++)
        {
          Users = (USER_INFO_0)Marshal.PtrToStructure(iter,
            typeof(USER_INFO_0));
          iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(USER_INFO_0)));
          textBox1.AppendText("当前帐户:" + Users.Username + "\r\n");
        }
        NetApiBufferFree(bufPtr);
      }
    }
    private void button3_Click(object sender, EventArgs e)
    {
      string stringMAC = "";
      string stringIP = "";
      ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
      ManagementObjectCollection MOC = MC.GetInstances();
      foreach (ManagementObject MO in MOC)
      {
        if ((bool)MO["IPEnabled"] == true)
        {
          stringMAC += MO["MACAddress"].ToString();
          string[] IPAddresses = (string[])MO["IPAddress"];
          if (IPAddresses.Length > 0) stringIP = IPAddresses[0];
          textBox1.Text = "IP地址:" + stringIP.ToString() + "\r\n" + "网卡地址:" + stringMAC.ToString();
        }
      }
    }
    private void button4_Click(object sender, EventArgs e)
    {
      Form2 f2 = new Form2();
      f2.ShowDialog();
      
    }
  }
}

附件

系统工具.rar (18 KB)

2007-6-28 19:33, 下载次数: 42

TOP

只能说----写得烂,很烂,非常烂!
不是我打击你

先说编码习惯
如果你是新手,请注意一下编程习惯:
工程名 变量命名 控件命名 类型转换 容错处理 异常处理 布尔表达式在if语句中的用法``````

再说功能实现
楼主应该还不熟悉.NET框架
查看系统这些信息哪用得着 注册表 Management  Net...
只需用个Microsoft.VisualBasic.Devices足以
--->  伱 能 領 導 潮 流.  我 可 領 導 全 賕!  <---

TOP

zshoucheng 大哥 教训的是... 这些地方 是没有太注意 我是新手

工程名 变量命名 控件命名  我一般不在认真写的时候 不会太去更改 我不知道 你们为什么都是换个名 只是就这些代码 不用重命名吧

布尔表达式在if语句中的用法``````  使用 true 和flash?

Microsoft.VisualBasic.Devices  这个类 我真的不太熟悉  
刚才上百度看了 一下 一会经细看一下
但是不用 Management 能或取到windows版本号吗
谢谢

TOP

如果不养成好的编码习惯,到以后你就知道麻烦了
新手更应该注意这些,即使是很简单的小程序
不然以后你开发大项目的时候,
面对button1 button2 button3 button4...
你自己都晕了,更别说给别人看了

关于布尔表达式在if语句中的用法,详细的你可以去看下 林锐的<<高质量C++编程指南>>
我简单说下:

不良用法:
if (b == true) { }
if (b == false) { }

正确用法:
if (b) { } // 如果b为真
if (!b) { } //如果b为假
--->  伱 能 領 導 潮 流.  我 可 領 導 全 賕!  <---

TOP

复制内容到剪贴板
代码:
      Computer MyComputer = new Computer();
      listboxInfo.Items.Add("当前操作系统版本:" + MyComputer.Info.OSFullName);
      listboxInfo.Items.Add("当前系统版本号:" + MyComputer.Info.OSVersion);
      listboxInfo.Items.Add("当前登陆用户:" + SystemInformation.UserName);
      listboxInfo.Items.Add("本地计算机名:" + MyComputer.Name);
效果:
--->  伱 能 領 導 潮 流.  我 可 領 導 全 賕!  <---

TOP

东方不败3
可认识我。
很好.

TOP

1楼说的实在
编程这个命名规范
和编程习惯非常重要
^_^    社会需求将决定你的价值    ^_^

TOP

bink
当然认识了 哈哈
你就是认为我这名字不好的

TOP

呵 明年我也要开始学编程 了  看了这受教 了

TOP

引用:
引用第1楼zshoucheng于2007-06-29 12:52发表的 :
只能说----写得烂,很烂,非常烂!
不是我打击你

先说编码习惯
如果你是新手,请注意一下编程习惯:
.......
刚开始我们菜菜就跟拼积木一样 能些出来就感觉到很自豪咯``

很难注意到结构啊``

TOP

记得我没次写 Test.asp 或者 Demo.asp 做测试演示都习惯了把名称定义规范。
变量的命名可是大有讲究。过两天我发个自己的命名习惯出来。每个人都有自己的命名习惯。
如果是团队开发项目就需要调整下自己的命名习惯一达到和团队的融合。比如我现在。哎。。
看着自己写的代码,真想 Ctrl+A 然后Delete 接着 Ctrl+S 。最后关闭。
很好.

TOP

2楼的看来真是新手,连false都写错!
成功的男人白天瞎JB忙,晚上JB瞎忙;失败的男人白天没啥鸟事,晚上鸟没啥事。

TOP

寂寞宝贝 大牛   我是新手嘛 哈哈 没注意 把FLASH给写成false

TOP

都是牛人
我闪~

TOP

    受教额,
       我命名都尽力做到 "见名知意"...         

TOP

发新话题