Click here to Skip to main content
15,893,588 members
Home / Discussions / C#
   

C#

 
GeneralRe: Fast messages not sent through TcpClient Pin
bocsiboti6-Aug-09 3:04
bocsiboti6-Aug-09 3:04 
GeneralRe: Fast messages not sent through TcpClient Pin
Ennis Ray Lynch, Jr.6-Aug-09 6:06
Ennis Ray Lynch, Jr.6-Aug-09 6:06 
GeneralRe: Fast messages not sent through TcpClient Pin
bocsiboti6-Aug-09 20:04
bocsiboti6-Aug-09 20:04 
AnswerRe: Fast messages not sent through TcpClient Pin
Luc Pattyn5-Aug-09 5:07
sitebuilderLuc Pattyn5-Aug-09 5:07 
GeneralRe: Fast messages not sent through TcpClient Pin
bocsiboti6-Aug-09 3:06
bocsiboti6-Aug-09 3:06 
GeneralRe: Fast messages not sent through TcpClient Pin
Luc Pattyn6-Aug-09 3:09
sitebuilderLuc Pattyn6-Aug-09 3:09 
QuestionMaking a wrapper: execlp or fork [modified] Pin
ajester655-Aug-09 4:28
ajester655-Aug-09 4:28 
QuestionTrying to create a shortcut... Pin
JollyMansArt5-Aug-09 4:25
JollyMansArt5-Aug-09 4:25 
My ultimate goal is to place shortcuts onto the desktop and startmenu of the files my application is copying to the workstation.
I found some code that allows me to create a shortcut file but I can not get the reference to work because I can not find the reference for IWshRuntimeLibrary in VS 2008 C#.

Does anyone have any suggestions on code I could use or reference to understand a better way of creating these shortcuts.


The Code below allows me to add a shortcut using :
Link.Update(Environment.SpecialFolder.DesktopDirectory, FileDestination, "Shell Link", true);



Here is the code that I found.

public class Link
     {
          /// <summary>
          /// Check to see if a shortcut exists in a given directory with a specified file name
          /// </summary>
          /// <param name="DirectoryPath">The directory in which to look</param>
          /// <param name="FullPathName">The name of the shortcut (without the .lnk extension) or the full path to a file of the same name</param>
          /// <returns>Returns true if the link exists</returns>
          public static bool Exists(string DirectoryPath, string LinkPathName)
          {
               // Get some file and directory information
               DirectoryInfo SpecialDir=new DirectoryInfo(DirectoryPath);
               // First get the filename for the original file and create a new file
               // name for a link in the Startup directory
               //
               FileInfo originalfile = new FileInfo(LinkPathName);
               string NewFileName = SpecialDir.FullName+"\\"+originalfile.Name+".lnk";
               FileInfo linkfile = new FileInfo(NewFileName);
               return linkfile.Exists;
          }
         
          //Check to see if a shell link exists to the given path in the specified special folder
          // return true if it exists
          public static bool Exists(Environment.SpecialFolder folder, string LinkPathName)
          {
               return Link.Exists(Environment.GetFolderPath(folder), LinkPathName);
          }
         
          /// <summary>
          /// Update the specified folder by creating or deleting a Shell Link if necessary
          /// </summary>
          /// <param name="folder">A SpecialFolder in which the link will reside</param>
          /// <param name="TargetPathName">The path name of the target file for the link</param>
          /// <param name="LinkPathName">The file name for the link itself or, if a path name the directory information will be ignored.</param>
          /// <param name="Create">If true, create the link, otherwise delete it</param>
          public static void Update(Environment.SpecialFolder folder, string TargetPathName, string LinkPathName, bool install)
          {
               // Get some file and directory information
               Link.Update(Environment.GetFolderPath(folder), TargetPathName, LinkPathName, install);
          }
              
          // boolean variable "install" determines whether the link should be there or not.
          // Update the folder by creating or deleting the link as required.
         
          /// <summary>
          /// Update the specified folder by creating or deleting a Shell Link if necessary
          /// </summary>
          /// <param name="DirectoryPath">The full path of the directory in which the link will reside</param>
          /// <param name="TargetPathName">The path name of the target file for the link</param>
          /// <param name="LinkPathName">The file name for the link itself or, if a path name the directory information will be ignored.</param>
          /// <param name="Create">If true, create the link, otherwise delete it</param>
          public static void Update(string DirectoryPath, string TargetPathName, string LinkPathName, bool Create)
          {
               // Get some file and directory information
               DirectoryInfo SpecialDir=new DirectoryInfo(DirectoryPath);
               // First get the filename for the original file and create a new file
               // name for a link in the Startup directory
               //
               FileInfo OriginalFile = new FileInfo(LinkPathName);
               string NewFileName = SpecialDir.FullName+"\\"+OriginalFile.Name+".lnk";
               FileInfo LinkFile = new FileInfo(NewFileName);

               if(Create) // If the link doesn't exist, create it
               {
                    if(LinkFile.Exists)return; // We're all done if it already exists
                    //Place a shortcut to the file in the special folder
                    try
                    {
                         // Create a shortcut in the special folder for the file
                         // Making use of the Windows Scripting Host
                         WshShell shell = new WshShell();
                         IWshShortcut link = (IWshShortcut)shell.CreateShortcut(LinkFile.FullName);
                         link.TargetPath=TargetPathName;
                         link.Save();
                    }
                    catch
                    {
                         MessageBox.Show("Unable to create link in special directory: "+NewFileName,
                              "Shell Link Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
               }
               else // otherwise delete it from the startup directory
               {
                    if(!LinkFile.Exists)return; // It doesn't exist so we are done!
                    try
                    {
                         LinkFile.Delete();
                    }
                    catch
                    {
                         MessageBox.Show("Error deleting link in special directory: "+NewFileName,
                              "Shell Link Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
               }
          }

     }
AnswerRe: Trying to create a shortcut... Pin
Jimmanuel5-Aug-09 5:32
Jimmanuel5-Aug-09 5:32 
QuestionReplication Feature of SQL 2005 Pin
Abdul Rahman Hamidy5-Aug-09 3:38
Abdul Rahman Hamidy5-Aug-09 3:38 
AnswerRe: Replication Feature of SQL 2005 Pin
Ennis Ray Lynch, Jr.5-Aug-09 4:19
Ennis Ray Lynch, Jr.5-Aug-09 4:19 
GeneralRe: Replication Feature of SQL 2005 Pin
Abdul Rahman Hamidy5-Aug-09 4:26
Abdul Rahman Hamidy5-Aug-09 4:26 
GeneralRe: Replication Feature of SQL 2005 Pin
Ennis Ray Lynch, Jr.5-Aug-09 4:30
Ennis Ray Lynch, Jr.5-Aug-09 4:30 
GeneralRe: Replication Feature of SQL 2005 Pin
Abdul Rahman Hamidy5-Aug-09 4:35
Abdul Rahman Hamidy5-Aug-09 4:35 
GeneralRe: Replication Feature of SQL 2005 Pin
Ennis Ray Lynch, Jr.5-Aug-09 4:44
Ennis Ray Lynch, Jr.5-Aug-09 4:44 
GeneralRe: Replication Feature of SQL 2005 Pin
Abdul Rahman Hamidy5-Aug-09 4:51
Abdul Rahman Hamidy5-Aug-09 4:51 
QuestionCan we import managed DLL Pin
jpk4205-Aug-09 3:24
jpk4205-Aug-09 3:24 
AnswerRe: Can we import managed DLL Pin
Luc Pattyn5-Aug-09 3:31
sitebuilderLuc Pattyn5-Aug-09 3:31 
AnswerRe: Can we import managed DLL Pin
jpk4205-Aug-09 3:33
jpk4205-Aug-09 3:33 
GeneralRe: Can we import managed DLL Pin
harold aptroot5-Aug-09 3:40
harold aptroot5-Aug-09 3:40 
GeneralRe: Can we import managed DLL Pin
Luc Pattyn5-Aug-09 3:49
sitebuilderLuc Pattyn5-Aug-09 3:49 
Question[Message Deleted] Pin
Amangang5-Aug-09 3:22
Amangang5-Aug-09 3:22 
NewsRe: Problem with brackets on the 'Console.WriteLine' & the 'Console.ReadLine' commands Pin
Amangang5-Aug-09 3:23
Amangang5-Aug-09 3:23 
AnswerRe: Problem with brackets on the 'Console.WriteLine' & the 'Console.ReadLine' commands Pin
Luc Pattyn5-Aug-09 3:35
sitebuilderLuc Pattyn5-Aug-09 3:35 
GeneralRe: Problem with brackets on the 'Console.WriteLine' & the 'Console.ReadLine' commands Pin
Amangang5-Aug-09 3:44
Amangang5-Aug-09 3:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.