C/C++教程

create shortcut and autorun program in Windows

本文主要是介绍create shortcut and autorun program in Windows,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  

 

For Current User:

  1. startup folder
    shell:startup

     

     

     

     

     

     

  2. Registry

     

     

     

     

     

     

     

     

For Local Machine:

  1. startup folder
    shell:common startup

     

     

  2. Registry

     

     

     

     

 

Create shortcut:

  1. cmd

     

     

     

     

     

     

     

     

     

     

  2. powershell
    # 通过new-object(cmdlet)创建com对象,类是WScript.shell
    $com=new-object -ComObject WScript.shell
    # 使用.NET框架System.Environment类的GetFolderPath静态方法取得common folder路径(desktop,windows,system32)
    $destFolder=[System.Environment]::GetFolderPath("commonstartup")
    # 调用com对象CreateShortcut
    $shortcut=$com.CreateShortcut("$destFolder\vmware-tray.lnk")
    # 设置TargePath, IconLocation属性
    $shortcut.TargetPath="C:\Program Files (x86)\VMware\VMware Workstation\vmware-tray.exe"
    $shortcut.IconLocation="C:\Program Files (x86)\VMware\VMware Workstation\ico\generic.ico"
    # 调用save方法, 生成快捷方式
    $shortcut.save()

     

这篇关于create shortcut and autorun program in Windows的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!