Solved

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

Posted on 2013-01-10
7
1,275 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 51

Expert Comment

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

~bp
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 200 total points
Comment Utility
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
Comment Utility
@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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Author Comment

by:cdebel
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

16 Experts available now in Live!

Get 1:1 Help Now