Sunday, April 15, 2012

Wix Create Directory/Directories/Folders - Doesn't work

There are times you feel you should be able to ask a question and get the complete and accurate answer, this is the case. I was searching for setting up "wix folder permissions", the first search result was my "complete and accurate answer".

Article Here - a thank you for Chris Jackson for such a post.

After finding what I was looking for; glanced the wix code and started putting the code into my existing wix project. I have put all the directory tags mentioned in the post, but the directories aren't created.

<Directory Id="TARGETDIR" Name="SourceDir">     
........

........
<Component Id="abc" .. ...>     
........
........
 </Component>     
........
........
</Directory>     
I didn't reliaze that a call has to be made for the component using the componentref in the feature like below.

<Feature Id="xyz" ....>
<ComponentRef Id="abc" />
</Feature>


After calling the component the directory was created with the permissions I needed.

Friday, February 17, 2012

Replacing lcd screen on a hp dv6 laptop

I have replaced several lcd screens on the laptops in the past replacing screen on a hp dv6 laptop however was not that straight forward.I had to dismantle the entire laptop to get to the broken lcd.Here is how you get to the lcd.

Screen : Samsung ltn156at05 5kak55804n H02






















HP Pavilion dv6-3127dx
Intel® CoreTM i3-350M processor; 4GB DDR3 memory
500GB Serial ATA hard drive; Multiformat DVD±RW/CD-RW drive with double-layer support
15.6" LED high-definition display; Intel® HD graphics
Built-in TrueVision webcam with digital microphone; 5-in-1 digital media reader
Built-in high-speed wireless LAN (802.11b/g/n); Windows 7 Premium Edition operating system

Wednesday, February 8, 2012

DirectorySearcher PropertiesToLoad Add is not working

If you have played with or is using System.DirectoryServices.ActiveDirectory, you might jump into the consclusio that "DirectorySearcher PropertiesToLoad.Add " is not working/useless/will be ignored.But that might not be the case.

Lets see a sample, this sample below tries to get the list of users with their user name, first name,last name and email.

  Private Sub LoadUsersForDomain(SelectedDomain As Domain)
        If SelectedDomain IsNot Nothing Then
            Dim sentry As DirectoryEntry = SelectedDomain.GetDirectoryEntry
            Dim Searcher As New DirectorySearcher(sentry)
            Dim srs As SearchResultCollection
            Searcher.PropertiesToLoad.Add("samaccountname")
            Searcher.PropertiesToLoad.Add("GivenName")
            Searcher.PropertiesToLoad.Add("sn")
            Searcher.PropertiesToLoad.Add("Mail")
            Searcher.Filter = "(&(objectClass=user)(objectCategory=person))"
            srs = Searcher.FindAll
            For Each Result As SearchResult In srs
                If Result IsNot Nothing Then
                    Dim fuser As New User
                    If Result.Properties("samaccountname") IsNot Nothing AndAlso Result.Properties("samaccountname").Count > 0 Then
                        fuser.UserName = (Result.Properties("samaccountname")(0).ToString())
                    End If
                    If Result.Properties("GivenName") IsNot Nothing AndAlso Result.Properties("GivenName").Count > 0 Then
                        fuser.FirstName = (Result.Properties("GivenName")(0).ToString())
                    End If
                    If Result.Properties("sn") IsNot Nothing AndAlso Result.Properties("sn").Count > 0 Then
                        fuser.LastName = (Result.Properties("sn")(0).ToString())
                    End If
                    If Result.Properties("Mail") IsNot Nothing AndAlso Result.Properties("Mail").Count > 0 Then
                        fuser.Email = (Result.Properties("Mail")(0).ToString())
                    End If
                End If
            Next
            Searcher.Dispose()
            sentry.Dispose()
        End If
    End Sub

When you debug the code, you will notice that for some search results there wont be sn givenname and mail properties in the returned list.

As samaccountname is the only required field when creating a active directory user you will get that all the time in the returned property list, but the others might be there or not depending on the  information got filled in properly or not at the time of creating the user.


----
directorysearcher propertiestoload list
directorysearcher propertiestoload add
directorysearcher clienttimeout
directorysearcher propertiestoload example
directorysearcher properties
directorysearcher filter
directorysearcher propertiestoload email
directorysearcher example

Results from Active Directory search query doesn't contain all the objects

If you are wondering why AD search didnot return all the results, the answer is there is a limit of 1000 records per search.This is the scenario we had:

We have many sub domains on the network like
a1.test.com
a2.test.com

We have users under a1.test.com like a1\user1a,a1\user2a . . . .
We have also users under a2.test.com like a2\user1,a2\user2...; also we have rda2\user3 rda2\user4....;
I dont have lot of knowledge about "AD" structure or the terminology.I dont know how the rda2\user3,user4 ended up under a2.test.com

My user is rda2\user3 and if look at the user domain using the "set" command I get a2.test.com, my user dns domain is rda2.

The problem is in my windows app I am trying to show the list of users under every domain
It shows somethings like this in the treeview
a1.test.com
a1\user1a
a1\user2a
a2.test.com
a2\user1
a2\user2
But users rda2\user3 and rda2\user4 is missing from the list.

I use the following code to get the list of users.Also I use the windows add user dialog on my machine I can see all the users if I pick "a2.test.com" as my source and hit find now.

--To get the list of users
Dim ds As New DirectorySearcher(Domain.GetCurrentDomain.GetDirectoryEntry)
ds.PropertiesToLoad.Add(samaccountname)
ds.Filter = "(&(objectClass=user)(objectCategory=person))"
For Each sr As SearchResult In ds.FindAll()
WriteLog("getUsersInGroup first for DomainName " + DomainName)
GetUser() -- code below
Next

--To get user
Searcher = New DirectorySearcher(Domain.GetCurrentDomain.GetDirectoryEntry())
Searcher.Filter = "(&(objectCategory=person)(objectClass=user)(samaccountname=" & adn.UserName & "))"
Searcher.PropertiesToLoad.Add(LDAP_PROPERTY_FIRST_NAME)
Searcher.PropertiesToLoad.Add(LDAP_PROPERTY_LAST_NAME)
Searcher.PropertiesToLoad.Add(LDAP_PROPERTY_EMAIL)

It seems like that the Domain I am trying to search has more than 1000 objects and the usersrda2\user3 and rda2\user4 are added recently so they are never returned back, I tried to use the windows built-in user search dialog and got a error "that there are more than 10000 objects", so to solve the problem

 I have added a filter textbox and is filtering the results.Now I have the users I wanted in the treeview.

Other option would be to set the DirectorySearcher.PageSize to value that is greater than 0 and less than 1000 and get all the results back, keep in mind this might be slow.

Sunday, January 22, 2012

Fetching logins from various sources - Active Directory, WIndows local logins and SQL Logins

At times there is need to get the list of logins from active directory, windows local logins or sql logins.Microsoft has done very good job of providing namespaces to fetch login info from various sources.Small example attached shows you how to use the namespace and gives some insight about the namespace, hope this helps someone out there.

Active Directory Users:


Windows Logins:

SQL logins:

Private Sub GetUser(ByVal sr As SearchResult, ByVal d As Domain, ByVal domainName As String, ByRef groupMembers As SortedList(Of String, CustomLoginNode))

If sr.Properties(LDAP_PROPERTY_USER_NAME) Is Nothing Then Return

Dim adn As New CustomLoginNode
Dim Searcher As DirectorySearcher
Dim Result As SearchResult
Dim UserEntry As DirectoryEntry

If sr.Properties(LDAP_PROPERTY_USER_NAME) IsNot Nothing Then
''this doamin name is PME , d.name = pme.local
adn.DomainName = domainName
adn.UserName = sr.Properties(LDAP_PROPERTY_USER_NAME)(0).ToString()
adn.UserNameWithDomainName = adn.DomainName + "\" + adn.UserName
End If

Searcher = New DirectorySearcher(d.GetDirectoryEntry)
Searcher.Filter = "(&(objectCategory=person)(objectClass=user)(samaccountname=" & adn.UserName & "))"
Searcher.PropertiesToLoad.Add(LDAP_PROPERTY_FIRST_NAME)
Searcher.PropertiesToLoad.Add(LDAP_PROPERTY_LAST_NAME)
Searcher.PropertiesToLoad.Add(LDAP_PROPERTY_EMAIL)

Result = Searcher.FindOne

If Result IsNot Nothing Then

UserEntry = Result.GetDirectoryEntry()

If UserEntry.Properties(LDAP_PROPERTY_FIRST_NAME).Value IsNot Nothing Then
adn.FirstName = UserEntry.Properties(LDAP_PROPERTY_FIRST_NAME).Value.ToString()
End If
If UserEntry.Properties(LDAP_PROPERTY_LAST_NAME).Value IsNot Nothing Then
adn.LastName = UserEntry.Properties(LDAP_PROPERTY_LAST_NAME).Value.ToString()
End If
If UserEntry.Properties(LDAP_PROPERTY_EMAIL).Value IsNot Nothing Then
adn.Email = UserEntry.Properties(LDAP_PROPERTY_EMAIL).Value.ToString()
End If

End If

adn.UserNameWithDomainNameAndFullName = GetFullName(adn.UserNameWithDomainName, adn.FirstName, adn.LastName)

If Not groupMembers.ContainsKey(adn.UserNameWithDomainName) Then
groupMembers.Add(adn.UserNameWithDomainName, adn)
End If

End Sub


Private Function getUsersInGroup(ByVal strGroupDN As String, ByVal d As Domain) As SortedList(Of String, CustomLoginNode)
Dim groupMembers As New SortedList(Of String, CustomLoginNode)

''To get the users from the nested groups
Dim CurrentGroupsAndNestedGroups As New SortedList(Of String, String)
Dim DomainName As String = String.Empty

''this doamin name is PME , d.name = pme.local
DomainName = d.GetDirectoryEntry.Properties("dc").Value.ToString.ToUpper

Dim ds As New DirectorySearcher(d.GetDirectoryEntry)
ds.PropertiesToLoad.Add(LDAP_PROPERTY_USER_NAME)

Try
If String.IsNullOrEmpty(strGroupDN) Then
ds.Filter = "(&(objectClass=user)(objectCategory=person))"
For Each sr As SearchResult In ds.FindAll()
WriteLog("getUsersInGroup first for DomainName " + DomainName)
GetUser(sr, d, DomainName, groupMembers)
Next
Return groupMembers
Else
''get the nested groups of the current group
CurrentGroupsAndNestedGroups = GetGroups(strGroupDN, d)

''adding the current group to the list
If Not CurrentGroupsAndNestedGroups.ContainsKey(strGroupDN) Then
CurrentGroupsAndNestedGroups.Add(strGroupDN, strGroupDN)
End If

For Each kv As KeyValuePair(Of String, String) In CurrentGroupsAndNestedGroups
ds.Filter = [String].Format("(&(memberOf={0})(objectClass=person))", kv.Key)

For Each sr As SearchResult In ds.FindAll()
WriteLog("getUsersInGroup DomainName second for " + DomainName)
GetUser(sr, d, DomainName, groupMembers)
Next
Next

Return groupMembers
End If
Catch ex As Exception
ProcessException(ex)
End Try

Return groupMembers
End Function

Private Function GetGroups(ByVal strGroupDN As String, ByVal d As Domain) As SortedList(Of String, String)
''for sorting and to avoid duplicates, otherwise would have used list of string
Dim groups As New SortedList(Of String, String)

' find all nested groups in this group
Dim ds As New DirectorySearcher(d.GetDirectoryEntry)

''if groupdn is not sent then return all the groups in the domain
If String.IsNullOrWhiteSpace(strGroupDN) Then
ds.Filter = "(&(objectClass=group))"
Else
''if groupdn is there then return the groups of the groupdn(nested groups)
ds.Filter = [String].Format("(&(memberOf={0})(objectClass=group))", strGroupDN)
End If

ds.PropertiesToLoad.Add(LDAP_PROPERTY_GROUP)

For Each sr As SearchResult In ds.FindAll()
WriteLog("GetGroups for " + strGroupDN)
Dim grpname As String = sr.Properties(LDAP_PROPERTY_GROUP)(0).ToString()
If Not groups.ContainsKey(grpname) Then
groups.Add(grpname, grpname)
End If
Next

Return groups
End Function



Private Sub LoadServerLocalGroupUsers(ByVal grpname As String, ByVal grpnode As TreeNode)

Dim serverName As String = txtServerName.Text
If String.IsNullOrEmpty(serverName) Then Return

Using groupEntry As New DirectoryEntry("WinNT://" + serverName + "/" + grpname + ",group")
For Each member As Object In DirectCast(groupEntry.Invoke("Members"), IEnumerable)
Using memberEntry As New DirectoryEntry(member)
If memberEntry.Parent.Name.ToLower = serverName.ToLower Then
BuildUserNodeForLocalUser(memberEntry, grpnode)
End If
End Using
Next
End Using
End Sub

Private Sub LoadWindowsUsers()
Dim serverName As String = txtServerName.Text
If String.IsNullOrEmpty(serverName) Then Return

Dim localMachinede As DirectoryEntry = New DirectoryEntry("WinNT://" + serverName)

Dim snd As New TreeNode
snd.Text = serverName
trvwUsers.Nodes.Add(snd)

Dim pund As New TreeNode
pund.Text = NODE_TEXT_USERS
snd.Nodes.Add(pund)

Dim gsnd As New TreeNode
gsnd.Text = NODE_TEXT_GROUPS
snd.Nodes.Add(gsnd)

For Each UserEntry As DirectoryEntry In localMachinede.Children
If UserEntry.SchemaClassName = "User" Then
BuildUserNodeForLocalUser(UserEntry, pund)
ElseIf UserEntry.SchemaClassName = "Group" Then
Dim gnd As New TreeNode
gnd.Text = UserEntry.Name
Dim adn1 As New CustomLoginNode
adn1.Source = CustomLoginNode.Sources.WindowsLocal
adn1.DomainName = UserEntry.Name
adn1.DirectoryEntry = localMachinede
adn1.NodeType = CustomLoginNode.NodeTypes.Groups
adn1.UserType = CustomLoginNode.UserTypes.WindowsLogin
gnd.Tag = adn1
gsnd.Nodes.Add(gnd)
gnd.Nodes.Add("")
End If
UserEntry.Dispose()
Next
trvwUsers.SelectedNode = pund
End Sub

Private Sub LoadSQLServerUsers()

Dim svr As Server = New Server(txtServerName.Text)
svr.ConnectionContext.LoginSecure = True

Dim pund As New TreeNode
pund.Text = NODE_TEXT_USERS
trvwUsers.Nodes.Add(pund)

For Each login As Login In svr.Logins
If login.LoginType = LoginType.SqlLogin Then
Dim und As New TreeNode
und.Text = login.Name
Dim adn1 As New CustomLoginNode
adn1.NodeType = CustomLoginNode.NodeTypes.User
adn1.UserType = CustomLoginNode.UserTypes.SQLLogin
und.Tag = adn1
pund.Nodes.Add(und)
End If
Next

trvwUsers.SelectedNode = pund
End Sub

Imports System.DirectoryServices.ActiveDirectory
Imports System.DirectoryServices
Imports Microsoft.SqlServer.Management.Smo

Download Sample

Monday, January 9, 2012

Crystal Report Build Errors in Visual Studio

If a machine has two versions of Crystal reports installed, visual studio somehow sometimes picks the older version and you endup with the following errors.

error BC30456: 'ReuseParameterValuesOnRefresh' is not a member of 'CrystalDecisions.Windows.Forms.CrystalReportViewer'.

error BC30456: 'ShowParameterPanelButton' is not a member of 'CrystalDecisions.Windows.Forms.CrystalReportViewer'.

error BC30455: Argument not specified for parameter 'endPageN' of 'Public Overridable Sub PrintToPrinter(nCopies As Integer, collated As Boolean, startPageN As Integer, endPageN As Integer)'.

error BC30311: Value of type 'System.Drawing.Printing.PrinterSettings' cannot be converted to 'Integer'.

error BC30311: Value of type 'System.Drawing.Printing.PageSettings' cannot be converted to 'Boolean'.

error BC30455: Argument not specified for parameter 'endPageN' of 'Public Overridable Sub PrintToPrinter(nCopies As Integer, collated As Boolean, startPageN As Integer, endPageN As Integer)'.

error BC30311: Value of type 'System.Drawing.Printing.PrinterSettings' cannot be converted to 'Integer'.

error BC30311: Value of type 'System.Drawing.Printing.PageSettings' cannot be converted to 'Boolean'.

error BC30456: 'Xml' is not a member of 'CrystalDecisions.Shared.ExportFormatType'.

error BC30456: 'Xml' is not a member of 'CrystalDecisions.Shared.ExportFormatType'.

error BC30456: 'Xml' is not a member of 'CrystalDecisions.Shared.ExportFormatType'.

error BC30456: 'Xml' is not a member of 'CrystalDecisions.Shared.ExportFormatType'.

In the project file the references were like this

 <Reference Include="CrystalDecisions.CrystalReports.Engine, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\..\..\Windows\assembly\GAC_MSIL\CrystalDecisions.CrystalReports.Engine\12.0.2000.0__692fbea5521e1304\CrystalDecisions.CrystalReports.Engine.dll</HintPath>
    </Reference>

but still uses 10.5.3700.0 version of the dlls.

Remove all the crystal references and add them back to the project, you will see this in the project file and build errors will go away!.

    <Reference Include="CrystalDecisions.CrystalReports.Engine, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />

IIS Manager Crashes on Load/Start Windows 7, IIS 7.5

IIS Manager Crashes on Start  Windows 7, IIS 7.5, Power Shell 5.1. Here is the error I got in the event viewer. IISMANAGER_CRASH IIS Ma...