Dans un Service Desk, on est régulièrement amené à faire des manipulations pour aider des utilisateurs. Certaines, tel que les ligne de commandes « NET USE » m’ont toujours semblaient étrange (bien qu’ayant une formation en Programmation logiciel).
NET USE J: /D /YES & NET USE J: \\NOMSERVEUR
Les lignes de commande Windows constitue une sorte de langage de programmation simplifiée (avec conditions). Pour plus d’information sur leur fonctionnement, voir https://prographie.wordpress.com/ligne-de-commande-windows/.
Ici on va comprendre à quoi sert Net Use J: /D /YES & NET USE J: \\NOMSERVEUR ?
A quoi sert Net Use ?
La commande Net Use est utilisée pour connecter, enlever et configurer les connexions aux ressources partagées (sur le système Windows bien évidemment).
La commande Net Use se présente via cette grammaire :
net use [{devicename | *}] [\\computername\sharename[\volume] [{password | *}]] [/user:[domainname\]username] [/user:[dotteddomainname\]username] [/user:[username@dotteddomainname] [/home {devicename | *} [{password | *}]] [/persistent:{yes | no}] [/smartcard] [/savecred] [/delete] [/help] [/?]
En somme, elle est capable d’établir la connexion avec une ressource sur le réseau, lancer une identification si besoin, et lancer une suppression ou une demande d’informations :
| net use | Execute the net use command alone to show detailed information about currently mapped drives and devices. |
| devicename | Use this option to specify the drive letter or printer port you want to map the network resource to. For a shared folder on the network, specify a drive letter from D: through Z:, and for a shared printer, LPT1: through LPT3:. Use * instead of specifying devicename to automatically assign the next available drive letter, starting with Z: and moving backward, for a mapped drive. |
| \\computername\sharename | This specifies the name of the computer, computername, and the shared resource, sharename, like a shared folder or a shared printer connected to computername. If there are spaces anywhere here, be sure to put the entire path, slashes included, in quotes. |
| volume | Use this option to specify the volume when connecting to a NetWare server. |
| password | This is the password needed to access the shared resource on computername. You can choose to enter the password during the execution of the net use command by typing * instead of the actual password. |
| /user | Use this net command option to specify a username to connect to the resource with. If you don’t use /user, net use will attempt to connect to the network share or printer with your current username. |
| domainname | Specify a different domain than the one you’re on, assuming you’re on one, with this option. Skip domainname if you’re not on a domain or you want net use to use the one you’re already on. |
| username | Use this option with /user to specify the username to use to connect to the shared resource. |
| dotteddomainname | This option specifies the fully qualified domain name where username exists. |
| /home | This net use command option maps the current user’s home directory to either the devicename drive letter or the next available drive letter with *. |
| /persistent:{yes | no} | Use this option to control the persistence of connections created with the net use command. Choose yes to automatically restore created connections at the next login or choose no to limit the life of this connection to this session. You can shorten this switch to /p if you like. |
| /smartcard | This switch tells the net use command to use the credentials present on the available smart card. |
| /savecred | This option stores the password and user information for use next time you connect in this session or in all future sessions when used with /persistent:yes. |
| /delete | This net use command is used to cancel a network connection. Use /delete with devicename to remove a specified connection or with * to remove all mapped drives and devices. This option can be shortened to /d. |
| /help | Use this option, or the shortened /h, to display detailed help information for the net use command. Using this switch is the same as using the net help command with net use: net help use. |
| /? | The standard help switch also works with the net use command but only displays the command syntax, not any detailed information about the command’s options. |
Il nous reste donc à comprendre
NET USE R: /D /YES & NET USE R: \\NOMSERVEUR\DOSSIER_1$
1) NET USE
La commande se prépare à créer, effacer ou configurer une connexion.
2) NET USE R:
Elle déclare le DeviceName, R: (la lettre d’un lecteur réseau)
3) NET USE R: /D
/delete, qui peut être raccourci en /d, permet la coupure d’une connexion
4) NET USE R: /D /YES
peu d’informations la-dessus : ça semble confirmer la suppression de cette connexion
5) NET USE R: /D /YES &
Se prépare à enchainer une deuxième commande
6) NET USE R: /D /YES & NET USE R:
Réutilise le lecteur R: pour…
7) NET USE R: /D /YES & NET USE R: \\NOMSERVEUR\DOSSIER_1$
…se connecter au serveur NOMSERVEUR, plus précisément au dossier DOSSIER_1$
Informations complémentaires :
Il existe un tuto très long, que j’ai du coup pas lu, pour ceux qui veulent prendre en main de manière maîtrisé les fichiers batch et les commandes windows :
https://windows.developpez.com/cours/ligne-commande/?page=page_5#LV