• 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/ ]
  • 相关阅读:
    常用操作之增、删、改、查
    文本编辑器相关操作
    关于Secondary NameNode
    hive基础概念总结(1)
    Shell 十三问[转]
    《SQL Server 2012 Tutorials Analysis Services Multidimensional Modeling》读后感
    HDFS随笔(1)
    Hue for Apache Hadoop
    大数据面试题总结
    关于数据倾斜
  • 原文地址:https://www.cnblogs.com/zjfree/p/1937970.html
Copyright © 2020-2023  润新知