Winform 建立桌面快捷方式

代码

private void Create_DesktopShortcut()
{
    
if(ApplicationDeployment.IsNetworkDeployed == true)
    {
         ApplicationDeployment ap 
= Application.CurrentDeployment;
         
if(ap.IsFirstRun == true)
         {
             
string companyName ="Pouchen Group";
             
string productName = "OnlinePOS AP";
             
if(string.IsNullOrEmpty(company) == false && string.IsNullOrEmpty(productName)==false)
             {
                 
//1.移除旧的程式快捷方式
                   if(File.Exists(string.Format("{0}\\{1}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"OnlinePOS Launcher")) == true)
                 {
                      
//移除桌面快捷方式
                      Remove_Link(string.Format("{0}\\{1}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"OnlinePOS Launcher"));
                     
//移除程式集
                         Remove_Link(string.Format("{0}\\{1}\\{2}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Programs),companyName,"OnlinePOS Launcher"));
                     
//启动
                        Remove_Link(string.Format("{0}\\{1}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Startup),"OnlinePOS Launcher"));

                     
//程序集里面
                        Remove_Link(string.Format("{0}\\{1}\\{2}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Programs),CompanyName,productName));

                     
//2.建立新的捷径  程序集的路径名称
                        string[] files = Direction.GetFiles(string.Format("{0}\\{1}",Environment.GetFolderPath(Environment.SpecialFolder.Programs),companyName));
                     
if(files.Length >0)
                     {
                         
string programsPath = files[0];
                         
//建立桌面快捷方式
                         string desktopPath = string.Format("{0}\\{1}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Desktop),productName);
                         
//启动资料夹的路径名称
                             string startupPath = string.Format("{0}\\{1}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Startup),productName);
                         
//复制捷径到桌面
                             File.Copy(programsPath,desktopPath,true);
                         
//赋值捷径到启动连接
                             File.Copy(programsPath,startupPath,true);
                         
//赋值新的名称
                             File.Copy(programsPath,string.Format("{0}\\{1}\\{2}.appref-ms",Environment.GetFolderPath(Environment.SpecialFolder.Programs),CompanyName,prodctName,true));
                         
                     }
    
                 }

             }










         }

    }


}

 

}

posted on 2009-12-21 20:47  秋迪  阅读(640)  评论(1编辑  收藏  举报

导航