[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] [已解决]“求恢复链接文件夹的快捷方式”备份已由版主写好了,代码在15楼。

本帖最后由 zhangop9 于 2011-9-9 23:01 编辑

“用VBS按需批量创建快捷方式”在网上找到的运行错误,求高手改一下方便系统重装时恢复快捷方式。
  1. "F:\GreenTools\系统工具\CloseMonitor.scr'
  2. "#F:\GreenTools\TextTools\UltraEdit16\Uedit32.exe
  3. "F:\GreenTools\VirtualTools\VMware7\vmware.exe"
  4. "F:\GreenTools\Devtools\MyEclipse8\MyEclipse 8.x Latest\myeclipse.exe"
  5. "F:\GreenTools\网络工具\comunication\QQ2010\Bin\QQ.exe"
  6. "F:\GreenTools\网络工具\FlashXP3.6\flashfxp.exe"
  7. "F:\GreenTools\通讯\G3 eWalk\G3 eWalk.exe"
  8. "F:\GreenTools\Devtools\VC++6\Common\MSDev98\Bin\MSDEV.EXE"
  9. "===================================================
  10. 'Option Explicit
  11. Const ForReading = 1
  12. Const isCrerateShortcut=1
  13. "参数说明:1创建快捷方式;0删除快捷方式
  14. Set objFSO = CreateObject("Scripting.FileSystemObject")
  15. Set objTextFile = objFSO.OpenTextFile("添加常用应用程序到桌面图标.vbs", ForReading)
  16. Do Until objTextFile.AtEndOfStream
  17.   Dim strNextLine
  18.   Dim spIndex,program,path,pname,ShortcutName
  19.   Dim WshShell
  20. set WshShell = WScript.CreateObject("WScript.Shell")
  21.   "
  22.   strNextLine = objTextFile.Readline
  23.   strNextLine = Mid(strNextLine,2,Len(strNextLine))
  24.   If(InStr(strNextLine,"=====")<>0) Then
  25.    Exit Do
  26.   End If
  27. spIndex=InStr(strNextLine,"#")
  28. If (spIndex=0) Then
  29. part=split(strNextLine,"\")
  30. program=strNextLine
  31. pname=part(UBound(part))
  32. path=Mid(strNextLine,1,InStr(strNextLine,pname)-1)
  33. ShortcutName=Mid(pname,1,InStr(pname,".")-1)
  34. "MsgBox ShortcutName
  35. "下面是创建或删除快捷方式
  36. strDesktop = WshShell.SpecialFolders("Desktop")
  37. If(isCrerateShortcut=1)Then "创建
  38. set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & ShortcutName & ".lnk") "快捷方式的名字
  39. oShellLink.TargetPath = program "快捷方式里的“目标”
  40. oShellLink.WindowStyle = 1 "快捷方式里的“运行方式”:参数1默认窗口激活,参数3最大化激活,参数7最小化
  41. oShellLink.WorkingDirectory =path "快捷方式里的“起始位置”
  42. oShellLink.Description = "该快捷方式由VBS添加" "快捷方式里的“备注”
  43. oShellLink.Save
  44. ElseIf(isCrerateShortcut=0)Then "删除
  45. objFSO.DeleteFile strDesktop & "\" & ShortcutName & ".lnk"
  46. End If
  47. End If
  48. Loop
  49. objTextFile.Close
复制代码
1

评分人数

    • broly: 感谢给帖子标题标注[已解决]字样PB + 2

求高手看一下!!!!

TOP

  1. 'F:\GreenTools\系统工具\CloseMonitor.scr'
  2. '#F:\GreenTools\TextTools\UltraEdit16\Uedit32.exe
  3. 'F:\GreenTools\VirtualTools\VMware7\vmware.exe"
  4. 'F:\GreenTools\Devtools\MyEclipse8\MyEclipse 8.x Latest\myeclipse.exe"
  5. 'F:\GreenTools\网络工具\comunication\QQ2010\Bin\QQ.exe"
  6. 'F:\GreenTools\网络工具\FlashXP3.6\flashfxp.exe"
  7. 'F:\GreenTools\通讯\G3 eWalk\G3 eWalk.exe"
  8. 'F:\GreenTools\Devtools\VC++6\Common\MSDev98\Bin\MSDEV.EXE"
  9. '===================================================
  10. 'Option Explicit
  11. Const ForReading = 1
  12. Const isCrerateShortcut=1
  13. '参数说明:1创建快捷方式;0删除快捷方式
  14. Set objFSO = CreateObject("Scripting.FileSystemObject")
  15. Set objTextFile = objFSO.OpenTextFile("添加常用应用程序到桌面图标.vbs", ForReading)
  16. Do Until objTextFile.AtEndOfStream
  17.   Dim strNextLine
  18.   Dim spIndex,program,path,pname,ShortcutName
  19.   Dim WshShell
  20. set WshShell = WScript.CreateObject("WScript.Shell")
  21.   '
  22.   strNextLine = objTextFile.Readline
  23.   strNextLine = Mid(strNextLine,2,Len(strNextLine))
  24.   If(InStr(strNextLine,"=====")<>0) Then
  25.    Exit Do
  26.   End If
  27. spIndex=InStr(strNextLine,"#")
  28. If (spIndex=0) Then
  29. part=split(strNextLine,"\")
  30. program=strNextLine
  31. pname=part(UBound(part))
  32. path=Mid(strNextLine,1,InStr(strNextLine,pname)-1)
  33. ShortcutName=Mid(pname,1,InStr(pname,".")-1)
  34. 'MsgBox ShortcutName
  35. '下面是创建或删除快捷方式
  36. strDesktop = WshShell.SpecialFolders("Desktop")
  37. If(isCrerateShortcut=1)Then '创建
  38. set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & ShortcutName & ".lnk") '快捷方式的名字
  39. oShellLink.TargetPath = program '快捷方式里的“目标”
  40. oShellLink.WindowStyle = 1 '快捷方式里的“运行方式”:参数1默认窗口激活,参数3最大化激活,参数7最小化
  41. oShellLink.WorkingDirectory =path '快捷方式里的“起始位置”
  42. oShellLink.Description = "该快捷方式由VBS添加" '快捷方式里的“备注”
  43. oShellLink.Save
  44. ElseIf(isCrerateShortcut=0)Then'删除
  45. objFSO.DeleteFile strDesktop & "\" & ShortcutName & ".lnk"
  46. End If
  47. End If
  48. Loop
  49. objTextFile.Close
复制代码
---学无止境---

TOP

你要实现些什么样的功能啊?请详细说明
---学无止境---

TOP

我的收藏文件夹下,链接文件夹中有很多目录,目录中有很多快捷方式,我想以文本的方式备份,下次系统重做系统后能恢复回来,不是简单的copy

TOP

回复 5# zhangop9


    以文本的形式备份?以后说明你的需求时最好把例子列举出来,帮助别人理解
---学无止境---

TOP

F:\GreenTools\系统工具\CloseMonitor.scr

F:\GreenTools\TextTools\UltraEdit16\Uedit32.exe

F:\GreenTools\VirtualTools\VMware7\vmware.exe"

"F:\GreenTools\Devtools\MyEclipse8\MyEclipse 8.x Latest\myeclipse.exe"

"F:\GreenTools\网络工具\comunication\QQ2010\Bin\QQ.exe"

"F:\GreenTools\网络工具\FlashXP3.6\flashfxp.exe"

"F:\GreenTools\通讯\G3 eWalk\G3 eWalk.exe"

"F:\GreenTools\Devtools\VC++6\Common\MSDev98\Bin\MSDEV.EXE"

TOP

楼主,我投降,我不得不承认自己智商不够高,看不懂你想要表达什么。
---学无止境---

TOP

"%HOMEPATH%\Favorites\链接"
备份上面路径下的所有快捷方式,以文本方式,还原时以文本为根据还原

TOP

回复 9# zhangop9


    里面的快捷方式的后缀是什么?.url?全是网址的快捷方式?你好给给我举个例子吧
---学无止境---

TOP

里面的快捷方式的后缀是.lnk,有子文件夹"每月工作"、“日常工作”等等

TOP

  1. Dim wsh,wshSysEnv,objLink
  2. Dim objFSO,subFolders,subFolder,Folder,Files,File
  3. Dim strHOMEDRIVE,strHOMEPATH
  4. Dim strBackup,strLnkPath,strWorkingDirectory,strTargetPath
  5. Set wsh = CreateObject("WScript.Shell")
  6. Set wshSysEnv = wsh.Environment("Process")
  7. strHOMEDRIVE = wshSysEnv("HOMEDRIVE")
  8. strHOMEPATH = wshSysEnv("HOMEPATH")
  9. Set objFSo = CreateObject("Scripting.FileSystemObject")
  10. FindLinks(strHOMEDRIVE & strHOMEPATH & "\Favorites\链接")
  11. Set File = objFSO.CreateTextFile("LinkBackUp.txt",True)
  12. File.Write strBackup
  13. File.Close
  14. Set wsh = Nothing
  15. Set wshSysEnv = Nothing
  16. Set objFSO = Nothing
  17. Set Folder = Nothing
  18. Set subFolders = Nothing
  19. Set Files = Nothing
  20. Set File = Nothing
  21. MsgBox "Backup Succeed!",,"TIPs"
  22. Sub FindLinks(strPath)
  23.   Set Folder = objFSO.GetFolder(strPath)
  24.   Set subFolders = Folder.subFolders
  25.   Set Files = Folder.Files
  26.   For Each File In Files
  27. If LCase(objFSO.GetExtensionName(File.Path)) = "lnk" Then
  28. Set objLink = wsh.CreateShortcut(File.Path)
  29. strWorkingDirectory = objLink.WorkingDirectory
  30. strTargetPath = objLink.TargetPath
  31. strBackup = strBackup & _
  32. "LinkPath:" & File.Path & vbCrLf & _
  33. "LinkTargetPath:" & strTargetPath & vbCrLf & _
  34. "LinkWorkingDirectory:" & strTargetPath _
  35. & vbCrLf & vbCrLf
  36. End If
  37.   Next
  38.   For Each subFolder In subFolders
  39.       FindLinks(subFolder.Path)
  40.   Next
  41. End Sub
复制代码
---学无止境---

TOP

本帖最后由 zhangop9 于 2011-9-9 08:49 编辑

备份没有问题,如何恢复到原处,最好是个vbs能一键恢复回去

TOP

回复 13# zhangop9


    晚上先
---学无止境---

TOP

备份部分(12楼代码有点错了,现在改回来):
  1. Dim wsh,wshSysEnv,objLink
  2. Dim objFSO,subFolders,subFolder,Folder,Files,File
  3. Dim strHOMEDRIVE,strHOMEPATH
  4. Dim strBackup,strLnkPath,strWorkingDirectory,strTargetPath
  5. Set wsh = CreateObject("WScript.Shell")
  6. Set wshSysEnv = wsh.Environment("Process")
  7. strHOMEDRIVE = wshSysEnv("HOMEDRIVE")
  8. strHOMEPATH = wshSysEnv("HOMEPATH")
  9. Set objFSo = CreateObject("Scripting.FileSystemObject")
  10. FindLinks(strHOMEDRIVE & strHOMEPATH & "\Favorites\链接")
  11. Set File = objFSO.CreateTextFile("LinkBackUp.txt",True)
  12. File.Write strBackup
  13. File.Close
  14. Set wsh = Nothing
  15. Set wshSysEnv = Nothing
  16. Set objFSO = Nothing
  17. Set Folder = Nothing
  18. Set subFolders = Nothing
  19. Set Files = Nothing
  20. Set File = Nothing
  21. MsgBox "Backup Succeed!",,"TIPs"
  22. Sub FindLinks(strPath)
  23.   Set Folder = objFSO.GetFolder(strPath)
  24.   Set subFolders = Folder.subFolders
  25.   Set Files = Folder.Files
  26.   For Each File In Files
  27.         If LCase(objFSO.GetExtensionName(File.Path)) = "lnk" Then
  28.                 Set objLink = wsh.CreateShortcut(File.Path)
  29.                 strWorkingDirectory = objLink.WorkingDirectory
  30.                 strTargetPath = objLink.TargetPath
  31.                 strBackup = strBackup & _
  32.                         "LinkPath:" & File.Path & vbCrLf & _
  33.                         "LinkTargetPath:" & strTargetPath & vbCrLf & _
  34.                         "LinkWorkingDirectory:" & strWorkingDirectory _
  35.                         & vbCrLf & vbCrLf
  36.         End If
  37.   Next
  38.   For Each subFolder In subFolders
  39.       FindLinks(subFolder.Path)
  40.   Next
  41. End Sub
复制代码
还原部分:
  1. Dim wsh,objFSO,f,Folder,strTxtLine,ary,objLink
  2. Dim strLnkPath,strWorkingDirectory,strTargetPath
  3. set wsh = CreateObject("WScript.Shell")
  4. Set objFSO = CreateObject("Scripting.FileSystemObject")
  5. Set f = objFSO.OpenTextFile("LinkBackUp.txt",1)
  6. While Not f.AtEndOfStream
  7. strTxtLine = f.ReadLine
  8. If strTxtLine <> "" Then
  9. ary = Split(strTxtLine,":",-1)
  10. ReDim Preserve ary(3)
  11. Select Case ary(0)
  12. Case "LinkPath"
  13. strLnkPath = ary(1) & ":" & ary(2)
  14. Case "LinkTargetPath"
  15. strTargetPath = ary(1) & ":" & ary(2)
  16. Case "LinkWorkingDirectory"
  17. strWorkingDirectory = ary(1) & ":" & ary(2)
  18. CreateLnk strLnkPath,strTargetPath,strWorkingDirectory
  19. End Select
  20. End If
  21. Wend
  22. f.Close
  23. Set wsh = Nothing
  24. Set objFSO = Nothing
  25. Set f= Nothing
  26. MsgBox "Restore Succeed!",Tips
  27. Sub CreateLnk(strLnkPath,strTargetPath,strWorkingDirectory)
  28. Folder = Left(strLnkPath,InStrRev(strLnkPath,"\"))
  29. If Not objFSO.FolderExists(Folder) Then
  30. objFSO.CreateFolder Folder
  31. End If
  32. Set objLink = wsh.CreateShortcut(strLnkPath)
  33. objLink.TargetPath = strTargetPath
  34. objLink.WorkingDirectory = strWorkingDirectory
  35. objLink.Save
  36. Set objLink = Nothing
  37. End Sub
复制代码
---学无止境---

TOP

返回列表