Solved

task created with schtasks is using the wrong current directory

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

11 Experts available now in Live!

Get 1:1 Help Now