c#建立快捷方式代码并且设置为管理员权限

建立快捷方式比较简单,

  WshShell shell = new WshShell();

            //通过该对象的 CreateShortcut 方法来创建 IWshShortcut 接口的实例对象 
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "//ShortCut.lnk");

            //设置快捷方式的目标所在的位置(源程序完整路径) 
            shortcut.TargetPath = @"C:\Program Files\xxx.exe";

            //应用程序的工作目录 
            //当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。 
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;

            //目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化) 
            shortcut.WindowStyle = 1;

            //快捷方式的描述 
            shortcut.Description = "ChinaDforce YanMang";

            //可以自定义快捷方式图标.(如果不设置,则将默认源文件图标.) 
            //shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165"; 

            //设置应用程序的启动参数(如果应用程序支持的话) 
            //shortcut.Arguments = "/myword /d4s"; 

            //设置快捷键(如果有必要的话.) 
            //shortcut.Hotkey = "CTRL+ALT+D"; 

            //保存快捷方式 
            shortcut.Save();

设置为管理员运行权限需要点黑科技


 

   using (FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "//ShortCut.lnk", FileMode.Open, FileAccess.ReadWrite))
            {

                fs.Seek(21, SeekOrigin.Begin);

                fs.WriteByte(0x22);

            }
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值