Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-10
7
Medium Priority
?
1,408 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 57

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 800 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 57

Accepted Solution

by:
Bill Prew earned 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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