Tag Archives: VB.NET

VB.NET: Get User’s SID from Active Directory

This function will connect to Active Directory and search for a specified username, and if found, return that user’s SID.

Usage:

1
GetSIDUsingADSearch("john.doe")

Returns:

1
S-1-5-21-53580104-3876648466-4083845538-427214
Read more

VB.NET: Parse “Special” Shortcuts

I recently had a problem in one of my applications where, when trying to parse .lnk files for target (using the

1
WshShell

approach), I would get something like

1
C:\Windows\Installer\{GUID}

instead of the path to the executable. Turns out some .lnk files (shortcuts) are of a different breed, ala “MSI Shortcut” or “Windows Installer Advertised Application”.

Here is a module which will let you get the Target path of such a shortcut. It returns NULL if it’s a standard .lnk, which you could use to determine whether to use the

1
WshShell

way instead.

Read more

VB.NET: Encrypt/Decrypt String (DES)

These functions will encrypt and decrypt (using DES) a string using a secret key.

1
Encrypt("I need this string to be a secret", "$ThIsIsAsUpErSeCrEtKeY!")

will return a string with the encrypted text.

1
Decrypt("5FkBed78KfrLmoU==BNu37N5kl", "$ThIsIsAsUpErSeCrEtKeY!")

will return the original string that was encrypted with

1
Encrypt()

and the same key.

If a different key is used for

1
Decrypt()

than was originally used for

1
Encrypt()

, an exception will be thrown.

Read more

VB.NET: Get carat position in a RichTextBox control

This function can be called by

1
KeyPress

,

1
Click

, and similar events to return a string with the X and Y coordinates of the carat within a

1
RichTextBox

control.

Example: ”

1
Line 35, Col 18


Function CursorPosition(ByVal Control)
Return “Line ” & (Control.GetLineFromCharIndex(Control.SelectionStart) + 1).ToString & “, Col ” & (Control.SelectionStart – Control.GetFirstCharIndexOfCurrentLine() + 1).ToString
End Function

Read more

VB.NET: Implement key/value pairs in ComboBox

This class will enable a key/value relationship with items in a

1
ComboBox

.

Example:

1
ComboBox1.Items.Add(New DataItem("Key", "Value"))

Key is available with

1
ComboBox1.Items.Item(ComboBox1.SelectedIndex).ID

Value is available with

1
ComboBox1.Items.Item(ComboBox1.SelectedIndex).Value
Read more