Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
NUmero seriale HD
venerdì 16 settembre 2005 - 16.35
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
deejay
Profilo
| Newbie
10
messaggi | Data Invio:
ven 16 set 2005 - 16:35
Buon giorno,
sono da poco passato a VB.NET proveniente da VB 6.
Ho la necessita' di avere una caratteristica univoca del computer su cui sta' girando il mio programma, in VB6 avevo trovato la possibilita' di sfruttare la funzione GetVolumeInformation che tra le altre cose mi permetteva di recuperare il numero seriale univoco dell'HD del computer.
Ho provato a riportare il programma in VB.NET ma sembra non funzionare, sicuramente c'e' una Classe .NET che mi permette di fare cio', qualcuno ne conosce il nome e l'utilizzo?
Sono graditi anche suggerimenti su metodi alternativi su come reperire informazioni univoche del PC (Seriale del microprocessore, ecc.....)
Grazie
Nicola
Cteniza
Profilo
| Guru
1.509
messaggi | Data Invio:
ven 16 set 2005 - 17:17
'
' Created by SharpDevelop.
' User: Luciano
' Date: 16/09/2005
' Time: 16.56
'
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System
Module Main
Sub Main()
Dim wx As New win32wrapper
For Each s As String In wx.GetInformations("C:\")
Console.WriteLine(s)
Next
End Sub
End Module
'file --->> win32wrapper.vb
Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Public NotInheritable Class Win32Wrapper
Public const DRIVE_UNKNOWN = &H0
Public const DRIVE_NO_ROOT_DIR = &H1
Public const DRIVE_REMOVABLE = &H2
Public const DRIVE_FIXED = &H3
Public const DRIVE_REMOTE = &H4
Public const DRIVE_CDROM = &H5
Public const DRIVE_RAMDISK = &H6
<DllImport("kernel32.dll")> _
Public Shared Function GetDriveType(ByVal lpRootPathName As String) As System.UInt32
End Function
<DllImport("kernel32.dll")> _
Private Shared Function GetVolumeInformation(ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As StringBuilder, ByVal nVolumeNameSize As Integer, ByRef lpVolumeSerialNumber As Integer, ByRef lpMaximumComponentLength As Integer, ByRef lpFileSystemFlags As Integer, ByVal lpFileSystemNameBuffer As StringBuilder, ByVal nFileSystemNameSize As Integer) As Boolean
End Function
Public Shared Function GetVolumeName(ByVal strRootPath As String) As String
Dim sbVolumeName As StringBuilder = New StringBuilder(256)
Dim sbFileSystemName As StringBuilder = New StringBuilder(256)
Dim nVolSerial As Integer = 0
Dim nMaxCompLength As Integer = 0
Dim nFSFlags As Integer = 0
Dim bResult As Boolean = GetVolumeInformation(strRootPath, sbVolumeName, 256, nVolSerial, nMaxCompLength, nFSFlags, sbFileSystemName, 256)
If bResult Then
Return sbVolumeName.ToString
Else
Return ""
End If
End Function
Public Shared Function GetInformations(ByVal strRootPath As String) As String()
Dim sbVolumeName As StringBuilder = New StringBuilder(256)
Dim sbFileSystemName As StringBuilder = New StringBuilder(256)
Dim nVolSerial As Integer = 0
Dim nMaxCompLength As Integer = 0
Dim nFSFlags As Integer = 0
Dim result As String() = {"", "", "", "", ""}
Dim bResult As Boolean = GetVolumeInformation(strRootPath, sbVolumeName, 256, nVolSerial, nMaxCompLength, nFSFlags, sbFileSystemName, 256)
If bResult Then
result(0) = sbVolumeName.ToString
result(1) = sbFileSystemName.ToString
result(2) = nVolSerial.ToString
result(3) = nMaxCompLength.ToString
result(4) = nFSFlags.ToString
End If
Return result
End Function
End Class
deejay
Profilo
| Newbie
10
messaggi | Data Invio:
lun 19 set 2005 - 11:22
Grazie
trinity
Profilo
| Guru
3.465
messaggi | Data Invio:
gio 22 set 2005 - 11:52
se ti può servire ti posto un esempio in vb net per individuare il seriale del disco fisso del computer:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Label1.Text =GetSerialNumber("C:\")
End Sub
Public Function GetSerialNumber(ByRef strDrive As String) As Integer
Dim SerialNum As Integer
Dim Res As Integer
Dim Temp1 As String
Dim Temp2 As String
Temp1 = New String(Chr(0), 255)
Temp2 = New String(Chr(0), 255)
' Se vi sono errori Res=0, altrimenti, se tutto e' andato ok, Res=1
Res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
GetSerialNumber = SerialNum
End Function
Ciao
Cirillo Fabio
www.wondernet.biz
fabio@wondernet.biz
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !