Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

TS : Mapper un lecteur réseau

6 réponses
Avatar
Patrick Fredin
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: \\serveur\partage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick

6 réponses

Avatar
Philippe T [MS]
Bonjour,

Voici un exemple complet Ms :

<<<
' Script d'exemple pour l'environnement d'exécution de scripts Windows
'
' ------------------------------------------------------------------------
' Copyright (C) 1996 Microsoft Corporation
'
' Microsoft vous concède le droit d'utiliser, de modifier, de reproduire
' et de distribuer les exemple de fichiers d'application (et/ou toutes
' versions modifiées) comme vous l'entendez, à condition que vous
' reconnaissiez que Microsoft n'a aucune garantie, aucune obligation,
' et aucune responsabilité pour aucun des exemples de fichiers
' d'application.
' ------------------------------------------------------------------------
'
' Cet exemple montre comment utiliser l'objet WSHNetwork.
' Il lit les propriétés réseau (nom d'utilisateur et de l'ordinateur),
' connecte, déconnecte et énumère les lecteurs réseau.


L_Welcome_MsgBox_Message_Text = "Cet exemple montre comment utiliser
l'objet WSHNetwork."
L_Welcome_MsgBox_Title_Text = "Exemple pour l'environnement d'exécution
de scripts Windows"
Call Welcome()

'
****************************************************************************
****
' *
' * Objet réseau WSH.
' *

Dim WSHNetwork
Dim colDrives, SharePoint
Dim CRLF

CRLF = Chr(13) & Chr(10)
Set WSHNetwork = WScript.CreateObject("WScript.Network")


Function Ask(strAction)

' Cette fonction demande à l'utilisateur s'il veut effectuer une action
' spécifique et paramètre un code de retour ou quitte l'exécution
' du script suivant le bouton pressé par l'utilisateur. Cette fonction
' est appelée à divers points du script ci-dessous.

Dim intButton
intButton = MsgBox(strAction, _
vbQuestion + vbYesNo, _
L_Welcome_MsgBox_Title_Text )
Ask = intButton = vbYes
End Function

' **************************************************
' *
' * Affiche les propriétés de l'objet WSHNetwork
' *
' *
MsgBox "UserDomain" & Chr(9) & "= " & WSHNetwork.UserDomain & CRLF &
_
"UserName" & Chr(9) & "= " & WSHNetwork.UserName & CRLF &
_
"ComputerName" & Chr(9) & "= " & WSHNetwork.ComputerName,
_
vbInformation + vbOKOnly,
_
"Propriétés WSHNetwork"

' **************************************************
' *
' * WSHNetwork.AddNetworkDrive
' *
' *

Function TryMapDrive(intDrive, strShare)
Dim strDrive
strDrive = Chr(intDrive + 64) & ":"
On Error Resume Next
WSHNetwork.MapNetworkDrive strDrive, strShare
TryMapDrive = Err.Number = 0
End Function

If Ask("Voulez-vous connecter un lecteur réseau ?") Then
strShare = InputBox("Entrez le partage réseau auquel vous voulez vous
connecter ")
For intDrive = 26 To 5 Step -1
If TryMapDrive(intDrive, strShare) Then Exit For
Next

If intDrive <= 5 Then
MsgBox "Impossible de se connecter au partage. "
& _
"Il n'y a plus de lettre de lecteur disponible. " & _
CRLF
& _
"Veuillez déconnecter une connexion existante " & _
"et réessayer. ", _
vbExclamation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strDrive = Chr(intDrive + 64) & ":"
MsgBox "Connexion " & strShare & " au lecteur " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text

If Ask("Voulez-vous déconnecter le lecteur réseau que vous venez de
créer ?") Then
WSHNetwork.RemoveNetworkDrive strDrive

MsgBox "Déconnexion du lecteur " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
End If
End If
End If


' **************************************************
' *
' * WSHNetwork.EnumNetworkDrive
' *
' *
'Demande à l'utilisateur s'il veut énumérer les lecteurs réseau
If Ask("Voulez-vous énumérer les lecteurs réseau ?") Then
'Énumère les lecteurs réseau dans un objet collection de type
WshCollection
Set colDrives = WSHNetwork.EnumNetworkDrives

'Si aucun lecteur réseau n'a été énuméré, alors l'utilisateur en est
'averti ; sinon, les lecteurs sont affichés
If colDrives.Count = 0 Then
MsgBox "Il n'y a pas de lecteur à énumérer.", _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strMsg = "Connexion en cours : " & CRLF
For i = 0 To colDrives.Count - 1 Step 2
strMsg = strMsg & CRLF & colDrives(i) & Chr(9) & colDrives(i +
1)
Next

MsgBox strMsg, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text

End If
End If

'
****************************************************************************
****
' *
' * Bienvenue
' *
Sub Welcome()
Dim intDoIt

intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub







Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"Patrick Fredin" wrote in message
news:#
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: serveurpartage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick






Avatar
Sebastien Piche
oui

voicie la doc tiré du sdk



Adds a shared network drive to your computer system.

object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile],
[strUser], [strPassword])
Arguments
object
WshNetwork object.
strLocalName
String value indicating the name by which the mapped drive will be known
locally.
strRemoteName
String value indicating the share's UNC name (xxxyyy).
bUpdateProfile
Optional. Boolean value indicating whether the mapping information is
stored in the current user's profile. If bUpdateProfile is supplied and has
a value of true, the mapping is stored in the user profile (the default is
false).
strUser
Optional. String value indicating the user name. You must supply this
argument if you are mapping a network drive using the credentials of someone
other than the current user.
strPassword
Optional. String value indicating the user password. You must supply this
argument if you are mapping a network drive using the credentials of someone
other than the current user.
Remarks
An attempt to map a non-shared network drive results in an error.

Example
The following code maps the logical drive "E" to a network share with the
UNC name "ServerPublic."

[VBScript]
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "ServerPublic"
[JScript]
var WshNetwork = WScript.CreateObject("WScript.Network");
WshNetwork.MapNetworkDrive ("E:", "\ServerPublic");
See Also
EnumNetworkDrives Method | RemoveNetworkDrive Method

Applies To: WshNetwork Object



"Patrick Fredin" a écrit dans le
message de news: %
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: serveurpartage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick



Avatar
Patrick Fredin
Merci.

Où peut-on trouver le SDK ?

Encore merci.

--
Patrick

"Sebastien Piche" wrote in message
news:%
oui

voicie la doc tiré du sdk



Adds a shared network drive to your computer system.

object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile],
[strUser], [strPassword])
Arguments
object
WshNetwork object.
strLocalName
String value indicating the name by which the mapped drive will be known
locally.
strRemoteName
String value indicating the share's UNC name (xxxyyy).
bUpdateProfile
Optional. Boolean value indicating whether the mapping information is
stored in the current user's profile. If bUpdateProfile is supplied and
has a value of true, the mapping is stored in the user profile (the
default is false).
strUser
Optional. String value indicating the user name. You must supply this
argument if you are mapping a network drive using the credentials of
someone other than the current user.
strPassword
Optional. String value indicating the user password. You must supply this
argument if you are mapping a network drive using the credentials of
someone other than the current user.
Remarks
An attempt to map a non-shared network drive results in an error.

Example
The following code maps the logical drive "E" to a network share with the
UNC name "ServerPublic."

[VBScript]
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "ServerPublic"
[JScript]
var WshNetwork = WScript.CreateObject("WScript.Network");
WshNetwork.MapNetworkDrive ("E:", "\ServerPublic");
See Also
EnumNetworkDrives Method | RemoveNetworkDrive Method

Applies To: WshNetwork Object



"Patrick Fredin" a écrit dans le
message de news: %
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: serveurpartage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick







Avatar
Patrick Fredin
Merci. C'est super.

--
Patrick

"Philippe T [MS]" wrote in message
news:
Bonjour,

Voici un exemple complet Ms :

<<<
' Script d'exemple pour l'environnement d'exécution de scripts Windows
'
' ------------------------------------------------------------------------
' Copyright (C) 1996 Microsoft Corporation
'
' Microsoft vous concède le droit d'utiliser, de modifier, de reproduire
' et de distribuer les exemple de fichiers d'application (et/ou toutes
' versions modifiées) comme vous l'entendez, à condition que vous
' reconnaissiez que Microsoft n'a aucune garantie, aucune obligation,
' et aucune responsabilité pour aucun des exemples de fichiers
' d'application.
' ------------------------------------------------------------------------
'
' Cet exemple montre comment utiliser l'objet WSHNetwork.
' Il lit les propriétés réseau (nom d'utilisateur et de l'ordinateur),
' connecte, déconnecte et énumère les lecteurs réseau.


L_Welcome_MsgBox_Message_Text = "Cet exemple montre comment utiliser
l'objet WSHNetwork."
L_Welcome_MsgBox_Title_Text = "Exemple pour l'environnement
d'exécution
de scripts Windows"
Call Welcome()

'
****************************************************************************
****
' *
' * Objet réseau WSH.
' *

Dim WSHNetwork
Dim colDrives, SharePoint
Dim CRLF

CRLF = Chr(13) & Chr(10)
Set WSHNetwork = WScript.CreateObject("WScript.Network")


Function Ask(strAction)

' Cette fonction demande à l'utilisateur s'il veut effectuer une action
' spécifique et paramètre un code de retour ou quitte l'exécution
' du script suivant le bouton pressé par l'utilisateur. Cette fonction
' est appelée à divers points du script ci-dessous.

Dim intButton
intButton = MsgBox(strAction, _
vbQuestion + vbYesNo, _
L_Welcome_MsgBox_Title_Text )
Ask = intButton = vbYes
End Function

' **************************************************
' *
' * Affiche les propriétés de l'objet WSHNetwork
' *
' *
MsgBox "UserDomain" & Chr(9) & "= " & WSHNetwork.UserDomain & CRLF &
_
"UserName" & Chr(9) & "= " & WSHNetwork.UserName & CRLF &
_
"ComputerName" & Chr(9) & "= " & WSHNetwork.ComputerName,
_
vbInformation + vbOKOnly,
_
"Propriétés WSHNetwork"

' **************************************************
' *
' * WSHNetwork.AddNetworkDrive
' *
' *

Function TryMapDrive(intDrive, strShare)
Dim strDrive
strDrive = Chr(intDrive + 64) & ":"
On Error Resume Next
WSHNetwork.MapNetworkDrive strDrive, strShare
TryMapDrive = Err.Number = 0
End Function

If Ask("Voulez-vous connecter un lecteur réseau ?") Then
strShare = InputBox("Entrez le partage réseau auquel vous voulez vous
connecter ")
For intDrive = 26 To 5 Step -1
If TryMapDrive(intDrive, strShare) Then Exit For
Next

If intDrive <= 5 Then
MsgBox "Impossible de se connecter au partage. "
& _
"Il n'y a plus de lettre de lecteur disponible. " & _
CRLF
& _
"Veuillez déconnecter une connexion existante " & _
"et réessayer. ", _
vbExclamation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strDrive = Chr(intDrive + 64) & ":"
MsgBox "Connexion " & strShare & " au lecteur " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text

If Ask("Voulez-vous déconnecter le lecteur réseau que vous venez de
créer ?") Then
WSHNetwork.RemoveNetworkDrive strDrive

MsgBox "Déconnexion du lecteur " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
End If
End If
End If


' **************************************************
' *
' * WSHNetwork.EnumNetworkDrive
' *
' *
'Demande à l'utilisateur s'il veut énumérer les lecteurs réseau
If Ask("Voulez-vous énumérer les lecteurs réseau ?") Then
'Énumère les lecteurs réseau dans un objet collection de type
WshCollection
Set colDrives = WSHNetwork.EnumNetworkDrives

'Si aucun lecteur réseau n'a été énuméré, alors l'utilisateur en est
'averti ; sinon, les lecteurs sont affichés
If colDrives.Count = 0 Then
MsgBox "Il n'y a pas de lecteur à énumérer.", _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strMsg = "Connexion en cours : " & CRLF
For i = 0 To colDrives.Count - 1 Step 2
strMsg = strMsg & CRLF & colDrives(i) & Chr(9) & colDrives(i +
1)
Next

MsgBox strMsg, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text

End If
End If

'
****************************************************************************
****
' *
' * Bienvenue
' *
Sub Welcome()
Dim intDoIt

intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub







Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"Patrick Fredin" wrote in message
news:#
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: serveurpartage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick










Avatar
Philippe T [MS]
Pas de quoi.

La difficulté c'était juste de remettre la main dessus :-)

Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"Patrick Fredin" wrote in message
news:
Merci. C'est super.

--
Patrick

"Philippe T [MS]" wrote in message
news:
Bonjour,

Voici un exemple complet Ms :

<<<
' Script d'exemple pour l'environnement d'exécution de scripts Windows
'

' ------------------------------------------------------------------------


' Copyright (C) 1996 Microsoft Corporation
'
' Microsoft vous concède le droit d'utiliser, de modifier, de reproduire
' et de distribuer les exemple de fichiers d'application (et/ou toutes
' versions modifiées) comme vous l'entendez, à condition que vous
' reconnaissiez que Microsoft n'a aucune garantie, aucune obligation,
' et aucune responsabilité pour aucun des exemples de fichiers
' d'application.

' ------------------------------------------------------------------------


'
' Cet exemple montre comment utiliser l'objet WSHNetwork.
' Il lit les propriétés réseau (nom d'utilisateur et de l'ordinateur),
' connecte, déconnecte et énumère les lecteurs réseau.


L_Welcome_MsgBox_Message_Text = "Cet exemple montre comment utiliser
l'objet WSHNetwork."
L_Welcome_MsgBox_Title_Text = "Exemple pour l'environnement
d'exécution
de scripts Windows"
Call Welcome()

'

****************************************************************************


****
' *
' * Objet réseau WSH.
' *

Dim WSHNetwork
Dim colDrives, SharePoint
Dim CRLF

CRLF = Chr(13) & Chr(10)
Set WSHNetwork = WScript.CreateObject("WScript.Network")


Function Ask(strAction)

' Cette fonction demande à l'utilisateur s'il veut effectuer une
action


' spécifique et paramètre un code de retour ou quitte l'exécution
' du script suivant le bouton pressé par l'utilisateur. Cette fonction
' est appelée à divers points du script ci-dessous.

Dim intButton
intButton = MsgBox(strAction, _
vbQuestion + vbYesNo, _
L_Welcome_MsgBox_Title_Text )
Ask = intButton = vbYes
End Function

' **************************************************
' *
' * Affiche les propriétés de l'objet WSHNetwork
' *
' *
MsgBox "UserDomain" & Chr(9) & "= " & WSHNetwork.UserDomain & CRLF
&


_
"UserName" & Chr(9) & "= " & WSHNetwork.UserName & CRLF &
_
"ComputerName" & Chr(9) & "= " & WSHNetwork.ComputerName,
_
vbInformation + vbOKOnly,
_
"Propriétés WSHNetwork"

' **************************************************
' *
' * WSHNetwork.AddNetworkDrive
' *
' *

Function TryMapDrive(intDrive, strShare)
Dim strDrive
strDrive = Chr(intDrive + 64) & ":"
On Error Resume Next
WSHNetwork.MapNetworkDrive strDrive, strShare
TryMapDrive = Err.Number = 0
End Function

If Ask("Voulez-vous connecter un lecteur réseau ?") Then
strShare = InputBox("Entrez le partage réseau auquel vous voulez vous
connecter ")
For intDrive = 26 To 5 Step -1
If TryMapDrive(intDrive, strShare) Then Exit For
Next

If intDrive <= 5 Then
MsgBox "Impossible de se connecter au partage. "
& _
"Il n'y a plus de lettre de lecteur disponible. " & _
CRLF
& _
"Veuillez déconnecter une connexion existante " & _
"et réessayer. ", _
vbExclamation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strDrive = Chr(intDrive + 64) & ":"
MsgBox "Connexion " & strShare & " au lecteur " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text

If Ask("Voulez-vous déconnecter le lecteur réseau que vous venez
de


créer ?") Then
WSHNetwork.RemoveNetworkDrive strDrive

MsgBox "Déconnexion du lecteur " & strDrive, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
End If
End If
End If


' **************************************************
' *
' * WSHNetwork.EnumNetworkDrive
' *
' *
'Demande à l'utilisateur s'il veut énumérer les lecteurs réseau
If Ask("Voulez-vous énumérer les lecteurs réseau ?") Then
'Énumère les lecteurs réseau dans un objet collection de type
WshCollection
Set colDrives = WSHNetwork.EnumNetworkDrives

'Si aucun lecteur réseau n'a été énuméré, alors l'utilisateur en est
'averti ; sinon, les lecteurs sont affichés
If colDrives.Count = 0 Then
MsgBox "Il n'y a pas de lecteur à énumérer.", _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text
Else
strMsg = "Connexion en cours : " & CRLF
For i = 0 To colDrives.Count - 1 Step 2
strMsg = strMsg & CRLF & colDrives(i) & Chr(9) & colDrives(i
+


1)
Next

MsgBox strMsg, _
vbInformation + vbOkOnly, _
L_Welcome_MsgBox_Title_Text

End If
End If

'

****************************************************************************


****
' *
' * Bienvenue
' *
Sub Welcome()
Dim intDoIt

intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
vbOKCancel + vbInformation, _
L_Welcome_MsgBox_Title_Text )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub







Phil.
________________________________________________________
Philippe TROTIN http://blogs.msdn.com/ptrotin
Microsoft Services France http://www.microsoft.com/france

"Patrick Fredin" wrote in message
news:#
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: serveurpartage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick














Avatar
Sebastien Piche
tu pouras le trouver a cette adresse
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/

bonne fin journée

"Patrick Fredin" a écrit dans le
message de news:
Merci.

Où peut-on trouver le SDK ?

Encore merci.

--
Patrick

"Sebastien Piche" wrote in message
news:%
oui

voicie la doc tiré du sdk



Adds a shared network drive to your computer system.

object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile],
[strUser], [strPassword])
Arguments
object
WshNetwork object.
strLocalName
String value indicating the name by which the mapped drive will be known
locally.
strRemoteName
String value indicating the share's UNC name (xxxyyy).
bUpdateProfile
Optional. Boolean value indicating whether the mapping information is
stored in the current user's profile. If bUpdateProfile is supplied and
has a value of true, the mapping is stored in the user profile (the
default is false).
strUser
Optional. String value indicating the user name. You must supply this
argument if you are mapping a network drive using the credentials of
someone other than the current user.
strPassword
Optional. String value indicating the user password. You must supply
this argument if you are mapping a network drive using the credentials of
someone other than the current user.
Remarks
An attempt to map a non-shared network drive results in an error.

Example
The following code maps the logical drive "E" to a network share with the
UNC name "ServerPublic."

[VBScript]
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "ServerPublic"
[JScript]
var WshNetwork = WScript.CreateObject("WScript.Network");
WshNetwork.MapNetworkDrive ("E:", "\ServerPublic");
See Also
EnumNetworkDrives Method | RemoveNetworkDrive Method

Applies To: WshNetwork Object



"Patrick Fredin" a écrit dans le
message de news: %
Bonjour,

Avec un fichier .BAT, on peut mapper un lecteur avec cette commande :

net use M: serveurpartage1

Existe-t-il la même chose avec VBScript ?

Merci pour votre aide.


--
Patrick