Come conoscere l'ID della scheda madre?

by 28. dicembre 2008 21.57

Questa funzione consente di conoscere l’identificativo del processore montato sul PC. Per poter eseguire correttamente questa funzione è necessario importare il namespace System.Management

   1:  Imports System.Management
   2:   
   3:  Public Function GetMotherBoardID() As String
   4:     Dim strMotherBoardID As String = String.Empty
   5:     Dim query As New SelectQuery("Win32_BaseBoard")
   6:     Dim search As New ManagementObjectSearcher(query)
   7:   
   8:     For Each info As ManagementObject In search.Get()
   9:        strMotherBoardID = info("SerialNumber").ToString()
  10:     Next
  11:   
  12:     Return strMotherBoardID
  13:  End Function

È possibile modificare questa funzione e trovare altre informazioni sul sistema.

Tags: , , , ,

Come conoscere l'ID del processore?

by 28. dicembre 2008 21.54

Questa funzione consente di conoscere l’identificativo del processore montato sul PC. Per poter eseguire correttamente questa funzione è necessario importare il namespace System.Management

   1:  Imports System.Management
   2:   
   3:  Public Function GetProcessorId() As String
   4:     Dim strProcessorId As String = String.Empty
   5:     Dim query As New SelectQuery("Win32_processor")
   6:     Dim search As New ManagementObjectSearcher(query)
   7:   
   8:     For Each info As ManagementObject In search.Get()
   9:        strProcessorId = info("processorId").ToString()
  10:     Next
  11:   
  12:     Return strProcessorId
  13:  End Function

Questa funzione può essere modificata per conoscere altre informazioni sulla macchina.

Tags: , , , , ,

Copia ricorsiva di File e Cartelle in VB.Net

by 20. dicembre 2008 12.19

Sembra banale, ma a volte la semplice copia dei file e delle sottodirectory contenute in una cartella può mettere in crisi un programmatore, proprio per la sua banalità.
Proprio per evitare questo, posto un esempio di copia ricorsiva.

Private Sub Copia(ByVal PathOrigine As String, _
            ByVal PathDestinazione As String)
    Dim Files() As String

    If PathDestinazione.Chars(PathDestinazione.Length - 1) <>
            Path.DirectorySeparatorChar Then
        PathDestinazione += Path.DirectorySeparatorChar
    End If

    If Not Directory.Exists(PathDestinazione) Then
        Directory.CreateDirectory(PathDestinazione)
    End If

    Files = Directory.GetFileSystemEntries(PathOrigine)

    Dim Elemento As String

    For Each Elemento In Files
        'Sotto cartelle
        If Directory.Exists(Elemento) Then
            Copia(Elemento, PathDestinazione +
                Path.GetFileName(Elemento))
            ' File nella cartella
        Else
            File.Copy(Elemento, PathDestinazione +
                Path.GetFileName(Elemento), True)
        End If
    Next Elemento
End Sub


Tags: , ,

Scompattare con SharpZipLib e VB.net un file zip con sottocartelle

by 20. dicembre 2008 12.16
Routine di scompattazione di un file Zip con l'utilizzo della dll rilasciata da ICSharpCode (IC#Code), open source, che si chiama SharpZipLib (#ZipLib) scaricabile liberamente QUI


Imports ICSharpCode.SharpZipLib.Zip
......
If File.Exists(fileName) Then

    destPath = fileName.Substring(0, fileName.Length - 4) 

    If Not Directory.Exists(destPath) Then
        Directory.CreateDirectory(destPath)
    Else
        For Each s As String In Directory.GetFiles(destPath)
            File.Delete(s)
        Next
    End If

    Dim inStream As New ZipInputStream(File.OpenRead(fileName))
    Dim outStream As FileStream
    Dim entry As ZipEntry
    Dim buff(2047) As Byte
    Dim bytes As Integer

    Do While True
        Try
            entry = inStream.GetNextEntry()
            If entry Is Nothing Then
                Exit Do
            End If

            If entry.Name.Last() = "/" Then
                Directory.CreateDirectory(destPath & "\" & _
                entry.Name.Replace("/""\"))
            Else
                Try
                    outStream = File.Create(destPath & _
                    "\" & entry.Name, 2048)
                    Do While True
                        bytes = inStream.Read(buff, 0, 2048)
                        If bytes = 0 Then
                            Exit Do
                        End If
                        outStream.Write(buff, 0, bytes)
                    Loop
                    outStream.Close()
                Catch
                End Try
            End If
        Catch
 ex As ZipException
            rtn += ex.Message & vbCrLf
        End Try
    Loop

    inStream.Close()
Else
    rtn = "File '" & fileName & "' non trovato."
End If

Tags: ,

Select Distinct su DataSet

by 20. dicembre 2008 12.14

Le funzioni sotto riportate permettono di effettuare da codice una query con "Select Distinct" su un DataSet.

FieldNames è un array di string con in campi su cui fare la select distinct.

 


Public Function SelectDistinct(ByVal SourceTable As DataTable, _
    ByVal ParamArray FieldNames() As StringAs DataTable

    Dim lastValues() As Object
    Dim newTable As DataTable

    If FieldNames Is Nothing OrElse FieldNames.Length = 0 Then
        Throw New ArgumentNullException("FieldNames")
    End If

    lastValues = New Object(FieldNames.Length - 1) {}
    newTable = New DataTable

    For Each field As String In FieldNames
        newTable.Columns.Add(field, SourceTable.Columns(field).DataType)
    Next

    For Each Row As DataRow In SourceTable.Select("",String.Join(", ", FieldNames))
        If Not fieldValuesAreEqual(lastValues, Row, FieldNames)Then
            newTable.Rows.Add(createRowClone(Row, newTable.NewRow(), FieldNames))
            setLastValues(lastValues, Row, FieldNames)
        End If
    Next

    Return newTable
End Function


Private Function fieldValuesAreEqual(ByVal lastValues() As Object, _
    ByVal currentRow As DataRow, ByVal fieldNames() As StringAs Boolean

    Dim areEqual As Boolean = True

    For i As Integer = 0 To fieldNames.Length - 1
        If lastValues(i) Is Nothing OrElse NotlastValues(i).Equals(currentRow(fieldNames(i))) Then
            areEqual = False
            Exit For
        End If
    Next

    Return areEqual
End Function


Private Function createRowClone(ByVal sourceRow As DataRow, _
    ByVal newRow As DataRow, ByVal fieldNames() As StringAsDataRow

    For Each field As String In fieldNames
        newRow(field) = sourceRow(field)
    Next

    Return newRow
End Function


Private Shared Sub setLastValues(ByVal lastValues() As Object, _
    ByVal sourceRow As DataRow, ByVal fieldNames() As String)

    For i As Integer = 0 To fieldNames.Length - 1
        lastValues(i) = sourceRow(fieldNames(i))
    Next
End Sub

Tags: ,

Page List

Calendar

<<  febbraio 2012  >>
lumamegivesado
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar