begin process at 2012 02 13 18:46:38
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

API

 > API WIN32 FACILE

API WIN32 FACILE


 Information sur la source

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :API Source .NET ( DotNet ) Classé sous :API, Windows, natif Niveau :Débutant Date de création :13/09/2008 Date de mise à jour :15/09/2008 17:43:49 Vu / téléchargé :7 093 / 523

Auteur : gillardg

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note


 Description

petit exemple d'utilisation des api

j'ai utilisé P/Invoke Interop Assistant pour les quelques fonctions démontrées

Source

  • Imports System.IO
  • Imports Shell32
  • Public Class Form1
  • <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="ShellAboutW")> _
  • Public Shared Function ShellAboutW(ByVal hWnd As System.IntPtr, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal szApp As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal szOtherStuff As String, ByVal hIcon As System.IntPtr) As Integer
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHFormatDrive")> _
  • Public Shared Function SHFormatDrive(ByVal hwnd As System.IntPtr, ByVal drive As UInteger, ByVal fmtID As UInteger, ByVal options As UInteger) As UInteger
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHFindFiles")> _
  • Public Shared Function SHFindFiles(ByVal pidlFolder As String, ByVal pidlSaveFile As UInteger) As Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHGetDiskFreeSpaceExW")> _
  • Public Shared Function SHGetDiskFreeSpaceExW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal pszVolume As String, ByRef pqwFreeCaller As ULong, ByRef pqwTot As ULong, ByRef pqwFree As ULong) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="Beep")> _
  • Public Shared Function Beep(ByVal dwFreq As UInteger, ByVal dwDuration As UInteger) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="IsDebuggerPresent")> _
  • Public Shared Function IsDebuggerPresent() As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="SetComputerNameW")> _
  • Public Shared Function SetComputerNameW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpComputerName As String) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="SetVolumeLabelW")> _
  • Public Shared Function SetVolumeLabelW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpRootPathName As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpVolumeName As String) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="Sleep")> _
  • Public Shared Sub Sleep(ByVal dwMilliseconds As UInteger)
  • End Sub
  • Private Declare Function AnimateWindow Lib "user32" ( _
  • ByVal hWnd As Integer, _
  • ByVal dwTime As Integer, _
  • ByVal dwFlags As Integer) As Integer
  • <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="FlashWindow")> _
  • Public Shared Function FlashWindow(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal bInvert As Boolean) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="FindExecutableW")> _
  • Public Shared Function FindExecutableW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpFile As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpDirectory As String, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal lpResult As String) As System.IntPtr
  • End Function
  • <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHObjectProperties")> _
  • Public Shared Function SHObjectProperties(ByVal hwnd As System.IntPtr, ByVal shopObjectType As UInteger, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal pszObjectName As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal pszPropertyPage As String) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
  • End Function
  • Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  • ' Permet de quitter si un cracker est
  • ' en train de tracer votre programme.
  • If IsDebuggerPresent() <> 0 Then End
  • ' Cet appel de fonction fera s'afficher progressivement la
  • ' fenêtre de son centre vers ses bords
  • AnimateWindow(Me.Handle, 1000, &H10 Or &H20000)
  • End Sub
  • ''' <summary>
  • ''' format a:\
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  • SHFormatDrive(Me.Handle, 0, 0, 0)
  • End Sub
  • ''' <summary>
  • ''' about
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  • ShellAboutW(Me.Handle, Application.ProductName, "ceci est un exemple", 0)
  • End Sub
  • ''' <summary>
  • ''' recherche des fichiers
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  • SHFindFiles(String.Empty, 0)
  • End Sub
  • ''' <summary>
  • ''' espace disque en MB ( ici C:)
  • ''' la fonction renvoit des bytes alors on divise par 1024 et puis encore par 1024
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  • Dim total, free, tot As ULong
  • SHGetDiskFreeSpaceExW("C:\", free, total, tot)
  • MsgBox("total disk space " & (total / 1024) / 1024 & vbCrLf & "free disk space " & (free / 1024) / 1024)
  • End Sub
  • ''' <summary>
  • ''' 'dwFreq [in] The frequency of the sound, in hertz.
  • ''' This parameter must be in the range 37 through 32767 (0x25 through 0x7FFF).
  • ''' dwDuration([in])The duration of the sound, in milliseconds.
  • ''' la fonction sleep "endord" le thread pour la durée
  • ''' en millisecondes qui est passée en parramètres
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  • Beep(50, 500)
  • Sleep(2000)
  • Beep(2000, 500)
  • End Sub
  • ''' <summary>
  • ''' Attention cela change le nom de votre PC
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  • If MsgBox("changer le nom de votre PC sur le réseau ? " & vbCrLf & " actuellement " & My.Computer.Name.ToString(), MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  • SetComputerNameW(InputBox("Nouveau nom de votre PC après redémmarrage ?"))
  • End If
  • End Sub
  • ''' <summary>
  • ''' changer le label d'un disque ( ici A:)
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  • If MsgBox("Changer le label de la disquette se trouvant dans A: ?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  • SetVolumeLabelW("A:\", InputBox("Nouveau Label de la disquette ? "))
  • End If
  • End Sub
  • Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  • For x = 0 To 20
  • Sleep(200)
  • FlashWindow(Me.Handle, True)
  • Application.DoEvents()
  • Next
  • End Sub
  • ''' <summary>
  • ''' dialogue de config du firewall
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
  • Microsoft.VisualBasic.Shell("Rundll32.exe shell32.dll,Control_RunDLL firewall.cpl")
  • 'cela fonctionne avec d'autre parrametre (*.cpl ) à vous d'essayer
  • 'ex : Shell("Rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl") 'sys admin
  • End Sub
  • ''' <summary>
  • ''' trouver le programme associé avec un type de document
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
  • Dim odf As New OpenFileDialog
  • Dim result As String = String.Empty
  • If odf.ShowDialog = Windows.Forms.DialogResult.OK Then
  • FindExecutableW(odf.FileName, String.Empty, result)
  • MsgBox(result)
  • End If
  • End Sub
  • ''' <summary>
  • ''' Zip un répertoire en utilisant shell32.dll
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
  • Dim mesdoc As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\mesdoc.zip"
  • Dim folder As New FolderBrowserDialog
  • If folder.ShowDialog() = Windows.Forms.DialogResult.OK Then
  • CompressFolder(mesdoc, folder.SelectedPath)
  • MsgBox(folder.SelectedPath & vbCrLf & vbCrLf & "compressé dans " & vbCrLf & mesdoc)
  • End If
  • End Sub
  • ''' <summary>
  • ''' fonction qui fait le zip
  • ''' </summary>
  • ''' <param name="CompressedFileName"></param>
  • ''' <param name="FolderToCompress"></param>
  • ''' <remarks></remarks>
  • Sub CompressFolder(ByVal CompressedFileName As String, ByVal FolderToCompress As String)
  • Dim B(21) As Byte
  • B(0) = 80 : B(1) = 75 : B(2) = 5 : B(3) = 6
  • File.WriteAllBytes(CompressedFileName, B) 'Make an empty PKZip file.
  • Dim SH As New Shell
  • Dim SF As Folder = SH.NameSpace(CompressedFileName)
  • Dim DF As Folder = SH.NameSpace(FolderToCompress)
  • SF.CopyHere(DF)
  • End Sub
  • ''' <summary>
  • ''' associer un Passport .net avec votre compte utilisateur
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
  • Microsoft.VisualBasic.Shell("rundll32.exe netplwiz.dll, PassportWizardRunDll")
  • End Sub
  • ''' <summary>
  • ''' affiche les propriétes d'un objet ( imprimante , fichier ,disque )
  • ''' </summary>
  • ''' <param name="sender"></param>
  • ''' <param name="e"></param>
  • ''' <remarks></remarks>
  • Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
  • Dim ret As Int16 = InputBox("entrer un numéro de 1 à 3")
  • Select Case ret
  • Case 1
  • 'changer le nom de l'imprimante si vous voulez
  • SHObjectProperties(0, 1, "Microsoft Office Document Image Writer", 0)
  • Case 2
  • Dim odf As New OpenFileDialog
  • odf.Title = "choisissez un fichier"
  • If odf.ShowDialog = Windows.Forms.DialogResult.OK Then
  • SHObjectProperties(0, 2, odf.FileName, 0)
  • End If
  • Case 3
  • 'changer "c:\" pour un autre disque si vous vouler
  • SHObjectProperties(0, 4, "c:\", 0)
  • End Select
  • End Sub
  • End Class
Imports System.IO
Imports Shell32
Public Class Form1
    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="ShellAboutW")> _
      Public Shared Function ShellAboutW(ByVal hWnd As System.IntPtr, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal szApp As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal szOtherStuff As String, ByVal hIcon As System.IntPtr) As Integer
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHFormatDrive")> _
       Public Shared Function SHFormatDrive(ByVal hwnd As System.IntPtr, ByVal drive As UInteger, ByVal fmtID As UInteger, ByVal options As UInteger) As UInteger
    End Function
    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHFindFiles")> _
          Public Shared Function SHFindFiles(ByVal pidlFolder As String, ByVal pidlSaveFile As UInteger) As Boolean
    End Function
    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHGetDiskFreeSpaceExW")> _
       Public Shared Function SHGetDiskFreeSpaceExW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal pszVolume As String, ByRef pqwFreeCaller As ULong, ByRef pqwTot As ULong, ByRef pqwFree As ULong) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="Beep")> _
         Public Shared Function Beep(ByVal dwFreq As UInteger, ByVal dwDuration As UInteger) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="IsDebuggerPresent")> _
      Public Shared Function IsDebuggerPresent() As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="SetComputerNameW")> _
        Public Shared Function SetComputerNameW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpComputerName As String) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function


    <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="SetVolumeLabelW")> _
     Public Shared Function SetVolumeLabelW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpRootPathName As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpVolumeName As String) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="Sleep")> _
          Public Shared Sub Sleep(ByVal dwMilliseconds As UInteger)
    End Sub

    Private Declare Function AnimateWindow Lib "user32" ( _
                       ByVal hWnd As Integer, _
                       ByVal dwTime As Integer, _
                       ByVal dwFlags As Integer) As Integer

    <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="FlashWindow")> _
           Public Shared Function FlashWindow(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal bInvert As Boolean) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function

    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="FindExecutableW")> _
             Public Shared Function FindExecutableW(<System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpFile As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPTStr)> ByVal lpDirectory As String, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal lpResult As String) As System.IntPtr
    End Function
    <System.Runtime.InteropServices.DllImportAttribute("shell32.dll", EntryPoint:="SHObjectProperties")> _
        Public Shared Function SHObjectProperties(ByVal hwnd As System.IntPtr, ByVal shopObjectType As UInteger, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal pszObjectName As String, <System.Runtime.InteropServices.InAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal pszPropertyPage As String) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '  Permet de quitter si un cracker est
        ' en train de tracer votre programme.
        If IsDebuggerPresent() <> 0 Then End
        ' Cet appel de fonction fera s'afficher progressivement la
        ' fenêtre de son centre vers ses bords
        AnimateWindow(Me.Handle, 1000, &H10 Or &H20000)
    End Sub
    ''' <summary>
    ''' format a:\
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SHFormatDrive(Me.Handle, 0, 0, 0)
    End Sub
    ''' <summary>
    ''' about
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ShellAboutW(Me.Handle, Application.ProductName, "ceci est un exemple", 0)
    End Sub
    ''' <summary>
    ''' recherche des fichiers
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        SHFindFiles(String.Empty, 0)
    End Sub
    ''' <summary>
    ''' espace disque en MB ( ici C:)
    ''' la fonction renvoit des bytes alors on divise par 1024 et puis encore par 1024
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim total, free, tot As ULong
        SHGetDiskFreeSpaceExW("C:\", free, total, tot)
        MsgBox("total disk space " & (total / 1024) / 1024 & vbCrLf & "free disk space " & (free / 1024) / 1024)

    End Sub
    ''' <summary>
    '''  'dwFreq [in] The frequency of the sound, in hertz.
    ''' This parameter must be in the range 37 through 32767 (0x25 through 0x7FFF).
    '''       dwDuration([in])The duration of the sound, in milliseconds. 
    ''' la fonction sleep "endord" le thread pour la durée
    '''  en millisecondes qui est passée en parramètres
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        Beep(50, 500)
        Sleep(2000)
        Beep(2000, 500)
    End Sub
    ''' <summary>
    ''' Attention cela change le nom de votre PC
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If MsgBox("changer le nom de votre PC sur le réseau ? " & vbCrLf & " actuellement " & My.Computer.Name.ToString(), MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            SetComputerNameW(InputBox("Nouveau nom de votre PC après redémmarrage ?"))

        End If
    End Sub
    ''' <summary>
    ''' changer le label d'un disque ( ici A:)
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If MsgBox("Changer le label de la disquette se trouvant dans A: ?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            SetVolumeLabelW("A:\", InputBox("Nouveau Label de la disquette ? "))
        End If
    End Sub


    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        For x = 0 To 20
            Sleep(200)
            FlashWindow(Me.Handle, True)
            Application.DoEvents()
        Next
    End Sub
    ''' <summary>
    ''' dialogue de config du firewall
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Microsoft.VisualBasic.Shell("Rundll32.exe shell32.dll,Control_RunDLL firewall.cpl")
        'cela fonctionne avec d'autre parrametre (*.cpl ) à vous d'essayer 
        'ex :  Shell("Rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl") 'sys admin

    End Sub
    ''' <summary>
    ''' trouver le programme associé avec un type de document
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Dim odf As New OpenFileDialog
        Dim result As String = String.Empty
        If odf.ShowDialog = Windows.Forms.DialogResult.OK Then
            FindExecutableW(odf.FileName, String.Empty, result)
            MsgBox(result)
        End If
    End Sub
    ''' <summary>
    ''' Zip un répertoire en utilisant shell32.dll
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Dim mesdoc As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\mesdoc.zip"
        Dim folder As New FolderBrowserDialog
        If folder.ShowDialog() = Windows.Forms.DialogResult.OK Then
            CompressFolder(mesdoc, folder.SelectedPath)
            MsgBox(folder.SelectedPath & vbCrLf & vbCrLf & "compressé dans " & vbCrLf & mesdoc)
        End If
    End Sub
    ''' <summary>
    ''' fonction qui fait le zip
    ''' </summary>
    ''' <param name="CompressedFileName"></param>
    ''' <param name="FolderToCompress"></param>
    ''' <remarks></remarks>
    Sub CompressFolder(ByVal CompressedFileName As String, ByVal FolderToCompress As String)

        Dim B(21) As Byte

        B(0) = 80 : B(1) = 75 : B(2) = 5 : B(3) = 6

        File.WriteAllBytes(CompressedFileName, B) 'Make an empty PKZip file.

        Dim SH As New Shell

        Dim SF As Folder = SH.NameSpace(CompressedFileName)

        Dim DF As Folder = SH.NameSpace(FolderToCompress)

        SF.CopyHere(DF)

    End Sub

    ''' <summary>
    ''' associer un Passport .net avec votre compte utilisateur
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Microsoft.VisualBasic.Shell("rundll32.exe netplwiz.dll, PassportWizardRunDll")

    End Sub
    ''' <summary>
    ''' affiche les propriétes d'un objet ( imprimante , fichier ,disque )
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        Dim ret As Int16 = InputBox("entrer un numéro de 1 à 3")
        Select Case ret
            Case 1
                'changer le nom de l'imprimante si vous voulez
                SHObjectProperties(0, 1, "Microsoft Office Document Image Writer", 0)
            Case 2
                Dim odf As New OpenFileDialog
                odf.Title = "choisissez un fichier"
                If odf.ShowDialog = Windows.Forms.DialogResult.OK Then
                    SHObjectProperties(0, 2, odf.FileName, 0)
                End If
            Case 3
                'changer "c:\" pour un autre disque si vous vouler
                SHObjectProperties(0, 4, "c:\", 0)


        End Select
    End Sub
End Class



 Conclusion

P/Invoke Interop Assistant est un outil formidable et très utile pour vb200*

disponible gratuitement ici

http://download.microsoft.com/download/f/2/7/f27 9e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008 _01.exe

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

15 septembre 2008 17:43:50 :
plusieurs fonctions ajoutées ZipFolder , associer un Passport .net avec votre compte utilisateur , affiche les propriétes d'un objet ( imprimante , fichier ,disque )

 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) EDITEUR DE TEXTE WINFORM AVEC CORRECTEUR ORTHOGRAPHIQUE WPF
Source .NET (Dotnet) LABEL ET IMAGE DANS TEXTBOX
Source avec Zip Source avec une capture Source .NET (Dotnet) VBZIP GESTION D'ARCHIVES AU FORMAT ZIP UTILISANT IONIC.UTIL...
Source avec Zip Source avec une capture Source .NET (Dotnet) VBZIP ZIP ET UNZIP EN VB.NET
Source avec Zip Source .NET (Dotnet) BACKUP SIMPLE EN 100 LIGNES

 Sources de la même categorie

Source avec Zip Source .NET (Dotnet) .NET DEPENDENCY VIEWER : ARBRE DES DÉPENDANCES D'UN ASSEMBLY... par ShareVB
Source avec Zip Source .NET (Dotnet) UTILITAIRE SKYDRIVE par MasterShadows
Source avec Zip ROTATION RAPIDE D'IMAGE par trex70
Source avec Zip Source avec une capture ENUMERATION DES PORTS TCP ET IDENTIFCATION DU PROCESS (PID) ... par Renfield
Source avec Zip Source avec une capture MOUSE SPEED AND WEIGHT : RETOUR DE FORCE VIRTUEL ! par ScSami

 Sources en rapport avec celle ci

Source .NET (Dotnet) MODIFICATION DATE DE WINDOWS EN VB.NET ET VBA par us_30
Source avec Zip COMMUNICATION MODBUS MASTER par sergelapointe
Source avec Zip Source avec une capture AFFICHEUR TYPE DIGITAL AVEC AVEC L'API SETBITMAPBITS par oeildedinde
Source avec Zip CONVERSION D'1 CHAINE DE CARACTÈRE AU FORMAT WINDOWS VERS LE... par Willi
Source avec Zip INFORMATIONS DIVERSES SUR WINDOWS PAR API par Nico

Commentaires et avis

Commentaire de boutemine le 14/09/2008 02:23:14 9/10

Bien commenté
Voici un site sur le meme sujet
PINVOKE Wiki
www.pinvoke.net

Commentaire de gillardg le 14/09/2008 02:29:45

merci je vais aller voir cela de suite

Commentaire de blootix le 15/09/2008 10:04:31

C un bon code mais je vais juste dire un truc c que pour les API il y a un outil 5 étoils qui permet d'offrir des exples d'utilisation des API et qui offre tous les API windows :-) c le API @ la loupe viewer 2.1
tapez ça sur google et télécharger cet outil, c hyper bien

Commentaire de gillardg le 15/09/2008 11:22:33

oui oui bien sur mais avec
P/Invoke Interop Assistant il suffit de copier coller la déclaration d'api de la msdn (en c)
et tu as directement la déclaration correcte pour vb.net
Pour TOUS les API, pas seulement pour ceux qui sont soit disant compatible vb

Commentaire de mehdikobra le 15/09/2008 17:37:02

cé coool !! merci

Commentaire de yassirguitare le 29/09/2008 07:08:32

MERCI beaucoup
il est temps d'interagire directement avec le coeur du system

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Api windows via visual basic 4.0 pro [ par Ouibounet ] Je cherche de la doc sur les api de windows pouvant etre intégrées dans le vb. si quelqu'un connait un site sur le quel je pourrais télécharger des do à part les API windows, quelles dll [ par dtune ] bonjour toi,j'ai à peu près compris l'utilisation des API classique win32api mais par contre, on n'y trouve pas toutpar exemple, j'ai essayé de faire API pour la gestion des comptes windows [ par chop ] SalutQelles sont les API que l'ont put utiliser pour récupérer les login, password etc. d'une personne loguée ??Et comment les utiliser !!Merci d'avan bouton parcourir et api windows [ par ravachol ] salut a touson a du vous poser la question cent fois mais je trouve pas en faisant recherche !vola je veux creer un bouton parcourirj'ai trouver plusi convertion path DOS -> path Windows [ par Repie ] l'api getfullpathname ne fonctionne pas chez moi, y a pas une autre api ou un autre moyen pou trouver le nom long? (chui sous win98) API Windows [ par rutabaga ] Bonjour,Exite-t-il une API ou au moins une solution pour détecter si un fichier partagé en réseau (un fichier excel par ex) est ouvert par un autre ut Quelle API Windows me faudrait-il pour ....? [ par Fr@nck ] Qlq'1 saurait il m'indiquer quelle API est appelée par Windows pour lancer certains programmes tels que IE.exe ? les API windows [ par Mskine ] Où je peux trouver des informations,definitions, conseils, des fonctions APIMerci d'avance les API windows [ par benzm ] documentation ou adresses des site qui traite ou donnent des explication sur les API windows (le role de chaque fonction)merci pour tous


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,279 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales