zoukankan      html  css  js  c++  java
  • C# 快捷方式 自启动 PHP

    C#创建快捷方式

    需要先引用COM组件 Interop.IWshRuntimeLibrary.dll 如下图

    代码

    private void CreateLnk(string lnkPath)
    {
    	if (!System.IO.File.Exists(lnkPath))
    	{
    		IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
    		IWshRuntimeLibrary.IWshShortcut shortCut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(lnkPath);
    		shortCut.TargetPath = Application.ExecutablePath;
    		shortCut.WindowStyle = 1;
    		shortCut.Description = Application.ProductName + Application.ProductVersion;
    		shortCut.IconLocation = Application.ExecutablePath;
    		shortCut.WorkingDirectory = Application.StartupPath;
    		shortCut.Save();
    	}
    }
    

    获取桌面路径

    string lnkPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + Application.ProductName + ".lnk";
    

    获取启动文件夹路径

    string lnkPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName + ".lnk";
    

    操作注册表实现自启动

    操作方法就是给注册表的 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 添加程序路径

    RegistryKey key = Registry.LocalMachine;
    key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
    key.SetValue(Application.ProductName, Application.ExecutablePath);
    

    注意此方法在Win7下测试报错!System.UnauthorizedAccessException: 试图执行未经授权的操作。


    创建URL快捷方式

    string deskDir = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    using (StreamWriter writer = new StreamWriter(deskDir + "\\aaaa.url"))
    {
    	writer.WriteLine("[InternetShortcut]");
    	writer.WriteLine("URL=http://www.163.com/");
    	writer.Flush();
    }
    

    示例下载:https://files.cnblogs.com/zjfree/linkTo.rar

    运行环境:WIN2003 + VS2005


    欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
  • 相关阅读:
    jmeter-测试webservice接口
    Python
    Mysql:PDBC(Python操作数据库-mysql)
    Mysql: JDBC(Java 操作数据库-mysql)
    Mysql:事务、索引(了解)
    Mysql:DQL(Data Query Language
    Mysql:DML(Data Manipulation Language- 数据操作语言)
    Mysql:列类型,表类型,常用字段属性
    Mysql:DDL(Data Definition Language-数据定义语言)
    Mysql:Centos7安装Mysql5.6
  • 原文地址:https://www.cnblogs.com/zjfree/p/1937970.html
Copyright © 2011-2022 走看看