创建并运行快捷方式

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IWshRuntimeLibrary;


namespace WindowsApplication2
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void button1_Click(object sender, EventArgs e)
        
{            
            
this.CreateLink();
             System.Diagnostics.Process.Start(
"C:\\mysql\\dbChecked");

        }


        
void CreateLink()
        
{
            WshShell shell 
= new WshShell();
            IWshShortcut shortcut 
= (IWshShortcut)shell.CreateShortcut("c:\\mysql" + "\\" + "dbChecked.lnk"
                );
            shortcut.TargetPath 
= "C:\\mysql\\pack516.BAT";
            shortcut.WorkingDirectory 
= "C:\\mysql";
            shortcut.WindowStyle 
= 7;
            shortcut.Description 
= "dbChecked";
            shortcut.IconLocation 
= System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();            
           
        }


    }

}

注:需引用COM组件"Windows Script Host Object Model"
posted @ 2007-05-26 22:36  yongwnet  阅读(369)  评论(0编辑  收藏  举报