Solved

task created with schtasks is using the wrong current directory

Posted on 2014-11-16
4
143 Views
Last Modified: 2014-11-17
I'm creating a scheduled task within a .vbs that creates the task using:
schtasks /create /tn Eterna /tr "d:\data\eterna.vbs /sc WEEKLY /d MON,TUE,WED,THU,FRI /st 08:00:00

Open in new window


But when I run the task, it thinks the current directory is c:\windows\system32.  I have an .ini file in the same directory as .vbs (d:\data) that it can't find.  How to I get the task scheduler to use the same directory as the target of the action?
0
Comment
Question by:StarDusterII
  • 3
4 Comments
 

Author Comment

by:StarDusterII
ID: 40446030
I found by adding /V1 to the parameters, it works correctly... I'm able to run the task by clicking run in the task scheduler.  However, using this switch when it creates the task, prompts for the user's password.  I'd like to skip that if possible.
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40446032
Best to calculate the script's folder in the VBS, and use that for access to further files.
The VBS needs something like this:
set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = objFSO.GetParentFolderName(objFSO.GetFile(Wscript.ScriptFullName))

Open in new window

and strFolder now contains the path.
0
 

Author Comment

by:StarDusterII
ID: 40449140
Interesting... I used:
CurrentDirectory = fso.GetAbsolutePathName(".")

Open in new window

Similar idea, but I'll give yours a go.
0
 

Author Comment

by:StarDusterII
ID: 40449165
Perfect!  Thanks a ton.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

17 Experts available now in Live!

Get 1:1 Help Now