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

假装没事ソ 提交于 2020-02-18 05:33:31

问题


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?


回答1:


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



回答2:


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.




回答3:


The fix is to use the Subst command instead of Net Use.



来源:https://stackoverflow.com/questions/24428597/task-scheduler-access-non-local-drives-while-running-task-not-logged-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!