You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Accessing mapped network drives (Windows)

Question:

I'm trying to access a mapped network drive (e.g. X:) from a JobScheduler job. The drive can be accessed from outside JobScheduler but within a Job it doesn't exist.

Answer:

This behaviour is more of a Windows feature than a JobScheduler bug. On Windows JobScheduler runs as a service and services are started by a process which is started very early when the operating system starts up. That happens long before the network drives are mounted, which happens when a user logs on.

In order to access a network drive from JobScheduler, you need to mount it in JobScheduler process. This can be done in the startup script of JobScheduler. In detail, do the following:

  • Make sure JobScheduler is running as a user which has permission to access the network drive(s) (Check the services configuration to set a different user).

  • Configure a scheduler start script to mount the network drive:

    <scheduler_script name = "mount_drives">
    <script language="VBScript">
    <![CDATA[
    Function spooler_init
    Dim ws, return_code, command
    *command = "net.exe use X: **\\server\dir* <file://%5C%5Cserver%5Cdir>*"
    *Set ws = CreateObject("Wscript.shell")
    return_code = ws.run( command, 0, 1 )
    Set ws = Nothing
    If return_code > 0 Then spooler_log.warn("Failed to mount drives: " & return_code)
    spooler_init = true
    End Function
    ]]>
    </script>
    </scheduler_script>
    
  • Put the <script> element into config/scheduler.xml between the <process_classes> and <http_server> elements.

  • Restart JobScheduler

Again, this might have to do with the moment that the process which starts the services is started. If the environment variables do not yet exist, then they cannot be inherited by the services. See if it changes when you change the user that runs the service.

  • No labels