mpettis has asked for the wisdom of the Perl Monks concerning the following question:

hello, i have a process on a domain_A-box that i want to schedule as a scheduled task to copy files over from domain_B-boxes. due to domain separation and security, i cannot use unc paths. however, i can mount drives to do this (don't ask why this works if it is a security issue... i don't control this aspect). to mount drives, i use the 'net use' system call command in my perl script, within which i pass the drive to use, the share i am mounting, and the username and pasword with which to mount the share to the drive. the account with which i mount the drive is an account that works within 'domain_B'. when i run my script from an interactive session (by double-clicking on the .pl file), it runs smoothly. when i schedule it as a scheduled task, the copy will not work. note that i am not logged on with an account that has mount priveledges, so it must get is credentials from what i supply as an account and password in the script no matter how i run the script. any ideas as to why this behaves so badly?
  • Comment on perl on windows: using `net use` command

Replies are listed 'Best First'.
Re: perl on windows: using `net use` command (restricted security context)
by tye (Sage) on Dec 28, 2004 at 02:47 UTC

    Background tasks on Win32 default to running in a security context that doesn't allow access to network resources, even if the task is "run as a user" that normally has access to network resources.

    Some background task runners support some customization of the security context to use (such as different levels of "impersonation") but I'm not sure even that would allow you to bypass this security restriction.

    - tye        

Re: perl on windows: using `net use` command
by legato (Monk) on Dec 27, 2004 at 23:33 UTC

    > any ideas as to why this behaves so badly?

    System commands can be troublesome, especially on Windows. Usually, it is better to avoid them unless there is no other way. In this case, Win32::NetResource would likely work much better.

    Anima Legato
    .oO all things connect through the motion of the mind

Re: perl on windows: using `net use` command
by aquarium (Curate) on Dec 27, 2004 at 22:41 UTC
    Do you run the scheduled task as the same user as when you run the script interactively? Any error messages in Event Viewer? Try using "system("net use ....") or die "error $?";" to get the child process error in Event Viewer, or alternatively, write this error into a log file.
    the hardest line to type correctly is: stty erase ^H
      Hi, I do run as the same user interactively as I set as the owner of the scheduled task. I wrote the value of the scalar value of the `net use ...` command (which I mistook as the error code), and have modified it to write out the $? value, which I see now is equal to 512. Any ideas with this new tidbit? Thanks, Matt
        Update on this problem: the drive mount is now working in this scheduled task after my administrator bounced the server on which I was having problems. The consensus around here was that the drive was not mapping because some old, conflicting mapping or credentials were cached. Thank you to everybody for their help. Matt