Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task Scheduler - Access non-local drives while running task not logged in

I had a task in win scheduler that runs every minute. The task runs a .bat file which SVN updates a series of folders then executes a perl script (which in turn will run off several others). The output/'log' of the perl script (tagged by date/time) is sent to a shared drive, not local to the machine the task runs on.

The whole task works flawlessly until sending the log to the shared drive. Since the task needs to run every minute I figured it would be best to use the setting 'Run whether user is logged on or not' in task scheduler.. A box beneath is detailed 'Do not store password. The task will only have access to local computer resources.' Obviously this is not going to work for me, so I left it unchecked.

However the script does still not write to the shared drive, even when logged in. Does anyone have any suggestions on how to work around this? I also realised I could 'Run only when the user is logged in' (this DOES write to shared drive), but in that case I would need a definite way to ensure the account never logs off, and cannot be force logged off by other users (the computer is shared by a number of users, max two at a time).

Thoughts?

like image 475
AMcNall Avatar asked Jun 26 '14 10:06

AMcNall


2 Answers

phd443322 has given already the right answer.

Mappings of a shared folders to drive letters are saved per user account in Windows registry if the network connection was made with default settings. Therefore every user using a computer can have different network drives.

There is the option Reconnect at logon to map the shared folder to a drive letter which is by default checked. But this option can be unchecked before creating the connection to map the shared folder to a drive letter just for current user session.

net use /? entered in a command prompt window outputs help of this command which is used to map a shared folder to a drive letter from command line or a batch file. There is the option /PERSISTENT:{YES | NO} whereby the default is YES. For example

net use Z: \\computer\share /persistent:no

connects a shared folder as drive Z: for current user session only.

This explains why AMcNall's failed with using a network drive in automated task.

Extra hint:

On using a laptop which is used in the office connected to company network, but also at home in a private network or no network, and finally also often in other networks, it is advisable to avoid an automatic network drive connection by Windows after logon in my point of view. It is better to use a batch file located somewhere on hard disk with a shortcut to this batch file stored in folder Startup of the user's Windows start menu with the property set to run the batch file with minimized window. The batch file contains for example:

@echo off
echo Checking availability of server/computer XXX
%SystemRoot%\system32\ping.exe -n 1 XXX >nul
if errorlevel 1 goto EndBatch
echo Map shared folder XXX\share to drive letter Z:
%SystemRoot%\system32\net.exe use Z: \\XXX\share /persistent:no
:EndBatch
like image 106
Mofi Avatar answered Sep 28 '22 00:09

Mofi


I had a similar issue - my task would run but not allow the called program access to a share even though I was asking it to run as a user who had rights.

The following helped and now it runs from within the Task Scheduler. Below is taken from a Google search that helped.

Go to the Start menu. Run. Type secpol.msc. ... The Local Security Policy manager opens. Go to Security Settings - Local Policies - User Rights Assignment node. Double click Log on as a batch job on the right side.

Hope this helps someone.

like image 34
Tim F. Avatar answered Sep 27 '22 23:09

Tim F.