rhodges Posted July 9, 2009 Posted July 9, 2009 Good Day Everyone, I am normally very good at finding .vbs files or .bat files and making them fit my need, but this one seems to have gotten the best of me.The Problem:1. Search for all instances of a particular desktop shortcut (file.url) and either replace it with an updated shortcut on the server or update the url address for each one2. All profiles under "Documents and Settings" must be searched and if the file exists either be updated or replaced (working with roaming and local profiles in the environment)3. Report all computers that have had this update in a directory on the server (capture the profiles that were touched if possible)3. Run either a .bat, .cmd, or .vbs as a Startup or Shutdown script so that it has System rights (working in a LUA environment)Here are the scripts that I have tried so far:.Vbs script=========================================================Dim CountCount = 0strComputer = "."Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") 'GetObject("winmgmts:" & strComputer & "{impersonationLevel=impersonate}!\\.\root\cimv2")Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_ShortcutFile Where FileName = 'file'")Set oWS = WScript.CreateObject("WScript.Shell")Set oFS = WScript.CreateObject("Scripting.FileSystemObject")For Each objItem in colItems If Instr(objItem.Name, "desktop") Then strPath = objItem.Name strPath = Replace(strPath, "\", "\\") Set colFiles = objWMIService.ExecQuery _ ("Select * From CIM_Datafile Where Name = '" & strpath & "'") WScript.Echo strpath End If Set oLink = oWS.CreateShortcut(strpath) sFind = "http://xx.xx.xx.xx/" sReplace = "http://xx.xx.xx.xx/" ix = InStr(oLink.TargetPath, sFind) If ix > 0 Then oLink.TargetPath = "http://xx.xx.xx.xx/" oLink.Save Count = Count + 1 End IfWScript.Echo Count & " Shortcuts have been updated."Wscript.Quitnext==========================================================================The above script runs for a little while and then errors out with a memory error...maybe an infinate loop...not too sure.The batch file==========================================================================@echo offnet use /d q: /ynet use q: \\server\share%SystemDrive%cd\cd "documents and settings"dir /s "file.url" && GOTO yes goto no :yes c:cd\cd %allusersprofile%\desktopdel "file.url"copy "q:\directory\#directory\directory\directory\directory\file.url" "%allusersprofile%\desktop\file.url"q:cd\cd "directory\#directory\computers touched repository"echo Computer Name: %computername%>%computername%.txtecho File update Location: All Users>%computername%.txtc:cd\net use /d q: /ygoto end :no c:cd\net use /d q: /ygoto end :end===========================================================================The above script works great except it does not search for and replace all of the instances of file.url and will not report all of the directories that they were in. I would need to do some sort of find and replace function as well as a better .txt file creation method.Any assistance with either of these scripts to solve the problem above would be greatly appriciated.Thanks.
rhodges Posted July 10, 2009 Author Posted July 10, 2009 Over thinking is always my specialty. I have decided that it would be best to just remove all of the instances of this shortcut and only have it located in the All Users profile. This will make the process much cleaner and easier to manage in the future. I will post the final code for professional review if anyone has time.
rhodges Posted July 10, 2009 Author Posted July 10, 2009 (edited) I think I will be going with the following Startup script to solve this issue:===============================================================================@echo offnet use /d q: /ynet use q: \\server\share /user:domin\username password%SystemDrive%cd\cd "documents and settings"for /f "tokens=* delims= " %%a in ('dir /s/b "your file.url"') do (del /s /q "%%a")cd\%windir%cd system32\config\systemprofilefor /f "tokens=* delims= " %%a in ('dir /s/b "your file.url"') do (del /s /q "%%a")cd\copy "q:\directory\new file.url" "%allusersprofile%\desktop\new file.url"q:cd\cd "directory\computers touched repository"echo Computer Name: %computername%>%computername%.txtecho New File Update Location: All Users>%computername%.txtc:net use /d q: /yexit===============================================================================Any suggestions about this particular finished script or explination on how and/or why the All User profile is also being stored in c:\windows\system 32\systemprofile would be great. Edited July 10, 2009 by rhodges
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