Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TuToRiAl] Helpful Newbie Visual Basic Code Snippets[/TuToRiAl]
#1
Hello there, here are little code snippets I compiled up for you guys. They are extremely helpful if you are new to VB and want to know how VB code works, functions and looks like. Enjoy.

Delete a File:
Code:
Dim FileToDelete As String
FileToDelete = "C:\File.exe"
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)


Kill a Process:
Code:
Dim RunningProcess As System.Diagnostics.Process = Process.GetProcessesByName("taskmgr.exe")(0)
RunningProcess.Kill()


Delete a Registry Key:
Code:
My.Computer.Registry.LocalMachine.DeleteSubKey("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SafeBoot")

Rename a File:
Code:
My.Computer.FileSystem.RenameFile ("C:\Program Files\Mozilla Firefox\firefox.exe", "Anything.exe")

Create a Registry Key:
Code:
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
regKey.CreateSubKey("MyApp")
regKey.Close()

Text to Speach:
Code:
Dim sapi
sapi = CreateObject("sapi.spvoice")
sapi.Speak(Textbox1.text)

Getting The Operating system Name:
Code:
Textbox1.text = My.Computer.Info.OSFullName

Gets OS Version & Build Number:
Code:
Textbox2.text = My.Computer.Info.OSVersion

Gets Available Physical Memory:
Code:
Textbox4.text = My.Computer.Info.AvailablePhysicalMemory

Gets Total Physical Memory:
Code:
Textbox3.text = My.Computer.Info.TotalPhysicalMemory

Gets the clipboard text:
Code:
Textbox5.text = My.Computer.Clipboard.GetText

CD-ROM Prank Roflmao (opens and closes):
Code:
Do
Dim oWMP = CreateObject("WMPlayer.OCX.7")
Dim colCDROMs = oWMP.cdromCollection
If colCDROMs.Count = 1 Then
For i = 0 To colCDROMs.Count - 1
colCDROMs.Item(i).Eject()
Next ' cdrom
End If
Loop


RC4 Text Encryption

Code:
Public Shared Function rc4(ByVal message As String, ByVal password As String) As String

        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim cipher As New StringBuilder
        Dim returnCipher As String = String.Empty

        Dim sbox As Integer() = New Integer(256) {}
        Dim key As Integer() = New Integer(256) {}

        Dim intLength As Integer = password.Length

        Dim a As Integer = 0
        While a <= 255

            Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))

            key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
            sbox(a) = a
            System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
        End While

        Dim x As Integer = 0

        Dim b As Integer = 0
        While b <= 255
            x = (x + sbox(b) + key(b)) Mod 256
            Dim tempSwap As Integer = sbox(b)
            sbox(b) = sbox(x)
            sbox(x) = tempSwap
            System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
        End While

        a = 1

        While a <= message.Length

            Dim itmp As Integer = 0

            i = (i + 1) Mod 256
            j = (j + sbox(i)) Mod 256
            itmp = sbox(i)
            sbox(i) = sbox(j)
            sbox(j) = itmp

            Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)

            Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)

            itmp = Asc(ctmp)

            Dim cipherby As Integer = itmp Xor k

            cipher.Append(Chr(cipherby))
            System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
        End While

        returnCipher = cipher.ToString
        cipher.Length = 0

        Return returnCipher

    End Function


Auto Typer

Code:
Public Class Form1

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If CheckBox1.Checked = True Then
            On Error Resume Next
            SendKeys.Send(TextBox1.Text)
            On Error Resume Next
            SendKeys.Send("{Enter}")
        End If
        If CheckBox2.Checked = True Then
            On Error Resume Next
            SendKeys.Send(TextBox2.Text)
            On Error Resume Next
            SendKeys.Send("{Enter}")
        End If
        If CheckBox3.Checked = True Then
            On Error Resume Next
            SendKeys.Send(TextBox3.Text)
            On Error Resume Next
            SendKeys.Send("{Enter}")
        End If
        If CheckBox4.Checked = True Then
            On Error Resume Next
            SendKeys.Send(TextBox4.Text)
            On Error Resume Next
            SendKeys.Send("{Enter}")
        End If
        If CheckBox5.Checked = True Then
            On Error Resume Next
            SendKeys.Send(TextBox5.Text)
            On Error Resume Next
            SendKeys.Send("{Enter}")
        End If
        Timer1.Start()

    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub


Listbox Auto Scroll

Code:
ListBox1.TopIndex = ListBox1.Items.Count - 1



Send Email

Code:
Dim SetUPMAIL As New MailMessage()
Try
SetUPMAIL.From = New MailAddress("YOURGOOGLEEMAIL@googlemail.com")
SetUPMAIL.To.Add("YOUREMAIL@ANYHOST.COM")
SetUPMAIL.Subject = "Subject"
SetUPMAIL.Body = "Body"
Dim SMTP As New SmtpClient("smtp.googlemail.com" or "smtp.gmail.com")
SMTP.Port = 587
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("YOURGOOGLEEMAIL@googlemail.com", "GOOGLEMAILPASSWORD")

SMTP.Send(SetUPMAIL)


Once Again, Enjoy.



Code from: www.pro-coders.com
[Image: t5BWm.png]
Reply
#2
Very helpful snippets here! Thanks for contributing...
[Image: just-cause-2-header.jpg]
Reply
#3
helpfull man ,Thank's for the share Smile.
[Image: skyk.png]
Reply
#4
These are all very helpful, thank you.
Reply
#5
Thanks, buddy. Looks very impressive and useful.
Reply
#6
This looks good I am sure this will help a lot of people! Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How To make an advanced Operating System in Visual Basic 2010 ? Mohamed Samir 9 11,522 01-15-2013, 09:30 PM
Last Post: Resistance
  Get Country Code In 1 Line Of Code. wchar_t 13 4,061 11-28-2012, 06:49 AM
Last Post: Cubs
  [HELP]Tutorial/Learning System[HELP] norBATman 2 1,092 09-08-2012, 10:17 PM
Last Post: AceInfinity
  [TuToRiAl] How to make Offline (No Internet) Captcha (Human Confirmation) [TuToRiAl] Resistance 24 10,958 08-30-2012, 10:14 PM
Last Post: Resistance
  [Visual Basic] FTP Uploader [Tutorial] Coding Support 6 2,738 08-12-2012, 12:36 AM
Last Post: Kenneth

Forum Jump:


Users browsing this thread: 1 Guest(s)