Tag: windows

Determine if a user belongs to a particular AD Group

This is the easiest way to determine if a user belongs to particular Active Directory user group using VB.NET without having to enumerate through all the user’s groups.

Public Function IsInGroup(ByVal GroupName As String) As Boolean
 Dim MyIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
 Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(MyIdentity)
 Return MyPrincipal.IsInRole(GroupName)
End Function

Replacing a string in each user’s profile

This routine replaces a string in the text file user.js.  The file is located in each user’s profile which also contains a random string as part of the path name.

Imports System.Net
Imports System.IO

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
 Dim strPath As String = "c:\users"
 Dim arrFolders() As String = System.IO.Directory.GetDirectories(strPath)
 Dim MozPath As String

'----------------------------------------------------------------
 ' get list of profiles
 '----------------------------------------------------------------
 For Each arrFolder As String In arrFolders
 MozPath = arrFolder & "\AppData\Roaming\Mozilla\Firefox\Profiles\"

If My.Computer.FileSystem.DirectoryExists(MozPath) = True Then
 Dim arrGUIDpath() As String = System.IO.Directory.GetDirectories(MozPath)

For Each arrGUIDfolder As String In arrGUIDpath
 If My.Computer.FileSystem.FileExists(arrGUIDfolder & "\user.js") = True Then
 Console.WriteLine("notepad " & arrGUIDfolder & "\user.js")

'----------------------------------------------------------------
 ' 1. rename the user.js file
 ' 2. replace the proxy defintion string tinto user.js
 '----------------------------------------------------------------
 Try
 My.Computer.FileSystem.DeleteFile(arrGUIDfolder & "\user2.js")
 Catch ex As Exception
 Application.DoEvents()
 End Try

My.Computer.FileSystem.CopyFile(arrGUIDfolder & "\user.js", arrGUIDfolder & "\user2.js")

My.Computer.FileSystem.WriteAllText(arrGUIDfolder & "\user.js", _
 My.Computer.FileSystem.ReadAllText(arrGUIDfolder & "\user2.js").Replace("user_pref(""network.proxy.type"", 4);", _
 "user_pref(""network.proxy.type"", 0);"), False)
 End If

'----------------------------------------------------------------
 ' clean up to avoid confusion in the future
 '----------------------------------------------------------------
 Application.DoEvents()

Try
 My.Computer.FileSystem.DeleteFile(arrGUIDfolder & "\user2.js")
 Catch ex As Exception
 Application.DoEvents()
 End Try
 Next
 End If

Next
 End
 End Sub

End Class

Authenticate User to Security Group

Imports System.Security.Principal

Public Class Form1
Public id As WindowsIdentity = WindowsIdentity.GetCurrent()
Public User As WindowsPrincipal = New WindowsPrincipal(id)

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim flg As Boolean = User.IsInRole(“Domain\Security Group”)

Select Case flg
Case True
MsgBox(“I am a member of the group”)
Case False
MsgBox(“Not a member”)
End Select

End
End Sub

End Class

Windows 7 taskbar not responding

Click Start

Type: CMD, from the results, right click CMD

Click ‘Run as Administrator’

At the Command Prompt, type: sfc/scannow

This will check for any integrity violations

Restart your system

  1. Insert the Windows 7 DVD
  2. Restart your computer
  3. When asked if you want to boot from your DVD drive, do so.
  4. Choose your language, click Next.
  5. Click ‘Repair your computer’
  6. Select operating system you want repair.

LDAP Active Directory User Object Properties/Attributes

LDAP Active Directory Properties/Attributes
LDAP Property Description
DN DN Stands for distinguisehd name. This is the unique identifier for any object in AD. An example value would be:

CN=Joe User, OU=Las Vegas, DC=mycompany,DC=com

Note that when identifying a DN value in your script you will likely be required to enclose the line above with double quotes (“) so it would look like this:

CN=Joe User, OU=Las Vegas, DC=mycompany,DC=com

CN CN = Joe User
CN stands for Common Name. This property is a combination of the givenName and SN attributes joined together
displayName displayName = Joe User
Note that displayName and CN are often confused for each other.
description Note that this is different from displayName
givenName The first name of the user
homeDrive Home Folder
name name = Joe User. The same as CN
ObjectClass objectClass = User
Identifies what type of object is selected. Other values are: Computer, orgnizationalUnit, container, group
objectCategory objectClass = Person
Defines what schema category that object belongs to.
physcialDeliveryOfficeName The office field of the user property
profilePath Roaming profile path: connect. Setup is a bit tricky
sAMAccountName sAMAAccountName = jUser
This is an old NT 4.0 logon ID. This value must be unique in the domain.
SN SN = User
This is the last name of the user. SN stands for surname
userAccountControl This property is used to enable or disable a user account. A value of 514 means that account is disabled. A value of 512 means the account is enabled.
userPrincipleName userPrincipleName = juser@lasvegas.com
This property is useful for logging in a large forest Active Directory architecutre. This is also a unique property throught the forest. This property is often abbreviated as UPN.
mail mail = juser@lasvegas.com
the email property of the user
C Country or Region
company Name of Company or Organization
department Department
homephone
l Location. Used mainly with printers
That is a lower case (L)
manager
mobile Cell phone or mobile phone number
OU Orgnizational Unit
postalCode Zip or post code
st State or province
streetAddress Street address, not including country or state
telephoneNumber Office Phone
dNSHostName
rID
url
uSNCreate
uSNChanged
tokenGroups A computed attribute that contains the list of SIDs due to a transitive group membership expansion operation on a given user or computer. Token Groups cannot be retrieved if no Global Catalog is present to retrieve the transitive reverse memberships.

More Info

.NET Active Directory – Understanding LDAP Active Directory User Object Properties/Attributes.