3

I am trying to run a vb script using task scheduler. I am using the .GetAbsolutePathName(".") to get the full path of the script. When I run the script manually, it was able to get the correct path. But when run as scheduled task, it outputs "C:\Windows\System32\ as the path.

I am using the path name to get the full path of an Excel file that I would like to run. The excel file is saved within the same path as the script.

Below is my code:

Set fso = CreateObject("Scripting.FileSystemObject")

scurDir = fso.GetAbsolutePathName(".")

set fso = nothing

Set myxlApplication = CreateObject("Excel.Application")

wscript.echo scurDir & "\OOO Automation Tool.xlsm"

Set myWorkBook = myxlApplication.Workbooks.Open( scurDir & "\OOO Automation Tool.xlsm" )

myxlApplication.Visible = False

myxlApplication.Wait(Now + TimeValue("0:00:10"))

'Run routine
myWorkBook.Application.Run "MOutofOffice.pDetectIdleTime" 

'Close application
myxlApplication.Quit

'Release objects
set myxlApplication = nothing
set myWorkBook = nothing

Can you help me get the correct path?

May Ann
  • 51
  • 8
  • Where is your script located, and what path do you expect? – rory.ap Oct 29 '15 at 14:35
  • It is located on \10.163.13.11\IBPOv2$\BEF_Manila\QUALITY\Team Members\Me\Projects, and I expect to get that path using the fso.GetAbsolutePathName(".") – May Ann Oct 29 '15 at 14:54

1 Answers1

4

You can try with

With WScript.CreateObject("Scripting.FileSystemObject") 
    WScript.Echo .GetFile(WScript.ScriptFullName).ParentFolder.Path
End With

You need the path where the script is stored, not the current active directory, what you retrieve with the "." reference.

MC ND
  • 69,615
  • 8
  • 84
  • 126