最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#利用win32 Api 修改本地系統(tǒng)時間、獲取硬盤序列號

 更新時間:2015年03月11日 16:08:23   投稿:hebedich  
這篇文章主要介紹了C#利用win32 Api 修改本地系統(tǒng)時間、獲取硬盤序列號的方法及代碼分享,需要的朋友可以參考下

C#利用win32 Api 修改本地系統(tǒng)時間、獲取硬盤序列號,可以用于軟件注冊機制的編寫!

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Fengyun
{
    public class Win32
    {
        #region 修改本地系統(tǒng)時間
        [DllImport("Kernel32.dll")]
        private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
        [DllImport("Kernel32.dll")]
        private extern static uint SetLocalTime(ref SYSTEMTIME lpSystemTime);
        [StructLayout(LayoutKind.Sequential)]
        private struct SYSTEMTIME
        {
            public ushort wYear;
            public ushort wMonth;
            public ushort wDayOfWeek;
            public ushort wDay;
            public ushort wHour;
            public ushort wMinute;
            public ushort wSecond;
            public ushort wMilliseconds;
        }
        /// <summary>
        /// 將本地時間與sqlserver服務器時間同步
        /// </summary>
        /// <param name="SqlServerTime">時間</param>
        public static void SetTime(DateTime SqlServerTime)
        {
            SYSTEMTIME st = new SYSTEMTIME();
            st.wYear = Convert.ToUInt16(SqlServerTime.Year);
            st.wMonth = Convert.ToUInt16(SqlServerTime.Month);
            st.wDay = Convert.ToUInt16(SqlServerTime.Day);
            st.wHour = Convert.ToUInt16(SqlServerTime.Hour);
            st.wMilliseconds = Convert.ToUInt16(SqlServerTime.Millisecond);
            st.wMinute = Convert.ToUInt16(SqlServerTime.Minute);
            st.wSecond = Convert.ToUInt16(SqlServerTime.Second);
            SetLocalTime(ref st);
        }
        #endregion
        #region 獲取硬盤序列號
        [DllImport("kernel32.dll")]
        private static extern int GetVolumeInformation(
        string lpRootPathName,
        string lpVolumeNameBuffer,
        int nVolumeNameSize,
        ref int lpVolumeSerialNumber,
        int lpMaximumComponentLength,
        int lpFileSystemFlags,
        string lpFileSystemNameBuffer,
        int nFileSystemNameSize
        );
        /// <summary>
        /// 獲取硬盤序列號
        /// </summary>
        /// <param name="drvID">硬盤盤符[c|d|e|....]</param>
        /// <returns></returns>
        public static string GetDiskVolume(string drvID)
        {
            const int MAX_FILENAME_LEN = 256;
            int retVal = 0;
            int lpMaximumComponentLength = 0;
            int lpFileSystemFlags = 0;
            string lpVolumeNameBuffer = null;
            string lpFileSystemNameBuffer = null;
            int i = GetVolumeInformation(
            drvID + @":\",
            lpVolumeNameBuffer,
            MAX_FILENAME_LEN,
            ref retVal,
            lpMaximumComponentLength,
            lpFileSystemFlags,
            lpFileSystemNameBuffer,
            MAX_FILENAME_LEN
            );
            return retVal.ToString("x");
        }
        #endregion
    }
}

以上就是本文所分享的代碼的全部內(nèi)容了,希望對大家學習C#能有所幫助。

相關文章

  • C#中遍歷DataSet數(shù)據(jù)集對象實例

    C#中遍歷DataSet數(shù)據(jù)集對象實例

    這篇文章主要介紹了C#中遍歷DataSet數(shù)據(jù)集對象實例,經(jīng)常忘記如何操作DataSet,這里記下來并分享,讓需要的朋友可以參考下
    2014-08-08
  • C#中struct和class的區(qū)別詳解

    C#中struct和class的區(qū)別詳解

    這篇文章主要介紹了C#中struct和class的區(qū)別,對C#初學者來說是需要牢固掌握的,需要的朋友可以參考下
    2014-08-08
  • 淺談C#多線程簡單例子講解

    淺談C#多線程簡單例子講解

    本篇文章主要介紹了C#多線程簡單例子,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • C#實現(xiàn)程序開機啟動的方法

    C#實現(xiàn)程序開機啟動的方法

    這篇文章主要介紹了C#實現(xiàn)程序開機啟動的方法,涉及C#針對應用程序及注冊表的相關操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-06-06
  • C#中的Action、Func和Predicate如何使用

    C#中的Action、Func和Predicate如何使用

    這篇文章主要給大家介紹了關于C#中Action、Func和Predicate如何使用的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • C#實現(xiàn)繪制面形圖表的方法詳解

    C#實現(xiàn)繪制面形圖表的方法詳解

    這篇文章主要介紹了C#實現(xiàn)繪制面形圖表的方法,對于C#初學者很好的掌握C#圖形繪制有一定的借鑒價值,需要的朋友可以參考下
    2014-07-07
  • c#  Linq distinct不會調(diào)用Equals方法詳解

    c# Linq distinct不會調(diào)用Equals方法詳解

    這篇文章主要介紹了c# Linq distinct不會調(diào)用Equals方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • 比較有效的使用C#讀取文件的代碼

    比較有效的使用C#讀取文件的代碼

    比較有效的使用C#讀取文件的代碼...
    2007-08-08
  • 3種C# 加載Word的方法

    3種C# 加載Word的方法

    本次經(jīng)驗內(nèi)容分享通過C#程序來加載Word文檔的3種不同方法。分別是:加載本地Word文檔、以只讀模式加載Word文檔、從流加載Word 想具體了解的小伙伴請參考下文
    2021-09-09
  • C#網(wǎng)絡爬蟲代碼分享 C#簡單的爬取工具

    C#網(wǎng)絡爬蟲代碼分享 C#簡單的爬取工具

    這篇文章主要為大家詳細介紹了C#網(wǎng)絡爬蟲代碼,教大家如何制作了簡單的爬取工具,感興趣的小伙伴們可以參考一下
    2016-07-07

最新評論

余庆县| 白银市| 乌拉特前旗| 出国| 龙门县| 专栏| 溧阳市| 仙桃市| 墨脱县| 银川市| 奎屯市| 银川市| 大悟县| 枝江市| 仙游县| 深州市| 基隆市| 廉江市| 百色市| 夏邑县| 南宫市| 桐城市| 额尔古纳市| 栾川县| 尤溪县| 安溪县| 淳化县| 景泰县| 延庆县| 兴山县| 同江市| 阿荣旗| 多伦县| 惠东县| 朝阳区| 嘉义市| 麻江县| 寻乌县| 大同市| 普定县| 福海县|