Solved

FileSystemObject.FolderExists always return false in VBScript started by Task Scheduler

Posted on 2013-01-10
7
1,339 Views
1 Endorsement
Last Modified: 2013-01-28
I've this little piece of code, that run perfectly when i type "cscript.exe MyScript.vbs" from command prompt, but as soon as i run it from the task manager, FolderExists always return False.

 
Set wFSO = CreateObject("Scripting.FileSystemObject")

    If Not wFSO.FolderExists(wSourceFolder & "Compressed") Then
	    Set oFile = wFSO.CreateFolder(wSourceFolder & "Compressed")
    END IF

Open in new window


wSourceFolder is a mapped drive (U:\ pointing to another computer).

Any idea?
1
Comment
Question by:cdebel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 38765504
What is wSourceFolder set to.  Can we see the full code?

~bp
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 200 total points
ID: 38765846
If wSourceFolder points to a mapped network drive, change it to the full UNC path instead, and see how that goes.

Rob.
0
 
LVL 10

Author Comment

by:cdebel
ID: 38767024
@Bill, here's the full code.  It use HandBrake to re-encode some video files taken from security cameras.  The security cameras are quite cheap, and the compression is almost innexistant.   Every 10 minutes, the camera produce a file of 70 Mb, so with this application i can shrink it to 2-7 Mb plus i can use some "Denoising".  

So the script take every files found in a folder on the cam server, it compress it and put it on DropBox, then it move the file to a temporary folder.  Once every files have been produced, the script delete that "compressed" directory and its content.

wSourceFolder is set to the letter of the drive (U:).  U: is a map on \\CACI10\uncompressed.  

Public wSourceFolder
Public wDestinationFolder
Public wFSO, wFile
Public wCommand, wCommand2
Public wCount

InitializeApp
EncodeAll

WScript.Quit 0

Public Sub InitializeApp()
    wCount = 0
    wSourceFolder = "U:"
    wDestinationFolder = "Z:"    

    wCommand = """C:\Program Files\Handbrake\HandBrakeCLI.exe"" -i """ & wSourceFolder  & "%1"" -t 1 -c 1 -o """ & wDestinationFolder & "%2"" -f mkv --deinterlace=""fast"" --denoise=""strong"" -w 800 -l 640 -e ffmpeg4 -q 5 --vfr  -a none --verbose=0"
End Sub


Public Sub EncodeAll()
    ' Create the object to access methods & properties of FileSystemObject
    Set wFSO = CreateObject("Scripting.FileSystemObject")

    If Not wFSO.FolderExists(wSourceFolder & "Compressed") Then
	    Set oFile = wFSO.CreateFolder(wSourceFolder & "Compressed")
    END IF
     
    ' Retrieve the files in the source folder
    Set Folder = wFSO.GetFolder(wSourceFolder)
    Set Files = Folder.Files
    Set wShell = WScript.CreateObject("WScript.Shell")
    
    For Each wFile In Files
	wNewFile = left(wFile.Name, len(wFile.Name)-4) & ".mkv"
	wCommand2 = Replace(wCommand, "%1", wFile.Name)
	wCommand2 = Replace(wCommand2, "%2", wNewFile)

	Return = wShell.Run(wCommand2, 0, True)
	wCount = wCount + 1
	wFSO.MoveFile wSourceFolder & wFile.Name, wSourceFolder & "Compressed\" & wFile.Name
    Next

    wFSO.DeleteFolder wSourceFolder & "Compressed"
End Sub

Open in new window

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 10

Author Comment

by:cdebel
ID: 38767270
I have the feeling that it has something to do with the rights, or the actual user that Task Scheduler is using...

I've done some modifications to the script.  I've added a wUNCSourceFolder, and that seems to solve the problem that i had about the FolderExists.  I still had some other problems, related to the task manager.  It gave me some Permission Denied error.

I've noticed that there's a check box "Exécuter avec les autorisations maximales" (which i would translate to "Execute with maximum authorizations" in an english version of windows).  It was checked.  I've removed the check, and now it seems to run properly without Permission Denied.

So i guess that the problem is solved.  I'll keep you informed after a day or two of tests.

thanks you
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 300 total points
ID: 38769257
What user are you running it as from task manager. I suspect you don't have the U: drive mapped when it runs from task manager, and that's why it's failing. You might need to either use the use the full share path (not U:) to the resource, or map the U: drive in the script.

~bp
0
 
LVL 10

Author Comment

by:cdebel
ID: 38788880
I've not tried to run it from the Task Manager, but it seems to work properly the way i did it (the last version in my last post, with a mix of UNC & Drive Letters).  I don't think handbrake will accept the UNC.

I'll give it 1 more day but i think everything is ok now.
0
 
LVL 10

Author Closing Comment

by:cdebel
ID: 38829138
Well, i consider that this problem is solved.  The checkbox "Execute with maximum authorizations" and the minor changes to the verification of the folder existence by using UNC instead of drive letter seems to work properly.

Thanks for the tips
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question