Jump to content

Recommended Posts

Posted

Hi,

 

Can anyone please help as to why this script doesnt work on XP? It works a treat on 7. It uses robocopy to copy shortcut files to the local machine then removes any ones for apps not installed.

 

Its just the robocopy part of copying the files that doesnt work.

 

I have the support tools installed and robocopy seem to work from a batch file.

 

Any thoughts please?

 

Thanks

 

Dim strSource, strDest
strSourceStudent = "\\falinge.int\NETLOGON\RedirectedFolders\x86\StudentStartMenu"
strDestStudent = "C:\RedirectedFolders\StudentStartMenu"
strSourceStudentDesktop = "\\falinge.int\NETLOGON\RedirectedFolders\x86\StudentDesktop"
strDestStudentDesktop = "C:\RedirectedFolders\StudentDesktop"
strSourceStaff = "\\falinge.int\NETLOGON\RedirectedFolders\x86\StaffStartMenu"
strDestStaff = "C:\RedirectedFolders\StaffStartMenu"
strSourceExamStartMenu = "\\falinge.int\NETLOGON\RedirectedFolders\x86\ExamStartMenu"
strDestExamStartMenu = "C:\RedirectedFolders\ExamStartMenu"
strSourceExamDesktop = "\\falinge.int\NETLOGON\RedirectedFolders\x86\ExamDesktop"
strDestExamDesktop = "C:\RedirectedFolders\ExamDesktop"
Set wshShell = WScript.CreateObject ("WSCript.shell") 	
wshshell.run "robocopy """ & strSourceStudent & """ """ & strDestStudent & """ /E /MIR /COPY:DATS /SECFIX /Z /W:20 /R:1", 6, True
wshshell.run "robocopy """ & strSourceStudentDesktop & """ """ & strDestStudentDesktop & """ /E /MIR /COPY:DATS /SECFIX /Z /W:20 /R:1", 6, True
wshshell.run "robocopy """ & strSourceStaff & """ """ & strDestStaff & """ /E /MIR /COPY:DATS /SECFIX /Z /W:20 /R:1", 6, True
wshshell.run "robocopy """ & strSourceExamStartMenu & """ """ & strDestExamStartMenu & """ /E /MIR /COPY:DATS /SECFIX /Z /W:20 /R:1", 6, True
wshshell.run "robocopy """ & strSourceExamDesktop & """ """ & strDestExamDesktop & """ /E /MIR /COPY:DATS /SECFIX /Z /W:20 /R:1", 6, True	
'The above runs: robocopy and copies the startmenu from the server to the workstation (creating folders if needed) 
'robocopy Source Destination Params
'/E = Copy subfolders, including empty ones
'/MIR = Mirrors the folder structure (e.g. deletes folders/files if they have been deleted at the source)
'/COPY:DATS = Copy the following file/folder attributes: D=Data, A=Attributes, T=Timestamps, S=Security=NTFS
'/SECFIX = Reapplies the folder security and ensures that it mirrors the source
'/W:20 = Wait 20 seconds before retrying any failed operation
'/R:1 = Retry any errors once
'/Z = Allows the copy process to auto restart if case of a network error
set wshshell = nothing
strSourceStudent = Null
strDestStudent = Null
strSourceStudentDesktop = Null
strDestStudentDesktop = Null
strSourceStaff = Null
strDestStaff = Null


'WScript.sleep 15000

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
objStartFolder = "C:\RedirectedFolders"
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,True
	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

Posted
Hi,

 

Can anyone please help as to why this script doesnt work on XP? It works a treat on 7. It uses robocopy to copy shortcut files to the local machine then removes any ones for apps not installed.

 

Its just the robocopy part of copying the files that doesnt work.

 

I have the support tools installed and robocopy seem to work from a batch file.

 

Any thoughts please?

 

Thanks

 

Have you tested if it runs just from CMD? Doing a single copy? As i'm not sure if XP has the default path settings for running robocopy normally. Might be worth checking to see if it's recognised in cmd.

 

Steve

Posted (edited)

Fixed it. It was the /secfix switch giving me the issue :)

 

I am getting an access denided error on line 105, do you know what that could be please?

Edited by FN-GM

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



×
×
  • Create New...