Accueil > > > API WIN32 FACILE
API WIN32 FACILE
Information sur la source
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
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
Sources de la même categorie
Commentaires et avis
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
|
Derniers Blogs
TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|