1

There is a Windows 7 PC with a scheduled task. The only thing it does is running a VBS file located on a mapped drive that points to a network share:

M:\Folder\Script.vbs

where M: is the mapped drive.

The task is set to Run whether user is logged in or not, and it has saved credentials for user who has access to that folder.

Now, if I select this in the dropdown:

enter image description here

then the task works. However if I select that:

enter image description here

then it fails with code 8007010B (which, as I understand it, is "Directory name is invalid"). It fails whether or not someone is logged in, and regardless of what triggered the task (the schedule or the user who Run it manually). It also fails if I log in to the computer as the user under which the task is supposed to run and Run it manually.

When I'm logged in as the user under which the task runs, I have access to the mapped drive and can run the script with Explorer no problem.

Apparently there is some compatibilty shim kicking in, but which one? And what do I do to make it work when 'configured for Windows 7', which should be the native mode for the computer?

I would just leave it as is, but if someone mistakenly 'upgrades' the task to the Windows 7 mode, there is no way back: the Windows XP option is then removed from the menu for that task. To have it back, one needs to export the task as XML, delete it and reimport.

2

When the task runs, the M: drive map doesn't exist in the context of the user/session the task is being run as.

Either reference the network location by UNC, or modify the task's script to map M: to the path before performing the rest of its work.

| improve this answer | |
  • That might be the case, but I want to understand exactly why. Why does it work in XP mode? Why does it not work in 7 mode when I'm logged in as the right user and already have the drive mapped (because another session is created for the task to run in, ignoring the existing session?)? Also I'd rather not change paths to UNC because the script uses M: paths too, and so do other scripts it calls. – GSerg Mar 28 '14 at 7:09
  • @GSerg Also, try unchecking "Run with highest privileges", it stymies me in weird ways every time I try to use it. – Ƭᴇcʜιᴇ007 Mar 28 '14 at 11:28
2

@Ƭᴇcʜιᴇ007 is correct. Running the script using "Run whether user is logged on or not" uses a system session and cannot see the drives of the physical user session.

Another solution is to create another task which uses the same user account and uses the same "Run whether user is logged on or not" selection. This task would be solely used to map the desired drives that your other Scheduled Tasks rely on. The drives will stay mapped in the system session and allow your other tasks to see the same mapped drives. I trigger this task that runs a batch file to map drives for the system user every 5 minutes.

Example Powershell Mapping

if (-not (test-path E:)) {Log -Letter "E:"; Net Use E: \\server\share 'password' /user:user /persistent:yes /y}

Simple Batch/Powershell Mapping

Net Use E: \\server\share 'password' /user:user /persistent:yes /y

| improve this answer | |
  • I believe you should remove the ' surrounding the password. – Jason Stevenson Dec 12 '19 at 21:14
  • Either or, it works for me with the carrots. – MickMorley Aug 10 at 20:04
0

According to this thread, you need to add the same path into the "start in" box. Add M:\Folder\ to the start in box and it should work fine.

| improve this answer | |
  • I have tried M:\Folder, M:\Folder\ , "M:\Folder" and "M:\Folder\". It does not work. It works under the Windows XP mode, where it contains M:\Folder without quotes or trailing slash, but it doesn't seem to have an effect on the Windows 7 mode. – GSerg Mar 27 '14 at 20:16
  • Weird. all the research I've done says that the start in box is the key ...without the double-quotes. – Nathan C Mar 27 '14 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.