首页 > 其他分享 >使用VBS创建快捷方式的代码

使用VBS创建快捷方式的代码

时间:2024-04-16 18:23:24浏览次数:18  
标签:exe oShellLink WScript 代码 VBS set WshShell 快捷方式

                        <p>在网吧维护过程中经常要发送桌面快捷方式,有什么批处理的方式能便捷发送桌面快捷方式呢,就拿我这边网吧steam下发为例给大家一个参考,如果要使用直接复制下面代码改下具体参数就行了。代码如下:</p>
@echo off
::设置程序或文件的路径(必选)
set Program=D:\Program Files\Microvirt\MEmu\MEmu.exe

::设置启动参数(可选)
set Arguments=

::设置快捷方式名称(必选)
set LnkName=test

::设置程序的工作路径,一般为程序主目录,此项若留空,脚本将自行分析路径
set WorkDir=

::设置快捷方式显示的说明(可选)
set Desc=

if not defined WorkDir call:GetWorkDir "%Program%"
(echo Set WshShell=CreateObject("WScript.Shell"^)
echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)
echo Set oShellLink=WshShell.CreateShortcut(strDesKtop&amp;"%LnkName%.lnk")
echo oShellLink.TargetPath="%Program%"
echo oShellLink.Arguments="%Arguments%"
echo oShellLink.WorkingDirectory="%WorkDir%"
echo oShellLink.WindowStyle=1
echo oShellLink.Description="%Desc%"
echo oShellLink.Save)>makelnk.vbs
echo 桌面快捷方式创建成功!
makelnk.vbs
del /f /q makelnk.vbs
exit
goto :eof
:GetWorkDir
set WorkDir=%~dp1
set WorkDir=%WorkDir:~,-1%
goto :eof

VBS:

第1个是桌面上创建快捷方式的应用范例

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") :'特殊文件夹“桌面”
set oShellLink = WshShell.CreateShortcut(strDesktop & "\计算器.lnk")
oShellLink.TargetPath = "C:\Windows\System32\Calc.exe" : '目标
oShellLink.WindowStyle = 3 :'参数1默认窗口激活,参数3最大化激活,参数7最小化
oShellLink.Hotkey = "Ctrl+Alt+C" : '快捷键
oShellLink.IconLocation = "C:\Windows\System32\Calc.exe" : '图标
oShellLink.Description = "系统默认计算器" : '备注
oShellLink.WorkingDirectory = strDesktop : '起始位置
oShellLink.Save : '创建保存快捷方式

第2个是自定义目录位置上创建快捷方式的应用范例

Set WshShell = WScript.CreateObject("WScript.Shell")
set oShellLink = WshShell.CreateShortcut("C:\Documents and Settings\Administrator\计算器调试.lnk")
oShellLink.IconLocation = "C:\Documents and Settings\Administrator\Calc.exe" : '图标
oShellLink.TargetPath = "C:\Documents and Settings\Administrator\Calc.exe" : '目标
oShellLink.WorkingDirectory = "C:\Documents and Settings\Administrator\" : '起始位置
oShellLink.Hotkey = "Ctrl+Alt+C" : '快捷键
oShellLink.WindowStyle = 3 :'运行方式,参数1默认窗口激活,参数3最大化激活,参数7最小化
oShellLink.Description = "系统默认计算器" : '备注
oShellLink.Save : '创建保存快捷方式

以下内容另存为 XXX.js

也是bat中经常调用的vbs

var fso = new ActiveXObject("Scripting.FileSystemObject");
var shl = WScript.CreateObject("WScript.Shell");
var oUrl = shl.CreateShortcut("C:\Documents and Settings\Administrator\Favorites\\游戏菜单.lnk");
oUrl.TargetPath = "E:\\nbmsclient\\BarClientView.exe";
oUrl.IconLocation = "E:\\nbmsclient\\BarClientView.exe";
oUrl.WorkingDirectory = "E:\\nbmsclient";
oUrl.Save();

可以增加可判断系统板本的:

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\xxx系统.lnk")

Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.folderExists("C:\Program Files (x86)") Then '通过目录来判断是32位还是64位操作系统
oShellLink.TargetPath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" '目标
oShellLink.WorkingDirectory = "C:\Program Files (x86)\Google\Chrome\Application" '起始位置
Else
oShellLink.TargetPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
oShellLink.WorkingDirectory = "C:\Program Files\Google\Chrome\Application"
End If
oShellLink.Arguments = "http://192.168.0.1:8080/xxx/" '运行参数
oShellLink.WindowStyle = 1 '参数1默认窗口激活,参数3最大化激活,参数7最小化
oShellLink.Hotkey = "" '快捷键
oShellLink.IconLocation = "C:\Program Files\ChromeStandaloneSetup\favicon.ico" '图标
oShellLink.Description = ""
oShellLink.Save '创建保存快捷方式

支持带参数的

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") '获取桌面路径
set oShellLink = WshShell.CreateShortcut(strDesktop & "\腾讯QQ.lnk")   '快捷方式将要保存到的完全路径
oShellLink.TargetPath = "http://www.hao123.com/" '快捷方式里的“目标”
oShellLink.Arguments = "/参数1 /参数2"    '“目标”的运行参数,无参数时,直接=""
oShellLink.WindowStyle = 1   '快捷方式里的“运行方式”
oShellLink.Hotkey = "Ctrl+Alt+e"   '快捷方式里的“快捷键”
oShellLink.IconLocation = "C:\Program Files\Tencent\qq.exe, 0"   '快捷方式的图标
oShellLink.Description = "腾讯QQ"   '快捷方式里的“备注”
oShellLink.WorkingDirectory = "C:\Program Files\Tencent"   '快捷方式里的“起始位置”
oShellLink.Save '使用以上的设置创建快捷方式

下面是其他网友的补充

利用VBS创建快捷方式详细说明

以下内容另存为 XXX.VBS

第1个是桌面上创建快捷方式的应用范例

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") :'特殊文件夹“桌面”
set oShellLink = WshShell.CreateShortcut(strDesktop & "\计算器.lnk")
oShellLink.TargetPath = "C:\Windows\System32\Calc.exe" : '目标
oShellLink.WindowStyle = 3 :'参数1默认窗口激活,参数3最大化激活,参数7最小化
oShellLink.Hotkey = "Ctrl+Alt+C" : '快捷键
oShellLink.IconLocation = "C:\Windows\System32\Calc.exe" : '图标
oShellLink.Description = "系统默认计算器" : '备注
oShellLink.WorkingDirectory = strDesktop : '起始位置
oShellLink.Save : '创建保存快捷方式

第2个是自定义目录位置上创建快捷方式的应用范例

Set WshShell = WScript.CreateObject("WScript.Shell")
set oShellLink = WshShell.CreateShortcut("C:\Documents and Settings\Administrator\计算器调试.lnk")
oShellLink.IconLocation = "C:\Documents and Settings\Administrator\Calc.exe" : '图标
oShellLink.TargetPath = "C:\Documents and Settings\Administrator\Calc.exe" : '目标
oShellLink.WorkingDirectory = "C:\Documents and Settings\Administrator\" : '起始位置
oShellLink.Hotkey = "Ctrl+Alt+C" : '快捷键
oShellLink.WindowStyle = 3 :'运行方式,参数1默认窗口激活,参数3最大化激活,参数7最小化
oShellLink.Description = "系统默认计算器" : '备注
oShellLink.Save : '创建保存快捷方式

以下内容另存为 XXX.js

第3个是自定义目录位置上以JS类创建快捷方式的应用范例

var fso = new ActiveXObject("Scripting.FileSystemObject");
var shl = WScript.CreateObject("WScript.Shell");
var oUrl = shl.CreateShortcut("C:\Documents and Settings\Administrator\Favorites\\游戏菜单.lnk");
oUrl.TargetPath = "E:\\nbmsclient\\BarClientView.exe";
oUrl.IconLocation = "E:\\nbmsclient\\BarClientView.exe";
oUrl.WorkingDirectory = "E:\\nbmsclient";
oUrl.Save();

从以上VBS和JS脚本对比我们可以发现有共同点之处,此类脚本开始都要声明以下内容以什么程序来解析运行,声明好了,接下去才是具体的步骤.

看如何在bat中调用vbs

@echo off
title 创业项目排行榜前十名http://www.piaodoo.com/ 桌面快捷方式创建工具!

>nul 2>&1 REG.exe query "HKU\S-1-5-19" || (
ECHO SET UAC = CreateObject("Shell.Application") > "%TEMP%\Getadmin.vbs"
ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\Getadmin.vbs"
"%TEMP%\Getadmin.vbs"
DEL /f /q "%TEMP%\Getadmin.vbs" 2>nul
Exit /b
)
set jb51name=Ditto3.lnk
set jb51path=%~dp0
set jb51exec=%~dp0Ditto.exe

mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""%jb51name%""):b.TargetPath=""%jb51exec%"":b.WorkingDirectory=""%jb51path%"":b.Save:close")

到此这篇关于使用VBS创建快捷方式的代码的文章就介绍到这了,更多相关VBS创建快捷方式内容请搜索创业项目排行榜前十名http://www.piaodoo.com/以前的文章或继续浏览下面的相关文章希望大家以后多多支持创业项目排行榜前十名http://www.piaodoo.com/!

                        友情连接: 

创业项目排行榜前十名

美文集

茂名一技

茂名一技

手游排行前十名

标签:exe,oShellLink,WScript,代码,VBS,set,WshShell,快捷方式
From: https://www.cnblogs.com/python1314520/p/18138892

相关文章

  • vbs实现web自动登录网站的方法
    <divid="navCategory"><h5class="catalogue">目录</h5><ulclass="first_class_ul"><li><ahref="#_label0">一,编写vbs</a></li><li><ahref="......
  • VBScript编写Windows防止锁屏脚本程序
    <divid="navCategory"><h5class="catalogue">目录</h5><ulclass="first_class_ul"><li><ahref="#_label0">背景介绍</a></li><li><ahref="#_......
  • VBS 批量Ping的项目实现
    <p>本文用vb编写的ping程序实现,具体如下:</p>'判断当前VBS脚本是否由CScript执行IfInStr(LCase(WScript.FullName),"cscript.exe")=0Then???'若不是由CScript执行,则使用CScript重新执行当前脚本???SetobjShell=CreateObject("Shell.Appl......
  • 教你用vbs实现微信自动发送消息功能
    <divid="navCategory"><h5class="catalogue">目录</h5><ulclass="first_class_ul"><li><ahref="#_label0">前言</a></li><li><ahref="#_la......
  • 抖音很火的vbs表白代码(简单实用!)
    <p>好玩的循环表白代码</p>1,右键->新建文本文件2,右键->编辑3,粘贴下面代码MsgBox"十年相遇"MsgBox"百年回眸"MsgBox"千年同船渡"MsgBox"我愿以万年的等待"MsgBox"......
  • 使用vbs脚本来监控windows服务器上的应用程序(不存在就启动)
    <p>这个vbs代码主要实现的功能就是运行该程序,就会在进程中出现一个wscript.exe它会每隔10s扫面一次进程中是否存在notepad.exe这个程序,不存在就启动。这个启动程序可能跟进程名不一样,好比tomcat应用,启动的是startup.bat,后台进程名为java.exe,这样就需要......
  • 2024 热门低代码平台盘点,十大主流低代码开发平台
    随着数字化转型的浪潮席卷全球,零代码平台成为企业快速构建应用程序的首选工具。国内低代码市场也呈现出蓬勃发展的态势,各种低代码平台如雨后春笋般涌现。本文将对2024年度国内低代码平台进行热度排名,以帮助企业和开发者更好地了解市场情况,选择适合自己的低代码平台。国内十大......
  • HTML代码第一课
    HTML可以用记事本来写代码,但是为了符合浏览器W3C规范,我们写代码都会用到专业的开发工具。写前端代码可以用Hbuilder和VisualStudio等等开发工具。不管是哪种开发工具,HTML的写法规范都是一样的,都包含以下基本格式:1.<DOCTYPEhtml>2. <html>3. <head>4. <metacharset="......
  • vscode 代码格式化设置
    1.设置默认格式化工具ctrl+shift+P,筛选“FormatDocument”,设置Prettier为默认、 2.设置保存自动格式化打开VSCode,并打开你想要格式化的代码文件。在菜单栏中,选择“文件”>“首选项”>“设置”(快捷键Ctrl+,)。在搜索框中输入“formatonsave”,然后点击“编辑insett......
  • 华为实习4.10机考第二题C++代码
    考的是简单的并查集这道题考法就是并查集,若两个图片相似度大于0,则将他们放到一个家族中,同时维护家族的相似度总和。注意M矩阵是对称矩阵,所以需要避免重复维护相似度,因此可以只针对M矩阵的下三角矩阵或上三角矩阵中的连接块,计算相似度总和;或考虑整个M矩阵,然后相似度总和除......