最近需要更新域里面所有PC的快捷方式,所以需要写个VBS的脚本用于设定在开机脚本里,需要实现的功能如下:
1.删除旧的程式,旧的快捷方式
2.将程序拷贝到指定目录
3.建立新的快捷方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
On Error Resume Next Dim file1, file2,fso, shortcutfile,FilePath, WSHShell, DesktopPath, MyShortcut set fso = CreateObject("Scripting.FileSystemObject") Set WSHShell=Wscript.createObject("Wscript.shell") Set WSHNet = WScript.CreateObject("WScript.Network") SourceFile = "\\FileServer\NewMES.exe" '******************************************************** 'Create by Carl Chen '******************************************************** If fso.FolderExists("C:\MiniMES") = "True" Then fso.copyfile SourceFile, "C:\MiniMES\" If fso.fileExists("c:\MiniMES\MES.exe") Then fso.deletefile "C:\MiniMES\MES.exe" End If Else fso.createFolder("C:\MiniMES") fso.copyfile SourceFile, "C:\MiniMES\" End If UserProgramPath = WSHShell.SpecialFolders("Programs") UserDesktopPath = WSHShell.SpecialFolders("Desktop") ProgramPath = WSHShell.SpecialFolders("AllUsersPrograms") DesktopPath = WSHShell.SpecialFolders("AllUsersDesktop") If fso.fileExists(ProgramPath & "\MES.lnk") Then fso.deletefile(ProgramPath & "\MES.lnk") End If If fso.fileExists(DesktopPath & "\MES.lnk") Then fso.deletefile(DesktopPath & "\MES.lnk") End If If fso.fileExists(UserDesktopPath & "\MES.lnk") Then fso.deletefile(UserDesktopPath & "\MES.lnk") End If If fso.fileExists(UserProgramPath & "\MES.lnk") Then fso.deletefile(UserProgramPath & "\MES.lnk") End If If fso.fileExists(UserDesktopPath & "\MES.lnk") Then fso.deletefile(UserDesktopPath & "\MES.lnk") End If If fso.fileExists(UserProgramPath & "\MES.lnk") Then fso.deletefile(UserProgramPath & "\MES.lnk") End If Set MyShortcutMega = WSHShell.CreateShortcut(ProgramPath & "\NewMES.lnk") MyShortcutMega.TargetPath = WSHShell.ExpandEnvironmentStrings("C:\MiniMES\NewMES.exe") MyShortcutMega.WorkingDirectory = WSHShell.ExpandEnvironmentStrings("c:\MiniMES\") MyShortcutMega.WindowStyle = 4 MyShortcutMega.IconLocation = WSHShell.ExpandEnvironmentStrings("c:\MiniMES\NewMES.exe, 0") MyShortcutMega.Save Set MyShortcutMega = WSHShell.CreateShortcut(DesktopPath & "\NewMES.lnk") MyShortcutMega.TargetPath = WSHShell.ExpandEnvironmentStrings("C:\MiniMES\NewMES.exe") MyShortcutMega.WorkingDirectory = WSHShell.ExpandEnvironmentStrings("c:\MiniMES\") MyShortcutMega.WindowStyle = 4 MyShortcutMega.IconLocation = WSHShell.ExpandEnvironmentStrings("c:\MiniMES\NewMES.exe, 0") MyShortcutMega.Save |