⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmabout.cs

📁 OPC-Client sdk for vb/vb.net/c#
💻 CS
字号:
using System.Runtime.InteropServices;
using System.Windows.Forms;
internal partial class frmAbout : System.Windows.Forms.Form
{

	// ×¢²á¼ü°²È«Ñ¡Ïî...
	const int KEY_ALL_ACCESS = 131135;


	// ×¢²á¼ü¸ùÀàÐÍ...
	const int HKEY_LOCAL_MACHINE = -2147483646;
	const short ERROR_SUCCESS = 0;
		// Unicode ¿Õ½áβ×Ö·û´®
	const short REG_SZ = 1;
		// 32λÊý
	const short REG_DWORD = 4;


	const string gREGKEYSYSINFOLOC = "SOFTWARE\\Microsoft\\Shared Tools Location";
	const string gREGVALSYSINFOLOC = "MSINFO";
	const string gREGKEYSYSINFO = "SOFTWARE\\Microsoft\\Shared Tools\\MSINFO";
	const string gREGVALSYSINFO = "PATH";
	[DllImport("advapi32", EntryPoint = "RegOpenKeyExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
	private static extern int RegOpenKeyEx(int hKey, string lpSubKey, int ulOptions, int samDesired, ref int phkResult);
	[DllImport("advapi32", EntryPoint = "RegQueryValueExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
	private static extern int RegQueryValueEx(int hKey, string lpValueName, int lpReserved, ref int lpType, string lpData, ref int lpcbData);
	[DllImport("advapi32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
	private static extern int RegCloseKey(int hKey);



	private void frmAbout_Load(object eventSender, System.EventArgs eventArgs)
	{
        //lblVersion.Text = "Version " + Application.Info.Version.Major + "." + My.Application.Info.Version.Minor + "." + My.Application.Info.Version.Revision;
		//    lblTitle.Caption = App.Title
	}



	private void cmdSysInfo_Click(object eventSender, System.EventArgs eventArgs)
	{
		StartSysInfo();
	}


	private void cmdOK_Click(object eventSender, System.EventArgs eventArgs)
	{
		this.Close();
	}
    [DllImport("shell32.dll",   EntryPoint="ShellExecute")]   
    public   static   extern   int   ShellExecute   (int   hwnd,string   lpOperation,string   lpFile,string   lpParameters,string   lpDirectory,int   nShowCmd);   
    

	public void StartSysInfo()
	{
		 // ERROR: Not supported in C#: OnErrorStatement



		int rc;
		string SysInfoPath;

		SysInfoPath = "";
		// ´Ó×¢²á±í»ñµÃϵͳÐÅÏ¢³ÌÐò·¾¶\Ãû³Æ...
        if (GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFO, gREGVALSYSINFO, SysInfoPath))
        {
        }
		// ½ö´Ó×¢²á±í»ñµÃϵͳÐÅÏ¢³ÌÐò·¾¶...
         else if (GetKeyValue(HKEY_LOCAL_MACHINE, gREGKEYSYSINFOLOC, gREGVALSYSINFOLOC, SysInfoPath)) {
            // ÑéÖ¤ÒÑÖªµÄ 32 λÎļþ°æ±¾µÄ´æÔÚ
            //UPGRADE_WARNING: Dir ÓÐÐÂÐÐΪ¡£ µ¥»÷ÒÔ»ñµÃ¸ü¶àÐÅÏ¢:¡°ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"¡±
           if ((System.IO.File.Exists(SysInfoPath + "\\MSINFO32.EXE")))
            {
                SysInfoPath = SysInfoPath + "\\MSINFO32.EXE";
            }


            // ´íÎó - ÎļþÕÒ²»µ½...
            else
            {
                goto SysInfoErr;
            }
        }
		 //´íÎó - ×¢²á±íÏîÕÒ²»µ½...
        else
        {
            goto SysInfoErr;
        }
        ShellExecute(0,"open",SysInfoPath,null,Application.StartupPath,1);   
        SysInfoErr:
		return;
        //MessageBox.Show("´ËʱϵͳÐÅÏ¢²»¿ÉÓÃ", MsgBoxStyle.OKOnly);
	}


	public bool GetKeyValue( int KeyRoot,  string KeyName,  string SubKeyRef,  string KeyVal)
	{
		bool functionReturnValue = false;
		int I;
		// Ñ­»·¼ÇÊýÆ÷
		int rc;
		// ·µ»Ø´úÂë
		int hKey=0;
		// ´ò¿ªµÄ×¢²á±í¼ü¾ä±ú
		//Dim hDepth As Integer '
		int KeyValType=0;
		// ×¢²á±í¼üÊý¾ÝÀàÐÍ
		string tmpVal="";
		// ÁÙʱ´æ´¢Ò»¸ö×¢²á±í¼üÖµ
		int KeyValSize=0;
		// ×¢²á±í¼ü±äÁ¿´óС
		//------------------------------------------------------------
		// ÔÚ¼ü¸ù{HKEY_LOCAL_MACHINE...}֮ϴò¿ª×¢²á¼ü
		//------------------------------------------------------------
		rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, ref hKey);
		// ´ò¿ª×¢²á±í¼ü


		if ((rc != ERROR_SUCCESS)) goto GetKeyError; 
		// ´íÎó´¦Àí...


		tmpVal = new string('\0', 1024);
		// ·ÖÅä±äÁ¿¿Õ¼ä
		KeyValSize = 1024;
		// ±ê¼Ç±äÁ¿´óС


		//------------------------------------------------------------
		// ¼ìË÷×¢²á±í¼üÖµ...
		//------------------------------------------------------------
		rc = RegQueryValueEx(hKey, SubKeyRef, 0, ref KeyValType, tmpVal,ref KeyValSize);
		// »ñµÃ/´´½¨¼üÖµ


		if ((rc != ERROR_SUCCESS)) goto GetKeyError; 
		// ´íÎó´¦Àí


		tmpVal = tmpVal.PadLeft(tmpVal.Length -1);


		//------------------------------------------------------------
		// ¾ö¶¨×ª»»µÄ¼üÖµÀàÐÍ...
		//------------------------------------------------------------
		switch (KeyValType) {
			// ËÑË÷Êý¾ÝÀàÐÍ...
			case REG_SZ:
				// ×Ö·û´®×¢²á±í¼üÊý¾ÝÀàÐÍ
				KeyVal = tmpVal;
				// ¸´ÖÆ×Ö·û´®Öµ
				break;
			case REG_DWORD:
				// Ë«¾«¶È×¢²á±í¼üÊý¾ÝÀàÐÍ
				for (I = tmpVal.Length ; I >= 1; I += -1) {
					// ת»»Ã¿Ò»Ò³
                    //KeyVal = KeyVal + Conversion.Hex(Strings.Asc(Strings.Mid(tmpVal, I, 1)));
					// Ò»¸ö×Ö·ûÒ»¸ö×Ö·ûµØÉú³ÉÖµ
				}

				KeyVal = "&h" + KeyVal;
				// ת»»Ë«¾«¶ÈΪ×Ö·û´®
				break;
		}


		functionReturnValue = true;
		// ·µ»Ø³É¹¦
		rc = RegCloseKey(hKey);
		// ¹Ø±Õ×¢²á±í¼ü
		return true ; // TODO: might not be correct. Was : Exit Function
		GetKeyError:
		// Í˳ö


		// Cleanup After An Error Has Occured...
		KeyVal = "";
		// Éè·µ»ØÖµÎª¿Õ×Ö·û´®
		functionReturnValue = false;
		// ·µ»ØÊ§°Ü
		rc = RegCloseKey(hKey);
		return functionReturnValue;
		// ¹Ø±Õ×¢²á±í¼ü
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -