الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Set/get Pocket Pc Device Name,id

بدأه bnitt في 27 سبتمبر 2009 · 1 رد · 1,382 مشاهدة · في برمجة الأجهزة الكفية والمحمولة بالدوت نيت
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

اقدم لكم هذا الكود لمعرفة اسم الجهاز ورقمة Unique Windows Mobile 5

 Public Shared Function GetDeviceID() As String
		' Initialize the output buffer to the size of a 
		' Win32 DEVICE_ID structure 
		Dim outbuff(19) As Byte
		Dim dwOutBytes As Int32
		Dim done As Boolean = False
		Dim nBuffSize As Int32 = outbuff.Length
		' Set DEVICEID.dwSize to size of buffer.  Some platforms look at
		' this field rather than the nOutBufSize param of KernelIoControl
		' when determining if the buffer is large enough.
		BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)
		dwOutBytes = 0
		' Loop until the device ID is retrieved or an error occurs.
		While Not done
			If KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, _
				0, outbuff, nBuffSize, dwOutBytes) Then
				done = True
			Else
				Dim errnum As Integer = Marshal.GetLastWin32Error()
				Select Case errnum
					Case ERROR_NOT_SUPPORTED
						Throw New NotSupportedException( _
							"IOCTL_HAL_GET_DEVICEID is not supported on this device", _
							New Win32Exception(errnum))
					Case ERROR_INSUFFICIENT_BUFFER
						' The buffer is not big enough for the data.  The
						' required size is in the first 4 bytes of the output 
						' buffer (DEVICE_ID.dwSize).
						nBuffSize = BitConverter.ToInt32(outbuff, 0)
						outbuff = New Byte(nBuffSize) {}

						' Set DEVICEID.dwSize to size of buffer.  Some
						' platforms look at this field rather than the
						' nOutBufSize param of KernelIoControl when
						' determining if the buffer is large enough.
						BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0)

					Case Else
						Throw New Win32Exception(errnum, "Unexpected error")
				End Select
			End If
		End While
		' Copy the elements of the DEVICE_ID structure.
		Dim dwPresetIDOffset As Int32 = BitConverter.ToInt32(outbuff, &H4)
		Dim dwPresetIDSize As Int32 = BitConverter.ToInt32(outbuff, &H8)
		Dim dwPlatformIDOffset As Int32 = BitConverter.ToInt32(outbuff, &HC)
		Dim dwPlatformIDSize As Int32 = BitConverter.ToInt32(outbuff, &H10)
		Dim sb As New StringBuilder
		Dim i As Integer
		For i = dwPresetIDOffset To (dwPresetIDOffset + dwPresetIDSize) - 1
			sb.Append(String.Format("{0:X2}", outbuff(i)))
		Next i
		sb.Append("-")
		For i = dwPlatformIDOffset To (dwPlatformIDOffset + dwPlatformIDSize) - 1
			sb.Append(String.Format("{0:X2}", outbuff(i)))
		Next i
		Return sb.ToString()
	End Function

في الشاشة الرئيسية هيك الكود :-

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
				DeviceID = MySettings.GetDeviceID
		DeviceName = System.Net.Dns.GetHostName()
			End Sub

لكن اريد تعديل اسم الجهاز يعني Set Device Name

تشكروووون

#2

السلام عليكــم ورحمـة الله وبركاتــه ،،

اقتباس
لكن اريد تعديل اسم الجهاز يعني Set Device Name

string NewDeviceName="TheNewName";
using (Microsoft.Win32.RegistryKey Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubkey("Ident", true))
  {
    Regkey.SetValue("Name", NewDeviceName);
  }

مواضيع مشابهة