Вопрос

I would like to know if somebody knows a walk round to the issue where task scheduler wont execute a batch on a shared directory.

The only way I know is to create one with username and password access however because I don’t have these details of any of the 17 pc I maintain (user privacy) I have to find another way IF I run the task with the system rights it wont run the batch located on a shared directory.

I have also tried to see if a shortcut linked to the batch might trick the system or if a batch calling the original batch on these hared directory might work but either has failed.

Это было полезно?

Решение

I assume that by a "shared directory" you mean a network share, like //server/c/directory/whatever.

Batch files have issues with network shares because you cannot make a network share your current directory because current directories require a drive letter for some reason. You can access data and even programs and batch files on a network share, but you cannot run a batch file in a network share.

What you need to do is map a network drive to a drive letter. You can use the net use command to do so from the command prompt or a batch file. Allowing the automatic connections to be created and destroyed only when needed. Permanent connections are problematic over WiFi because Windows will probably try (and fail) to reconnect them before you've even gotten an IP address.

:: Things inside hard bracksts [] are optional
net use [DRIVE_LETTER:] \\server\Path [/user:domain\UserName] [Password]

:: To remove that mapped drive
net use DRIVE_LETTER: /delete

So, an example would be:

:: Make a 'drive' z: and connect it to \\Linda-PC\c\Downloads
::  Drive: \\Share    \Path               Domain\User   Password
net use z: \\Linda-PC\c\Downloads
net use z: \\Linda-PC\c\Downloads /user:Linda-PC\James
net use z: \\Linda-PC\c\Downloads /user:Linda-PC\James T@ste7heRainbovv

:: The same command will close any connection and remove any associated
:: drive letter. Like so:
net use z: /delete

.

Line 1 will only reliably work if \\Linda-PC\c\Downloads requires no username or password. If \\Linda-PC\c\Downloads DOES need a username and password it may prompt you for them, it may simply fail, or it may appear to connect but be unable to read any files or directories. (Unless you are using a username with the same domain and password on both PC's. Like a network administrator.)

Line 2 will only work if you have a username and password on that PC (Unless you have a user with the same domain, username, and password on both PC's.) If you are using and login to an account that has the same domain, username and password on both PC's, it will not ask for your password.

Line 3 will only work if you have a username and password on that PC (Unless you have a user with the same domain, username, and password on both PC's.).

  • NOTE: It is NOT necessary to use the same user on both machines.

It is possible to browse and use any subdirectories off your mount-point, though you may need to propagate the permissions throughout them, or you may set user access by Group or by User for every individual directory. Hidden files and folders will be hidden unless you have permission to see them, but still only when using the dir /a:h command. Normal file and folder attributes may be set and eliminated by ATTRIB.EXE.

You may connect many different drive letters to many different mount-points on the same machine and give them all the same, or different, sets of user rights and requirements.

So you may Connect: To:

         W:     \\Linda-PC\c
         X:     \\Linda-PC\c\Downloads
         Y:     \\Linda-PC\c\Users\John
         Z:     \\Linda-PC\c\Users\Public\Documents

So under the right circumstances (Windows 7 has made user rights and permissions more complicated), drive W: (or \\Linda-PC\c) could have access to the entire C: drive of Linda-PC, but be limited in access to members of the Administrator's Group on Linda-PC.

Drive X: or network share \\Linda-PC\c\Downloads, you could give Read access to the group Everyone, eliminating the need for using a username or password when connecting, browsing, or downloading files.

Drive Y:, or \\Linda-PC\c\Users\John you could give Full-Control access to the user John from `Linda-PC'.

And Drive Z: or \\Linda-PC\c\Users\Public\Documents you could give read/write access to the Group Guests, and limit access to those who have an account in the group Guests on DansPc.

All these permissions must be set up on the machine hosting or serving the files, and to give access to groups or users that do not have an account on the SERVER, that server must have Administrative network access to the other machine. So you could hook up the user DansPC\Dan with access to drive Y:, but DansPc and Linda-PC must be able to talk, and simultaneously have a user logged in or connected to both machines with Administrative access to both.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top