Snippets Part 3
I will Be adding more as I write them
Empty Recycling Bin
Declarations And Variables
[php]
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hWnd As Int32, ByVal pszRootPath As String, ByVal dwFlags As Int32) As Int32
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Int32
Empty Recycling Bin Sub
[php]
Private Sub takeoutthetrash()
SHEmptyRecycleBin(Me.Handle.ToInt32, vbNullString, SHERB_NOCONFIRMATION + SHERB_NOSOUND)
SHUpdateRecycleBinIcon()
End Sub
[/php]
Code to call the empty recycling bin sub
[php]
takeoutthetrash()
[/php]
Add a Windows User
Add 3 TextBox's
Add 1 Button
TextBox1 will be for the new Username
Textbox2 will be the password field
Textbox3 will be the verify password field
Button_Click Event for button
[php]
Dim username As String = TextBox1.Text
Dim password As String = TextBox2.Text
'Match the passwords, if they match, then add user
If TextBox2.Text = TextBox3.Text Then
Shell("net user " & username & " " & password & " /add")
MessageBox.Show("Windows User Created)
Else
MessageBox.Show("Passwords are different")
End If
[/php]
[php]
Public Class HardDrive
Private dsk_model As String
Private dsk_type As String
Private dsk_serialNo As String
Public Property Model() As String
Get
Return dsk_model
End Get
Set(ByVal value As String)
dsk_model = value
End Set
End Property
Public Property Type() As String
Get
Return dsk_type
End Get
Set(ByVal value As String)
dsk_type = value
End Set
End Property
Public Property serialNo() As String
Get
Return dsk_serialNo
End Get
Set(ByVal value As String)
dsk_serialNo = value
End Set
End Property
End Class
[/php]
Now Add a textbox to your form, set it to multiline=true
View Code
In the namespace
[php]
Imports System
Imports System.Collections
Imports System.Management
[/php]
Variables and Declarations
'Dim appname as system.STATthreadattribute()
Dim WindowsApplication1 As System.STAThreadAttribute()
In Form1 Load add
[php]
Dim SerialHD As New ArrayList()
Dim Obsearch As New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
Dim HDinfo As New ManagementObject()
For Each HDinfo In Obsearch.Get
Dim hd As New Class1.HardDrive()
hd.Model = HDinfo("Model").ToString()
hd.Type = HDinfo("InterfaceType").ToString()
SerialHD.Add(hd)
Next
Dim searcher1 As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
Dim i As Integer = 0
For Each HDinfo In searcher1.Get()
Dim hd As Class1.HardDrive
hd = SerialHD(i)
If HDinfo("SerialNumber") = "" Then
hd.serialNo = "None"
Else
hd.serialNo = HDinfo("SerialNumber").ToString()
i += 1
End If
Next
Dim hd1 As Class1.HardDrive
Dim ii As Integer = 0
For Each hd1 In SerialHD
ii += 1
TextBox1.Text = TextBox1.Text + "Serial No: " + hd1.serialNo + Chr(13) + Chr(10) + Chr(13) + Chr(10)
Next
[/php]
More coming soon, Check Back
Great tut/snip!
Alot of new thing I can learn, thanks next
error for ManagementObjectSearcher and ManagementObject.