AlexB Posted May 16, 2011 Posted May 16, 2011 Thanks, does this work with the Batch File or instead of please? It would work best when run after the batch file.
FN-GM Posted May 16, 2011 Author Posted May 16, 2011 (edited) It would work best when run after the batch file. Cheers, do you use the VBS script? Quick question. If a user installs some software and they have a redirected start menu. Would the shortcuts be placed into the redirected folder or would they show in the All users startmenu? Thanks Edited May 16, 2011 by FN-GM
AlexB Posted May 16, 2011 Posted May 16, 2011 Cheers, do you use the VBS script? No, I have no dead shortcuts Quick question. If a user installs some software and they have a redirected start menu. Would the shortcuts be placed into the redirected folder or would they show in the All users startmenu? Thanks Most likely the all users startmenu... but why would you allow users to install software?
FN-GM Posted May 16, 2011 Author Posted May 16, 2011 but why would you allow users to install software? My thoughts exactly.....
Freedom Posted May 17, 2011 Posted May 17, 2011 [ATTACH=CONFIG]10080[/ATTACH] You've got a spelling error in 'Macromedia Studio MX 2004' before some know it all kid spots it On another note I really need to do this to our network so when I get a chance I will start playing with the code you guys have already posted . Thanks for it! 1
FN-GM Posted May 17, 2011 Author Posted May 17, 2011 It would work best when run after the batch file. Both Work a treat thanks
FN-GM Posted May 17, 2011 Author Posted May 17, 2011 It would work best when run after the batch file. Daft question, how would i call the VBS script from the batch file please? Everywhere i put the line it doesnt seem to run Thanks
AlexB Posted May 18, 2011 Posted May 18, 2011 I believe cscript is the correct way to call vb scripts. You might also want to take a look at another very similar post. The tidy up script is a lot more fleshed out than the one above I wrote quickly at home the other day, but it does look rather similar
FN-GM Posted May 18, 2011 Author Posted May 18, 2011 I believe cscript is the correct way to call vb scripts. You might also want to take a look at another very similar post. The tidy up script is a lot more fleshed out than the one above I wrote quickly at home the other day, but it does look rather similar cheers will have a look.
FN-GM Posted May 19, 2011 Author Posted May 19, 2011 Bah, what can I say, the idea intrigued me! Anyway, this script will parse through the location defined in objStartFolder and look for any shortcuts pointing to locations beginning with sTargetStart and if they don't point to anything valid it deletes them. Afterwards it goes through and looks for empty folders and removes them too. As it is set atm it looks in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Applications" (After first checking it exists) for any shortcuts (.lnk) that point to a target starting with "C:\" and removes it if the target doesn't exist. I've hacked this together quite quickly, so don't expect anything pretty Set objFSO = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject("WScript.Shell") objStartFolder = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Applications" sTargetStart = "C:\" If objFSO.FolderExists(objStartFolder) Then ' Check for invalid shortcuts pointing to locations starting with sTargetStart Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files For Each objFile in colFiles CheckValid objFile Next CheckSubFoldersShortcuts objFSO.GetFolder(objStartFolder) ' Check for empty folders after clearing out invalid shortcuts CheckSubFoldersEmptyAndRemove objFSO.GetFolder(objStartFolder) Else 'msgbox objStartFolder & " does not exist" End If Sub CheckSubFoldersEmptyAndRemove(Folder) For Each Subfolder in Folder.SubFolders Set objFolder = objFSO.GetFolder(Subfolder.Path) If FolderEmpty(Subfolder.Path) Then 'msgbox "delete " & Subfolder.Path objFSO.DeleteFolder Subfolder.Path Else 'msgbox Subfolder.Path & " is occupied" CheckSubFoldersEmptyAndRemove Subfolder End If Next End Sub Sub CheckSubFoldersShortcuts(Folder) For Each Subfolder in Folder.SubFolders Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles CheckValid objFile Next CheckSubFoldersShortcuts Subfolder Next End Sub Sub CheckValid(objCheckFile) If LCase(objFSO.GetExtensionName(objCheckFile.name)) = "lnk" Then Set oLnk = oShell.CreateShortcut(objCheckFile.path) 'msgbox objCheckFile.Path 'msgbox oLnk.TargetPath If StrComp(LCase(Left(oLnk.TargetPath,Len(sTargetStart))),LCase(sTargetStart)) = 0 Then If objFSO.FileExists(oLnk.TargetPath) Then 'msgbox objCheckFile.path & " is a valid shortcut" Else 'msgbox objCheckFile.path & " is an invalid shortcut" objFSO.DeleteFile objCheckFile.path End If Else 'msgbox "Not local shortcut" End If End If End Sub Function FolderEmpty(strFolderPathName) Dim oFiles, oFile, oFolder, oSubFolders, oSubFolder Dim blnFileFound : blnFileFound = False Set oFolder = objFSO.GetFolder(strFolderPathName) Set oFiles = oFolder.Files If oFiles.Count > 1 Then FolderEmpty = False Exit Function ElseIf oFiles.Count = 1 Then For Each oFile In oFiles If oFile.Name <> "desktop.ini" Then FolderEmpty = False Exit Function End If Next End If Set oSubFolders = oFolder.SubFolders For Each oSubFolder In oSubFolders If Not FolderEmpty(oSubFolder.Path) Then FolderEmpty = False Exit Function End If Next FolderEmpty = True End Function I know my original script was batch, but I didn't think I could do this with batch, so vbs will have to do Every now and then the script is erroring throwing up access denied. It is then not deleting folders automatically. if i delete them manually its fine. Any thoughts please?
Steve21 Posted May 19, 2011 Posted May 19, 2011 Every now and then the script is erroring throwing up access denied. It is then not deleting folders automatically. if i delete them manually its fine. Any thoughts please? Any chance of getting the full error (or line), and/or files it fails on? And by any chance is the full filename over 250 chars long? If so you'd need to force it to be a shortpath. One thing I noticed aswell, if you're only having problems on a few files objFSO.DeleteFolder Subfolder.Path Is going to fail on read-only files, You'll need to do a force delete aka objFSO.DeleteFolder Subfolder.Path,True Might be worth trying that. Other options although I haven't checked all of it yet, is your script is modifying/opening a file when it's running. Thus locking it. If the above doesn't work, shout and I'll check rest. Steve 1
FN-GM Posted May 19, 2011 Author Posted May 19, 2011 objFSO.DeleteFolder Subfolder.Path,True That did the trick. Thanks
FN-GM Posted June 6, 2011 Author Posted June 6, 2011 Hi Guys, For network applications where do you put the shortcuts? If i put them in a redirected folder on the C Drive, when a laptop is taken home the start menu will freeze because the shortcuts lead to a path that the machine can't contact. How would you deal with it? Thanks
AlexB Posted June 7, 2011 Posted June 7, 2011 Hi Guys, For network applications where do you put the shortcuts? If i put them in a redirected folder on the C Drive, when a laptop is taken home the start menu will freeze because the shortcuts lead to a path that the machine can't contact. How would you deal with it? Thanks Hi @FN-GM We sync (one way sync) our P drive to all staff laptops so that these network apps are available at home. (P drive is the mapped drive to the network apps share)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now