VB .net - auto-mate/CheatSheetWiki GitHub Wiki
- Add to Clipboard
- Command Line Args
- Get Data Directly From Web Page Via Proxy
- Loop through Characters of a string
- Loop While Error
- Move and Click Mouse
- Read and Write From Console
- Read Stream
- Sleep
- Write bulk text to file
- Write lines to file
To Add Hex(crypt).ToString
Read Stream
Sub main()
Dim inReader As IO.StreamReader, myStr As String
inReader = FileIO.FileSystem.OpenTextFileReader("C:\temp\temp.txt")
Do While inReader.EndOfStream = False
myStr = inReader.ReadLine()
Console.Write(myStr)
Loop
inReader.Close()
End Sub
Write lines to file
Dim FO As System.IO.StreamWriter
FO = FileIO.FileSystem.OpenTextFileWriter(path, False) 'False = Overwrite | True = Append
FO.WriteLine("SomeText")
FO.Close()
Write bulk text to file
FileIO.FileSystem.WriteAllText(outputDir & "\" & outFileNm, StringToWriteToFile, False)
Loop While Error
Do
Err.Clear()
A Statement that may raise an error until a certain time
Loop While Err.Number <> 0
Command Line Args
argcount = My.Application.CommandLineArgs.Count
someVar = My.Application.CommandLineArgs(0)
Add to Clipboard
My.Computer.Clipboard.SetText(MyString)
Sleep
System.Threading.Thread.Sleep(60000) 'Wait 60secs
Read and Write From Console
Console.WriteLine("Enter Data")
x = Console.ReadLine()
Loop through Characters of a string
Dim ch as Char, demString as String
demString="Hello"
For Each ch In demString
.....
Next
Get Data Directly From Web Page Via Proxy
Imports System
Imports System.IO.File
Imports System.Net
Module MyMod
Sub Main()
Dim mActWebPage As WebRequest = WebRequest.Create("http://www.bbc.co.uk")
Dim mWebProxy As New WebProxy("http://proxyServer.com:8080")
Dim mContent As WebResponse
Dim mStream As IO.Stream
Dim x, y, z
mWebProxy.Credentials() = New Net.NetworkCredential("UID Details", "Password")
mActWebPage.Proxy = mWebProxy
mContent = mActWebPage.GetResponse()
mStream = mActWebPage.GetResponse.GetResponseStream
y = ""
For z = 1 To mContent.ContentLength
x = mStream.ReadByte
y = y & Chr(x)
Next
MsgBox(y)
End Sub
End Module
Move and Click Mouse
Imports System.Runtime.InteropServices
Imports System.Threading
Imports Microsoft.VisualBasic.Interaction
Public Class Form1
Const MOUSEEVENTF_LEFTDOWN As UInteger = &H2 '0x0002
Const MOUSEEVENTF_LEFTUP As UInteger = &H4 '0x0004
<DllImport("user32.dll")>
Private Shared Sub mouse_event(ByVal dwFlags As UInteger, ByVal dx As UInteger, ByVal dy As UInteger, ByVal dwData As UInteger, ByVal dwExtraInfo As Integer)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim x, y
Threading.Thread.Sleep(10000)
x = Shell("C:\Program Files\Internet Explorer\iexplore.exe http://www.bbc.co.uk", AppWinStyle.MaximizedFocus)
y = Process.GetProcessById(x)
Cursor.Position = New Point(1275, 40)
Threading.Thread.Sleep(5000)
clk()
Threading.Thread.Sleep(10000)
'y.kill
End Sub
Sub clk()
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Thread.Sleep(100)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
End Class