maandag 29 september 2008
Vista boot disc / recovery disc
I found a solution though, you can download a recovery disc from this website. With this disc I was able to boot from CD and run chkdisc from the CD. The size of the download is approximatly 120 MB and best of all completly free.
vrijdag 26 september 2008
Show temporary file in an external application VB.NET
In this example I will show you how to start an external application and how to generate a temporary file in the temp directory configured in Windows. The source code below create a text file in the temp directory and shows this file Notepad. The filename for the file is automatically generated.
Dim sw As IO.StreamWriter
Dim sTmpFile As String
'Write the temp file
sTmpFile = System.IO.Path.GetTempFileName()
sw = New IO.StreamWriter(sTmpFile, False)
sw.Write(Me.BookingRow.sCRSRecord)
sw.Close()
'Launch the external application
Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
myProcess.StartInfo.FileName = "notepad.exe"
myProcess.StartInfo.Arguments = sTmpFile
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal myProcess.Start()
Encryption in VB.NET
Encryption in Visual Basic .NET has become quite simple, as the .NET Framework already includes some popular encryption providers. The following class makes it easier to use encryption in your application.
Public Class CryptTools
Private Shared HashKey As Byte() = {12, 45, 7, 123, 6, 34, 56, 12, 245, 34} Public Shared Function GetHexHash(ByVal ba As Byte()) As String
Dim hb As String
Dim ret As String = ""
For i As Integer = 0 To ba.Length - 1
hb = Hex(ba(i))
If hb.Length = 0 Then
hb = "00"
ElseIf hb.Length = 1 Then
hb = "0" & hb
End If
ret &= hb
Next
Return ret
End Function
Public Shared Function Encrypt(ByVal data As String, ByVal key As String) As Byte()
Return Encrypt(System.Text.ASCIIEncoding.ASCII.GetBytes(data), key)
End Function
Public Shared Function Encrypt(ByRef data As Byte(), ByVal key As String) As Byte()
Dim RMCrypto As New System.Security.Cryptography.RijndaelManaged
Dim mStream As System.IO.MemoryStream
Dim CryptStream As System.Security.Cryptography.CryptoStream
Dim bytIV() As Byte = {115, 21, 106, 15, 12, 78, 19, 30, 200, 90, 40, 75, 13, 212, 21, 67}
Dim bytKEY() As Byte
Dim sha As New System.Security.Cryptography.HMACSHA256(HashKey)
'Create key from the hash of the string
bytKEY = sha.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(key))
'Encrypt the data
mStream = New IO.MemoryStream()
RMCrypto.KeySize = 256
CryptStream = New System.Security.Cryptography.CryptoStream(mStream, RMCrypto.CreateEncryptor(bytKEY, bytIV), System.Security.Cryptography.CryptoStreamMode.Write)
CryptStream.Write(data, 0, data.Length)
CryptStream.FlushFinalBlock()
'Cean up
CryptStream.Close()
mStream.Close()
Return mStream.ToArray()
End Function
Public Shared Function Decrypt(ByVal data As String, ByVal key As String) As Byte()
Return Decrypt(System.Text.ASCIIEncoding.ASCII.GetBytes(data), key)
End Function
Public Shared Function Decrypt(ByRef data As Byte(), ByVal key As String) As Byte()
Dim RMCrypto As New System.Security.Cryptography.RijndaelManaged
Dim mStream As System.IO.MemoryStream
Dim CryptStream As System.Security.Cryptography.CryptoStream
Dim cryptBuffer As Byte()
Dim bytIV() As Byte = {115, 21, 106, 15, 12, 78, 19, 30, 200, 90, 40, 75, 13, 212, 21, 67}
Dim bytKEY() As Byte
Dim sha As New System.Security.Cryptography.HMACSHA256(HashKey)
'Create key from the hash of the string
bytKEY = sha.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(key))
'Encrypt the data
mStream = New IO.MemoryStream(data)
RMCrypto.KeySize = 256
CryptStream = New System.Security.Cryptography.CryptoStream(mStream, RMCrypto.CreateDecryptor(bytKEY, bytIV), System.Security.Cryptography.CryptoStreamMode.Read)
ReDim cryptBuffer(data.Length - 1)
CryptStream.Read(cryptBuffer, 0, data.Length)
'Cean up
CryptStream.Close()
mStream.Close()
Return cryptBuffer
End Function
End Class
Simple encryption in VB
This is an simple introduction on write your own encryption functions, but as stated these function are very simple, so do NOT use this function for encrypting any important data.
The first and very simple encryption:
The following function adds the code number to the ascii value of the text, which all characters change to something else.
An output of this function could be:
Rovvy8*^ro*}zkwwo|*lovy�*s}*os~ro|*}sxq*ƒy|*|o}y|mo}*~y*}oxn*y~*lvu
x}yvsms~on*mywwo|mskv*o7wksv*2,}zkw,3*y|*s}*nomoz~s€ovƒ*~|ƒsxq*~y*wkuo*s~
vyyu*vsuo*ro*s}8*Sx*os~ro|*mk}o6*k*voqs~swk~o*mywzkxƒ*vsuo*ƒy|}
*z|ylklvƒ�yvn*xy~*kzz|y€
o8*^ro*sxpy|wk~syx*lovy�*}ryvn*lo*kvv*ƒy*xoon8
Quite hard to read, isn't it?
Public Function Encrypt1(Txt As String, CodeNr As Integer) As String |
As encryption en decryption are not that different we just call Encrypt1 from the decryption function:
Public Function Decrypt1(Txt As String, CodeNr As Integer) As String End Function |
Now you may be wondering why this code is so extremely weak. But it's actually quite simple, as the most commonly used character would normally be the space. Below the code to break this code easily:
Function BreakCode(CText as String) as String |
Open default browser
This source code will open a site/html page in the clients default browser (for example Internet Explorer or Firefox).
Add the following source code to a module:
'*************************************************************** 'Windows APIl Declarations for :Open Default Web Browser '*************************************************************** Public Declare Function ShellExecute Lib "shell32.dll" Alias _
|
If you want to open a browser window from a form, use the following VB code:
| GotoWebsite(Me, "http://www.compuonline.info/") |
Get HTML from Webbrowser Control
Public Function GetHTML(Web As WebBrowser) As String 'declare variables Dim doc As HTMLDocument 'Make sure the page has been completely loaded 'if not wait Do DoEvents Loop Until Not Web.Busy Set doc = Web.Document 'return the html GetHTML = doc.All(0).outerHTML End Function |
Filling a form in the WebBrowser Control (automatically)
In this sample I will fill the altavista search box, with the WebBrowser control. Below I will list some subs and functions which are used in this sample.
Open a new project (standard exe) and place a WebBrowser control, a textbox, and a command button on form1. Make sure you also have an reference to mshtml.tlb.
Add the following code to form1:
Private Sub Command1_Click() 'go to the altavista (text) search page 'Wait until page is loaded 'Make doc reference to the document inside the webbrowser control 'Set field q with the value of Text1 'Submit the form (same result as click the search button) 'Wait until result are loaded MsgBox "Altavista search result loaded" |
Add the following code to a module:
Public Sub SetInputField(doc As HTMLDocument, Form As Integer, Name As String, Value As String) For q = 0 To doc.Forms(Form).length - 1 |
Additional useful subs:
Sub to get the contents from a textbox:
| Public Function GetInputField(doc As HTMLDocument, Form As Integer, Name As String) As String For q = 0 To doc.Forms(Form).Length - 1 If doc.Forms(Form)(q).Name = Name Then GetInputField = doc.Forms(From)(q).Value Exit For End If Next q End Function |
Sub to set a Checkbox:
| Public Sub SetCheckBox(doc As HTMLDocument, Form As Integer, Name As String, Value As Boolean) For q = 0 To doc.Forms(Form).Length - 1 If doc.Forms(Form)(q).Name = Name Then doc.Forms(From)(q).Checked = Value Exit For End If Next q End Sub |
Sub set a radio button:
| Public Sub SetRadioButton(doc As HTMLDocument, Form As Integer, Name As String, Name2 As String) For q = 0 To doc.Forms(Form).Length - 1 If (doc.Forms(Form)(q).Name = Name) And (doc.Forms(Form)(q).Value = Name2) Then doc.Forms(From)(q).Checked = True Exit For End If Next q End Sub |
Sub set a combo box:
| Public Function SetComboBoxValue(ByVal doc As IHTMLDocument3, Form As Integer, Name As String, Name2 As String) '**** This one bases it's selection on the Value of the - - Tag. Dim q, i For q = 0 To doc.Forms(Form).length - 1 If (doc.Forms(Form)(q).Name = Name) Then For i = 0 To doc.Forms(Form)(q).length - 1 If doc.Forms(Form)(q).Options(i).Value = Name2 Then doc.Forms(Form)(q).Options(i).Selected = True Exit For End If Next i End If Next q End Function |
Public Function SetComboValue(ByVal doc As IHTMLDocument3, Form As Integer, Name As String, Name2 As String) '**** This one bases it's selection on the Value of the Text after the - 'Text - Tag. Dim q, i For q = 0 To doc.Forms(Form).length - 1 If (doc.Forms(Form)(q).Name = Name) Then For i = 0 To doc.Forms(Form)(q).length - 1 If doc.Forms(Form)(q).Options(i).Text = Name2 Then doc.Forms(Form)(q).Options(i).Selected = True Exit For End If Next End If Next q |
Order the WebBrowser control to click a link
The following sub will click a link with the text LinkText in a document, given that you referenced mshtml.tlb and pass a HTMLDocument as the doc parameter (for example WebBrowser.Document):
| Public Sub ClickLink(doc, LinkText As String) For i = 0 To doc.links.length - 1 If LTrim(RTrim(doc.links(i).outerText)) = LinkText Then doc.links(i).Click Exit For End If Next i End Sub |
The following sub will click a link which refers to LinkUrl in a document:
Public Sub ClickLinkUrl(doc, LinkUrl As String)
For i = 0 To doc.links.length - 1
If LTrim(RTrim(doc.links(i).href)) = LinkUrl Then
doc.links(i).Click
Exit For
End If
Next i
End Sub