Solved

task created with schtasks is using the wrong current directory

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

733 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