MSFN Forum: cmd or vbs does not matter - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

cmd or vbs does not matter need to find and replace desktop shortcuts Rate Topic: -----

#1 User is offline   rhodges 

  • Group: Members
  • Posts: 3
  • Joined: 09-July 09

  Posted 09 July 2009 - 02:49 PM

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

Quote

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

Quote

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


#2 User is offline   rhodges 

  • Group: Members
  • Posts: 3
  • Joined: 09-July 09

Posted 10 July 2009 - 09:01 AM

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.

#3 User is offline   rhodges 

  • Group: Members
  • Posts: 3
  • Joined: 09-July 09

Posted 10 July 2009 - 10:57 AM

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.

This post has been edited by rhodges: 10 July 2009 - 10:58 AM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy