Dario
Dario

Reputation: 3

vbs scheduled path not found

I cannot figure out what I'm doing wrong. I have a batch file starting a vbs script. The script just makes some operations in some files, like moving them, create, delete... It works fine. Executing the bat it starts the vbs script and everything work. The bat file just makes a cscript file.vbs

The problem is that I've scheduled this bat file . When the times come, it gets executed but I get the error "path not found" in the vbs script.

It's not a schedule task problem because I've 11 task running batch files and they run smootly, and the script is executed (I've put controllers on it). But the vbs script returns always the same path not found error.

Again,if I execute the script manually, it runs without problems.

The task is scheduled with the same account I use to manual execute the file, so it's not a permission issue. I just doubleclick the batch and it runs, click on execute on the task schedule manager and it fails.

The system is windows server 2008 r2 standard. I already tried to reboot, deleting and making a new task....

Thanks to everyone

[UPDATE]

I paste here part of the code

FILE: D:\scripts\conf.ini

[script1]
    fileA=D:\Rep\exportA.csv
    fileB=D:\Rep\exportB.csv
    fileC=D:\Rep\exportC.csv
    dirHistory=D:\Rep\history

FILE: D:\scripts\merge.vbs

Dim iniObj
Set iniObj=New ClsINI
If iniObj.OpenINIFile("D:\scripts\conf.ini") = False Then
    wLog("Impossible to read file ini")
    Set iniObj = Nothing
    Chiudi()
End If
Dim errIni,tmpVal
Dim fileA,fileB,fileC,dirHistory

errIni = iniObj.GetINIValue("script1", "fileA", fileA)
tmpVal = iniObj.GetINIValue("script1", "fileB", fileB)
errIni = errIni+tmpVal
tmpVal = iniObj.GetINIValue("script1", "fileC", fileC)
errIni = errIni+tmpVal
tmpVal = iniObj.GetINIValue("script1", "dirHistory", dirHistory)
errIni = errIni+tmpVal

If errIni > 0 Then
    wLog("Error loading file ini")
    wLog(errIni)
    iniObj.CloseINIFile()
    Set iniObj = Nothing
    Chiudi()
End If

wLog("File ini Caricato")

Dim objFso,posizioneFile,Fase
Dim arrElement,resArray,actionArray,cedoleArray,varArray ,i
Dim conn,rs,strCon
Dim maxPos,maxTemp
Dim objExcel, objSheet,cella

Set objFso = CreateObject("Scripting.FileSystemObject")

if objFso.FileExists(fileA) then
    objFso.DeleteFile(posizione)
    wLog("File posizione moved")
else
    wLog("File posizione not found")
end if

At this line a get the error of "Path not found"

Set posizioneFile = objFso.OpenTextFile(fileA, 8, True)

If not objFso.FileExists(fileB) then
    SendEmail("nego")
    Fase=false
Else
    Set tFile = objFso.OpenTextFile(fileB, 1)
    strFile=tFile.ReadAll

    tFile.Close
    posizioneFile.WriteLine strFile
    objFso.MoveFile fileB, dirHistory&"\Negoz_"& CreaId(2) & ".csv"
End If
posizioneFile.Close

FILE: D:\scripts\merge.bat

echo Start Merge %date% %time% >> Started.log
cscript D:\scripts\merge.vbs

Sorry if I didn't put it before, but I was thinking it was a windows issue, because I thought the code was fine.

Thanks

Upvotes: 0

Views: 2702

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200233

This sounds like an issue with the working directory although it's a bit difficult to tell, since you chose not to show the content of the batch script. If you start the script manually (by double-clicking), the working directory is the directory in which the batch script (and probably the VBScript as well) resides. If you run the batch script as a scheduled task, the working directory is %SystemRoot%\system32 unless you expressly set a working directory in the task's properties.

Now, if your batch script looks like this:

cscript.exe your.vbs

it will look for your.vbs in the working directory and won't find it if the working directory is not the directory containing your.vbs. If my assumption that both scripts are in the same directory is correct you could either set the working directory in the properties of the scheduled task or (better) change the batch script to something like this:

cscript.exe "%~dp0your.vbs"

%0 is the path to the batch script itself as it was called. %~dp0 expands %0 to the absolute path of the parent directory (including a trailing backslash).

Upvotes: 1

Related Questions