+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Script not Running on XP but does on 7 in Coding and Web Development; Hi, Can anyone please help as to why this script doesnt work on XP? It works a treat on 7. ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449

    Script not Running on XP but does on 7

    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

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

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,696
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by FN-GM View Post
    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

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Yep robocopy works fine from the command prompt just like 7.

  4. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    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?
    Last edited by FN-GM; 30th March 2012 at 12:06 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. Script to run on certain Operating Systems?
    By CallumCatterall in forum Scripts
    Replies: 15
    Last Post: 29th November 2011, 09:50 PM
  2. unattend.xml not running on a custom syspreped image??
    By burgemaster in forum Windows 7
    Replies: 2
    Last Post: 25th March 2010, 10:21 AM
  3. Replies: 0
    Last Post: 23rd September 2009, 01:06 PM
  4. My Documents script not working on R2
    By contink in forum Scripts
    Replies: 15
    Last Post: 11th June 2008, 10:40 AM
  5. Printer script not running at start up
    By richard in forum Scripts
    Replies: 11
    Last Post: 29th May 2007, 07:39 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •