vbs:bulkshortcutrebuild
Differences
This shows you the differences between two versions of the page.
Last revisionBoth sides next revision | |||
vbs:bulkshortcutrebuild [2014/04/29 12:59] – created gfsadministrator | vbs:bulkshortcutrebuild [2014/04/29 13:03] – gfsadministrator | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | Ottiene le informazioni sulla scheda | + | Modifica il puntamento dei collegamenti alle cartelle |
- | <file vb localhostinfo.vbs> | + | Richiamo del VBS tramite batch: |
- | dim NIC1, Nic, StrIP, CompName | + | |
- | Set NIC1 = GetObject(" | + | |
- | For Each Nic in NIC1 | + | |
- | if Nic.IPEnabled then | + | |
- | StrIP = Nic.IPAddress(i) | + | |
- | CompName = WshNetwork.Computername | + | |
- | Dim WMI, Configs, Config, Adapters, Adapter | + | |
- | Set WMI = GetObject(" | + | |
- | Set Configs = WMI.ExecQuery(" | + | |
- | For Each Config In Configs | + | |
- | Set Adapters = WMI.AssociatorsOf(" | + | |
- | For Each Adapter In Adapters | + | |
- | VPNIP = Config.IPAddress(0) | + | |
- | Next | + | |
- | Next | + | |
- | MsgBox "IP Address: "& | + | |
- | & "VPN IP Address: "& | + | |
- | & " | + | |
- | wscript.quit | + | |
- | end if | + | |
- | next | + | < |
+ | cscript \\%USERDNSDOMAIN%\netlogon\scripts\BulkShortcut.vbs //B " | ||
+ | |||
+ | <file vb BulkShortcut.vbs> | ||
+ | ' MODIFICA IN BULK DEGLI SHORTCUT | ||
+ | ' Codice originale : Rob Dunn | ||
+ | ' Modificato da : GSolone | ||
+ | ' Ultima modifica : 29-04-2014 (rev1) | ||
+ | ' ------------------------------------------------------------------- | ||
+ | ' MODIFICHE | ||
+ | ' | ||
+ | |||
+ | Dim Silent, CurTime, sIsDrive | ||
+ | Dim newlink, oldlink, oldfull, fullname, oldfile, bgcolor | ||
+ | Dim CheckFolder, | ||
+ | Dim w, ws | ||
+ | const ForReading = 1 | ||
+ | const ForWriting = 2 | ||
+ | const ForAppending = 8 | ||
+ | |||
+ | 'On Error Resume Next | ||
+ | |||
+ | 'Find current time that the script runs | ||
+ | set wso = CreateObject(" | ||
+ | set fso = CreateObject(" | ||
+ | |||
+ | ' | ||
+ | Set objArgs = WScript.Arguments | ||
+ | |||
+ | 'pull the system' | ||
+ | ' for the output file and WINDIR to figure out the default | ||
+ | ' location of user's desktop folder - whether 9x or NT/2k/XP) | ||
+ | Set WshSysEnv = wso.Environment(" | ||
+ | |||
+ | 'pull the system' | ||
+ | userprofile = wso.ExpandEnvironmentStrings(" | ||
+ | |||
+ | 'set your variables here | ||
+ | ' | ||
+ | ' 0 - verbose | ||
+ | ' 1 - turns off verification prompts | ||
+ | ' 2 - turns off verification and initial config prompts | ||
+ | ' | ||
+ | ' | ||
+ | ' above server vars are needed only for when silent = 2 | ||
+ | ' | ||
+ | ' place of all the code after the equal sign (i.e. | ||
+ | ' outputfile = " | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | Silent = 2 | ||
+ | ChangePathFrom = objArgs(0) | ||
+ | ChangePathTo = objArgs(1) | ||
+ | OutputFile = WshSysEnv(" | ||
+ | RootFolder = objArgs(2) | ||
+ | ' | ||
+ | |||
+ | CurTime = Now | ||
+ | OSType = WshSysEnv(" | ||
+ | WinDirectory = WshSysEnv(" | ||
+ | |||
+ | |||
+ | If Silent > 0 Then | ||
+ | CheckFolder = RootFolder | ||
+ | Else | ||
+ | |||
+ | End If | ||
+ | |||
+ | If CheckFolder = "" | ||
+ | |||
+ | If OSType <> " | ||
+ | ' | ||
+ | CheckFolder = Windirectory & " | ||
+ | Else | ||
+ | ' | ||
+ | CheckFolder = userprofile & " | ||
+ | End If | ||
+ | End If | ||
+ | |||
+ | 'check to see if ouputfile exists or not, deletes it if it does | ||
+ | If CheckFileExists(OutputFile) Then | ||
+ | Set oldfile = fso.GetFile(OutputFile) | ||
+ | oldfile.Delete | ||
+ | Else | ||
+ | ' | ||
+ | End If | ||
+ | |||
+ | 'Start writing the HTM Log file... | ||
+ | Set w = fso.OpenTextFile (OutputFile, | ||
+ | w.Writeline ("< | ||
+ | w.Writeline ("< | ||
+ | & CheckFolder & "</ | ||
+ | w.Writeline ("< | ||
+ | w.Writeline ("< | ||
+ | w.Writeline ("< | ||
+ | w.Writeline ("< | ||
+ | w.Writeline ("</ | ||
+ | w.Writeline ("</ | ||
+ | w.Writeline ("< | ||
+ | & " | ||
+ | & CheckFolder & " <font face=Arial color=# | ||
+ | & " searching recursively at " & CurTime & "</ | ||
+ | w.WriteLine ("< | ||
+ | w.WriteLine ("< | ||
+ | & "</ | ||
+ | w.WriteLine ("< | ||
+ | & "</ | ||
+ | w.WriteLine ("< | ||
+ | & "</ | ||
+ | w.WriteLine ("</ | ||
+ | |||
+ | If ChangePathFrom = "" | ||
+ | wscript.echo "You have not specified a source string to change." | ||
+ | Call Cserver | ||
+ | ElseIf ChangePathTo = "" | ||
+ | wscript.echo "You have not specified a new string name to"_ | ||
+ | & " replace" | ||
+ | Call Nserver | ||
+ | ElseIf CheckFolder = "" | ||
+ | wscript.echo "You must specify a root folder to begin your" | ||
+ | & " search from." | ||
+ | Call CFolder | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | ModifyLinks CheckFolder | ||
+ | |||
+ | Sub ModifyLinks (foldername) | ||
+ | |||
+ | dim file 'for stepping through the files collection | ||
+ | dim folder | ||
+ | dim fullname | ||
+ | dim link ' | ||
+ | |||
+ | ' | ||
+ | For each file in fso.GetFolder(foldername).Files | ||
+ | |||
+ | ' | ||
+ | If strcomp(right(file.name, | ||
+ | |||
+ | ' | ||
+ | | ||
+ | |||
+ | ' | ||
+ | set link = wso.CreateShortcut(fullname) | ||
+ | | ||
+ | |||
+ | | ||
+ | oldlink = targetpath | ||
+ | newlink = "Not Updated" | ||
+ | |||
+ | ' | ||
+ | ' troubleshooting the script). | ||
+ | 'If Silent = 0 Then | ||
+ | ' | ||
+ | '& | ||
+ | 'End If | ||
+ | |||
+ | 'If the current server (one you want to change) is found in the | ||
+ | ' target path, then run the following code | ||
+ | If InStr(1, targetpath, ChangePathFrom) > 0 Then | ||
+ | sChangeTargetTo = "" | ||
+ | sChangePathTo = "" | ||
+ | |||
+ | 'Set numerical length of full target path | ||
+ | VarLengthPath = Len(targetpath) | ||
+ | 'Set numerical length of ChangePathFrom | ||
+ | VarLengthCPF = Len(ChangePathFrom) | ||
+ | |||
+ | 'Find out what's between character 0 and where changepathfrom starts | ||
+ | VarBeginPath = InStr(1, targetpath, ChangePathFrom) | ||
+ | |||
+ | ' | ||
+ | 'This is so you will have a ' | ||
+ | 'UNC to replace - there shouldn' | ||
+ | '' | ||
+ | VarBeginPath = VarBeginPath - 1 | ||
+ | |||
+ | ' | ||
+ | BeginPath = Null | ||
+ | BeginPath = Left(targetpath, | ||
+ | |||
+ | ' | ||
+ | |||
+ | 'Find out how many characters are left after subtracting the beginpath | ||
+ | 'and search strings from the whole path | ||
+ | VarEndPath = VarLengthPath - (VarBeginPath + VarLengthCPF) | ||
+ | |||
+ | 'Find out what text appears after the search string | ||
+ | EndPath = Right(targetpath, | ||
+ | ' | ||
+ | |||
+ | workingpath = link.workingdirectory | ||
+ | |||
+ | 'Set variable to text before/ | ||
+ | ' | ||
+ | 'or c: | ||
+ | sChangePathTo = BeginPath & ChangePathTo & EndPath | ||
+ | ' | ||
+ | |||
+ | 'If there is no working directory, then text will show 'not set' during | ||
+ | ' | ||
+ | If workingpath = "" | ||
+ | workingpath = "not set" | ||
+ | End If | ||
+ | |||
+ | |||
+ | 'if you are running in verbose mode, you will be prompted with | ||
+ | 'each shortcut and working folder. | ||
+ | If Silent = 0 Then | ||
+ | MyVar = MsgBox ("Path contains " & Chr(34) & ChangePathFrom & " | ||
+ | & " | ||
+ | & targetpath & " | ||
+ | & workingpath & " | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | 'If there is a working dir, then run following code | ||
+ | If workingpath <> "not set" Then | ||
+ | |||
+ | VarBeginPath = InStr(1, workingpath, | ||
+ | If VarBeginPath > 0 Then | ||
+ | VarBeginPath = VarBeginPath - 1 | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | BeginPath = Null | ||
+ | ' | ||
+ | BeginPath = Left(workingpath, | ||
+ | ' | ||
+ | |||
+ | 'Set numerical length of working directory | ||
+ | VarLengthWorking = Len(link.workingdirectory) | ||
+ | |||
+ | VarEndPath = VarLengthWorking - (VarBeginPath + VarLengthCPF) | ||
+ | ' | ||
+ | '& | ||
+ | ' | ||
+ | '& | ||
+ | ' | ||
+ | |||
+ | If VarEndPath >= 0 Then | ||
+ | EndPath = Right(workingpath, | ||
+ | sChangeTargetTo = BeginPath & ChangePathTo & EndPath | ||
+ | |||
+ | ' | ||
+ | WorkingMSG = "Also change working directory to " & sChangeTargetTo & "?" | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | |||
+ | Else | ||
+ | link.workingdirectory = "" | ||
+ | WorkingMSG = "No working directory will be set at this time." | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | '& | ||
+ | |||
+ | ' | ||
+ | If Silent = 0 Then | ||
+ | ModifyPath = InputBox (" | ||
+ | & VBCRLF & " | ||
+ | & "and replace with " & sChangePathTo & "?" | ||
+ | & WorkingMSG,"" | ||
+ | & "Type ' | ||
+ | | ||
+ | | ||
+ | End If | ||
+ | If ModifyPath = " | ||
+ | bgcolor = "# | ||
+ | ' | ||
+ | link.targetpath = Chr(34) & sChangePathTo & Chr(34) | ||
+ | |||
+ | newlink = link.targetpath | ||
+ | |||
+ | ' | ||
+ | If VarLengthWorking <> "" | ||
+ | ' | ||
+ | ' \\ChangePathToname\workingpath | ||
+ | link.workingdirectory = Chr(34) & sChangeTargetTo & Chr(34) | ||
+ | End If | ||
+ | |||
+ | ' | ||
+ | link.save | ||
+ | |||
+ | 'If answer above is anything but yes, the script will proceed | ||
+ | ' to the next shortcut | ||
+ | |||
+ | Else | ||
+ | |||
+ | End if | ||
+ | |||
+ | ' | ||
+ | MyPos = 0 | ||
+ | MyPosEnd = 0 | ||
+ | End if | ||
+ | |||
+ | 'write output to logfile | ||
+ | Call WriteEntry | ||
+ | End If | ||
+ | |||
+ | | ||
+ | |||
+ | ' | ||
+ | For each folder in fso.GetFolder(foldername).Subfolders | ||
+ | call ModifyLinks(folder.path) | ||
+ | |||
+ | | ||
+ | End Sub | ||
+ | |||
+ | ' | ||
+ | ' Function WriteEntry to write change history to logfile in outputfile path | ||
+ | ' | ||
+ | |||
+ | Function WriteEntry | ||
+ | If newlink <> " | ||
+ | w.WriteLine ("< | ||
+ | w.WriteLine ("< | ||
+ | & oldfull & "</ | ||
+ | w.WriteLine ("< | ||
+ | & oldlink & "</ | ||
+ | w.WriteLine ("< | ||
+ | & newlink & "</ | ||
+ | w.WriteLine ("</ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | End If | ||
+ | End Function | ||
+ | |||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | Function CheckFileExists(sFileName) | ||
+ | |||
+ | Dim FileSystemObject | ||
+ | Set FileSystemObject = CreateObject(" | ||
+ | If (FileSystemObject.FileExists(sFileName)) Then | ||
+ | CheckFileExists = True | ||
+ | Else | ||
+ | CheckFileExists = False | ||
+ | End If | ||
+ | Set FileSystemObject = Nothing | ||
+ | End Function | ||
+ | |||
+ | w.Writeline ("</ | ||
+ | |||
+ | 'if silent = 2, then it will not open the log file | ||
+ | If Silent <= 1 Then | ||
+ | 'set command variable with path in quotes (for long filenames) | ||
+ | Command = Chr(34) & OutputFile & Chr(34) | ||
+ | |||
+ | 'run htm file in your default browser | ||
+ | wso.Run Command | ||
+ | End If | ||
</ | </ |