Option Explicit
Dim oldpath,newpath
'Dim 变量
'Set 赋值
'NoThing 释放内存
'Function 函数
'call 调用方法
'Sub 方法
'msgbox 消息框
''''''''''''''''说明'''''''''''''''''
'作用:批量修改快捷方式的“目标”和“起始位置”
'使用方法:和需要修改的快捷方式放在同一个文件夹执行
'''''''''''''''说明完'''''''''''''''''
oldpath = "C:\Users\Hos\AppData\Local\Youdao\Dict\Application" '设置原路径中将被替换的内容
newpath = "C:\Users\Hos\AppData\Local\Youdao\Dict\Application" '设置新路径中要使用的内容
Dim Wsh,fso
Set Wsh = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Dim ji_1,ji_2,Folder,res
ji_1 = 0
ji_2 = 0
'获取当前目录
Folder = Wsh.CurrentDirectory
if Ask("将要修改"&chr(34)& Folder &chr(34)&"里的快捷方式,是否继续") then
Dim f,fc,f1,ext
'获取当前目录的文件夹
Set f = fso.GetFolder(Folder)
'获取文件夹下的所有文件
Set fc = f.Files
For Each f1 in fc
'Ask("将要修改"&chr(34)& f1 &chr(34)&"里的快捷方式,是否继续")
'文件获取后缀名
ext = LCase(fso.GetExtensionName(f1))
'Ask("将要修改"&chr(34)& ext &chr(34)&"里的快捷方式,是否继续")
if ext = "lnk" then
ji_1 = ji_1 + 1
call Doit(f1)
end if
Next
end if
Set WSH = Nothing
msgbox "找到 "&ji_1&" 个快捷方式"&vbCrLf&"修改 "&ji_2&" 个快捷方式",64,"执行完毕!"
WScript.quit
Sub Doit(strlnk)
Dim oShlnk
Set oShlnk = Wsh.CreateShortcut(strlnk)
'Ask("开始目录"&chr(34)& oShLnk.WorkingDirectory &chr(34)&"\n")
'判断开始目录是不是旧目录
If Instr(oShLnk.WorkingDirectory,oldpath) > 0 Then
'替换链接程序
'Replace(父字符串,子字符串,用来替换子字符串的字符串)
oShLnk.TargetPath = Replace(oShLnk.TargetPath,oldpath,newpath)
'替换开始目录'
oShLnk.WorkingDirectory = Replace(oShLnk.WorkingDirectory,oldpath,newpath)
'Ask("目录"&chr(34)& ext &chr(34))
oShLnk.Save
ji_2 = ji_2 + 1
End If
Set oShLnk=NoThing
End Sub
Function Ask(strAction)
Dim intButton
'msgBox(提示字符串,对话框按钮形式,对话框标题)
intButton = MsgBox(strAction,vbQuestion + vbYesNo,"询问")
Ask = intButton = vbYes
End Function
【语言-JavaScript】windows 下修改快捷方式的 起始位置 和 目标 (vb脚本)
最新推荐文章于 2023-07-25 15:35:06 发布