This is what i have written so far. I am having an issue creating a desktop shortcut with the home directory path. What is the best way to capture the path and create a shortcut link on the desktop with the homedirectory path? Any help is very much appreciated as i'm a beginner with C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.DirectoryServices;
using System.Management;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
String username = Environment.UserName;
try
{
DirectoryEntry myLdapConnection = createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(myLdapConnection);
search.Filter = "(cn=" + username + ")";
// add the objects to search for
string[] requiredProperties = new string[] {"homeDirectory"};
foreach (String property in requiredProperties)
search.PropertiesToLoad.Add(property);
SearchResult result = search.FindOne();
if (result != null)
{
foreach (String property in requiredProperties)
foreach (Object myCollection in result.Properties[property])
Console.WriteLine(String.Format("{0,-20} : {1}",
property, myCollection.ToString()));
}
else Console.WriteLine("User not found!");
}
catch (Exception e)
{
Console.WriteLine("Exception caught:\n\n" + e.ToString());
}
}
static DirectoryEntry createDirectoryEntry()
{
// create and return new LDAP connection
DirectoryEntry ldapConnection = new DirectoryEntry("Domain.com");
ldapConnection.Path = "LDAP://OU=User,DC=test,DC=domain,DC=com";
ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
return ldapConnection;
}
}
}