Solved

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

Posted on 2013-01-10
7
1,291 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
  • 4
  • 2
7 Comments
 
LVL 52

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 52

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

There are many reasons a PC runs slower than when it was new, ranging from malicious software intended to mess things up to simple general Windows use.  Your PC performance may slowly degrade over time without you noticing but when you buy a PC from…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now