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
Solved

task created with schtasks is using the wrong current directory

Posted on 2014-11-16
4
147 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 69

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

856 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