Solved

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

Posted on 2013-01-10
7
1,367 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
[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 56

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:Christian de Bellefeuille
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 10

Author Comment

by:Christian de Bellefeuille
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 56

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:Christian de Bellefeuille
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:Christian de Bellefeuille
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

632 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