Scheduled task works on a mapped drive when configured for Windows XP mode, but not for Windows 7
Solution 1
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.
Solution 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
Related videos on Youtube
GSerg
Updated on September 18, 2022Comments
-
GSerg over 1 year
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:
then the task works. However if I select that:
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 whoRun
it manually). It also fails if I log in to the computer as the user under which the task is supposed to run andRun
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.
-
GSerg about 10 yearsI have tried
M:\Folder
,M:\Folder\
,"M:\Folder"
and"M:\Folder\"
. It does not work. It works under the Windows XP mode, where it containsM:\Folder
without quotes or trailing slash, but it doesn't seem to have an effect on the Windows 7 mode. -
GSerg about 10 yearsThat 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.
-
Ƭᴇcʜιᴇ007 about 10 years@GSerg Also, try unchecking "Run with highest privileges", it stymies me in weird ways every time I try to use it.
-
Jason Stevenson over 4 yearsI believe you should remove the ' surrounding the password.
-
MickMorley almost 4 yearsEither or, it works for me with the carrots.
-
Ali over 3 yearsWhy we need to create 2 different tasks? Why can't me map the drives and then perform the operation in the same script within a single task?
-
MickMorley about 2 years@Ali, this is due to the first line. The tasks use a system session that cannot see the mapped drives of the physical user.