locked
VBScript: Error: Move folder Permission Denied + code: 800A0046 RRS feed

  • Question

  • Hi All,

    i tried move a folder YYYYmm format using below VBScript, move to destination same folder directory, YYYY\yyyyMM. However, command prompt shown me Permission Denied, Error Code: 800A0046.

    server Date time format: mm/DD/yyyy, i use VBscript to twist to format DD/MM/yyyy to match folder.

    CDATE(currDay+ "/"  + currMonth + "/" + CurrYYYY)

    'How to use:
    ' type "archiver D:\root source folder" in command line eg: D:\Test\archiver\archiver.vbs "D:\Test\archiver"
    
    DIM strLogFile
    Const ForAppending = 8
    'Wscript.StdOut.WriteBlanklines 100
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    strLogFile=WScript.Arguments(0) &"\Log\ARCHIVER_Log_" & Year(Date) & Month(Date) & Day(Date) & ".txt"
    
    'Log\ folder not exists then create new folder
    IF NOT FSO.FolderExists(WScript.Arguments(0) &"\Log\") THEN
    		FSO.CreateFolder WScript.Arguments(0) & "\Log\"
    END IF
    
    Set objLogFile = FSO.OpenTextFile(strLogFile, ForAppending, True)
    
    objLogfile.WriteLine NOW & ">> ------------ ARCHIVER BEGIN ------------------"
    objLogfile.WriteLine ""
    objLogfile.WriteLine Now & ">> Root Folder: " & WScript.Arguments(0)
    objLogfile.WriteLine ""
    archiver(FSO.GetFolder(WScript.Arguments(0)))
    objLogfile.WriteLine NOW & ">> ------------ ARCHIVER END ------------------"
    objLogfile.WriteLine ""
    objLogFile.Close 
    
    
    Sub archiver(Folder)
    
    	DIM year_
    	DIM month_
    	Dim dt
    	dt=now
    	
    	'output format: yyyymmddHHnn
    	currMonth=Cstr(month(dt)) 	'current Month
    	currDay=Cstr(day(dt)) 		'current day
    	CurrYYYY=Cstr(year(dt)) 	'current Year
    	'wscript.echo currMonth
    	'wscript.echo currDay
    	'wscript.echo CurrYYYY	
    	
    	archiveMonth = -6
    	'Set myLog = objFSO.OpenTextFile(destinationPath, For_Writing, True)
            For Each Subfolder in Folder.SubFolders		
    		IF LEN(subfolder.Name) = 8 AND ISNUMERIC(subfolder.Name) THEN
    			year_ = MID(subfolder.Name,1,4)
    			month_ = MID(subfolder.Name,5,2)
    			
    
    			objLogfile.WriteLine "Process Checking MM-DD-YY Now......"
    			'objLogfile.WriteLine FormatDateTime(CDATE("01/" + month + "/" + year),2)
    			'IF IsDate(CDATE("01/" + month + "/" + year)) AND DateDiff("m", Date, "01/" + month + "/" + year) < archiveMonth  THEN
    			IF IsDate(CDATE("01/" + month_ + "/" + year_)) AND DateDiff("m", CDATE(currDay+ "/"  + currMonth + "/" + CurrYYYY), "01/" + month_ + "/" + year_) <= archiveMonth  THEN
    			
    				objLogfile.WriteLine archiveMonth '-6
    				objLogfile.WriteLine IsDate(CDATE("01/" + month_ + "/" + year_)) 'True
    				
    				objLogfile.WriteLine NOW & ">> Processing >> " + Subfolder.Name
    				destinationPath = year_ 'WScript.Arguments(0) + " " + year
    				'Year folder not exists then create new folder
    				IF NOT FSO.FolderExists(destinationPath) THEN
    					FSO.CreateFolder destinationPath
    					
    				END IF
    		
    				IF FSO.FolderExists(destinationPath) THEN
    					destinationPath = destinationPath + "\" + year_ + month_
    					IF FSO.FolderExists(destinationPath) THEN
    						objLogfile.WriteLine NOW & ">> Moving folder " + Subfolder.Name + " to destination: " + destinationPath
    						Subfolder.Move destinationPath + "\" + Subfolder.Name
    					ELSE
    						'Year + Month folder not exists then create new folder
    						FSO.CreateFolder destinationPath
    						IF FSO.FolderExists(destinationPath) THEN
    							objLogfile.WriteLine NOW & ">> Moving folder " + Subfolder.Name + " to destination: " + destinationPath
    							Subfolder.Move destinationPath + "\" + Subfolder.Name
    						ELSE
    							objLogfile.WriteLine NOW & ">> ** ERROR: Unable to create folder: " + destinationPath	
    						END IF
    					END IF
    				ELSE
    					objLogfile.WriteLine NOW & ">> ** ERROR: Unable to create folder: " + destinationPath
    				END IF
    				'Wscript.StdOut.WriteBlanklines 1
    				'objLogfile.WriteLine ""
    
    			END IF
    		END IF
            Next
    End Sub

    Error Message

    Script: D:\....\Archived\archiver.vbs

    Line: 71

    Char: 7

    Error Code: Permission Denied

    Code: 800A0046

    Source Code: Microsoft VBScript runtime error




    • Moved by Bill_Stewart Wednesday, January 2, 2019 3:18 PM This is not "fix/debug/rewrite my script for me" forum
    Monday, October 29, 2018 5:38 AM

All replies

  • You cannot change a script to overcome your lack of permission. You must have permission on the resources in order to change it.

    Perhaps you need to run as an elevated admin.


    \_(ツ)_/

    Monday, October 29, 2018 5:44 AM
  • Hi,

    i already grant myself under server administrator group.

    Problem still persist.
    Monday, October 29, 2018 5:56 AM
  • You have to run elevated as a full administrator.  Server Admin will not grant the permissions you need.


    \_(ツ)_/

    Monday, October 29, 2018 6:08 AM
  • Change

    destinationPath = year_ 'WScript.Arguments(0) + " " + year

    to

    destinationPath = WScript.Arguments(0) + "\" + year

    Tuesday, October 30, 2018 4:09 AM