Jump to content

Recommended Posts

Posted

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 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

=========================================================

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

==========================================================================

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 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

===========================================================================

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.


Posted

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.

Posted (edited)

I think I will be going with the following Startup script to solve this issue:

===============================================================================

@echo off

net use /d q: /y

net 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\systemprofile

for /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%.txt

echo New File Update Location: All Users>%computername%.txt

c:

net use /d q: /y

exit

===============================================================================

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 by rhodges

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...