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 one
2. 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
=========================================================
QUOTE
CODE
Dim Count
Count = 0
strComputer = "."
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 If
WScript.Echo Count & " Shortcuts have been updated."
Wscript.Quit
next
Count = 0
strComputer = "."
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 If
WScript.Echo Count & " Shortcuts have been updated."
Wscript.Quit
next
==========================================================================
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
==========================================================================
QUOTE
CODE
@echo off
net use /d q: /y
net use q: \\server\share
%SystemDrive%
cd\
cd "documents and settings"
dir /s "file.url" && GOTO yes
goto no
:yes
c:
cd\
cd %allusersprofile%\desktop
del "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%.txt
echo File update Location: All Users>%computername%.txt
c:
cd\
net use /d q: /y
goto end
:no
c:
cd\
net use /d q: /y
goto end
:end
net use /d q: /y
net use q: \\server\share
%SystemDrive%
cd\
cd "documents and settings"
dir /s "file.url" && GOTO yes
goto no
:yes
c:
cd\
cd %allusersprofile%\desktop
del "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%.txt
echo File update Location: All Users>%computername%.txt
c:
cd\
net use /d q: /y
goto end
:no
c:
cd\
net use /d q: /y
goto 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.