Bonjour, cela fait plusieurs jours que je suis sur le script. Il ne fonctionne pas. Il s'affiche une erreur comme quoi le périphérique local est déja utilisé alors que ce n'est pas le cas.

L'erreur intervient à la fin du script dans ma partie "MONTAGE ET CONNEXION DES LECTEURS RESEAUX " et "REMONTEES DES LECTEURS RESEAUX" soit WSHNetwork.MapNetworkDrive "Q:" , "\\XX-DSM\Autre", False, varUser, varPassword.

Puis-je avoir votre aide s'il vous plaît ? Merci d'avance

Voila mon code (désolé, il est long)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
'	DESACTIVATION DE L'UAC                                                                                                                                                                                                '
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
 
Option Explicit
 
'---- Déclaration des variables -------------------------------------------------------------------------------------------------------------------------------------------------------------
Dim ObjetRegedit, CleRegistre, WshShell, ObjetNetwork, objNetwork, run, shl, oProcess, hostsNewLine, hostsNewLineLocal, fso, WinDir, HostsFile, objFSO, objFile, filetxt, x, varUser, varPassword, bKey, pKey, WSHNetwork
 
'---- Definition du contenu de la variable ---------------------------------------------------------------------------------------------------------------------------------------
Set ObjetRegedit = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set shl = createobject("wscript.shell")
Set WshShell = WScript.CreateObject("WScript.Shell")
 
'---- Execution des droits administrateurs ---------------------------------------------------------------------------------------------------------------------------------------
If Not WScript.Arguments.Named.Exists("elevate") Then
  CreateObject("Shell.Application").ShellExecute WScript.FullName _
    , WScript.ScriptFullName & " /elevate", "", "runas", 1
	WScript.Quit
End If
 
'---- Récupération du contenu de la clef, placement dans la variable "CleRegistre" ----------------------------------------------------------------------------------------------------------------------------------------
CleRegistre = ObjetRegedit.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA")
 
'---- Lecture de la clé de registre. Si la valeur est égale à 1 tout est correct sinon la clé qui est égale à 0 doit être supprimée puis créée avec la valeur 1.
If TypeName(CleRegistre) = "Empty" Then
	Else
	If CleRegistre = "1" then'
		'---- Suppression de la clé de registre
		shl.run "cmd /c REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f"
 
		'---- Création des valeurs et son type "REG_DWORD".
		shl.run "cmd /c REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f"
 
	End If
End if
 
'msgbox "Coupure1" 
 
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
'	AJOUTER DANS LE FICHIER HOSTS                                                                                                                                                                                         '
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
 
Const ForReading = 1, ForWriting = 2, ForAppending = 8, ReadOnly = 1
'msgbox "Coupure2"
'---- Ajout des lignes dans le fichier hosts ------------------------------------------------------------------------------------------------------------------------------------------------------ 
hostsNewLine = "	10.8.XX.XX		XX-DSM"
hostsNewLineLocal = "	172.16.XX.XX	XX-DSM"
'msgbox "Coupure2.1"
'---- Modificatication du fichier hosts ---------------------------------------------------------------------------------------------------------------------------------------------------------
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell=CreateObject("WScript.Shell")
WinDir =WshShell.ExpandEnvironmentStrings("%WinDir%")
'msgbox "Coupure2.2"
'----
HostsFile = WinDir & "\System32\Drivers\etc\Hosts"
'msgbox "Coupure3"
'----
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(HostsFile, ForReading)
'msgbox "Coupure4"
'----
Do Until objFile.AtEndOfStream
If InStr (objFile.ReadLine, hostsNewLine) <> 1 Then
'WScript.Quit
End If
Loop
'objFile.Close
'msgbox "Coupure5" 
'----
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(HostsFile)
If objFile.Attributes AND ReadOnly Then
objFile.Attributes = objFile.Attributes XOR ReadOnly
End If
 
'---- Execution des droits administrateurs -----------------------------------------------------------------------------------------------------------------------------------------------------
If Not WScript.Arguments.Named.Exists("elevate") Then
  CreateObject("Shell.Application").ShellExecute WScript.FullName _
    , WScript.ScriptFullName & " /elevate", "", "runas", 1
  WScript.Quit
End If
 
'----
Set filetxt = fso.OpenTextFile(HostsFile, ForAppending, True)
filetxt.WriteLine(vbNewLine & hostsNewLine)
filetxt.WriteLine(vbNewLine & hostsNewLineLocal)
filetxt.Close
 
'---- Destruction des objets ----------------------------------------------------------------------------------------------------------------------------------------------------------------
Set ObjetRegedit = Nothing
 
'---- Quitter le script ------------------------------------------------------------------------------------------------------------------------------------------------------------------
'WScript.Quit
 
'msgbox "Coupure6"
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
'	ACTIVATION DE L'UAC                                                                                                                                                                                                   '
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
'msgbox "Coupure7" 
'---- Definition du contenu de la variable -----------------------------------------------------------------------------------------------------------------------------------------------
'Set ObjetRegedit = CreateObject("WScript.Shell")
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set shl = createobject("wscript.shell")
'Set WshShell = WScript.CreateObject("WScript.Shell")
'msgbox "Coupure8" 
 
'---- Execution des droits administrateurs --------------------------------------------------------------------------------------------------------------------------------------------------------------------
'If Not WScript.Arguments.Named.Exists("elevate") Then
'  CreateObject("Shell.Application").ShellExecute WScript.FullName _
'    , WScript.ScriptFullName & " /elevate", "", "runas", 1
'  WScript.Quit
'End If
'msgbox "Coupure9"
 
'---- Récupération du contenu de la clef, placement dans la variable "CleRegistre" ---------------------------------------------------------------------------------------------------
'CleRegistre = ObjetRegedit.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA")
 
'---- Lecture de la clé de registre. Si la valeur est égale à 0 alors le rajout de la ligne dans le fichier host est à effectuer sinon la clé qui est égale à 1 doit être supprimée --
'---- puis créée avec la valeur 0. ---------------------------------------------------------------------------------------------------------------------------------------------------
'msgbox "Coupure10"
'If TypeName(CleRegistre) = "Empty" Then
	'MsgBox "Clef registre inexistante"
'	Else
	'MsgBox "Valeur de CleRegistre " & CleRegistre
'	If CleRegistre = "0" then
'msgbox "Coupure11"
	'---- Suppression de la clé de registre ------------------------------------------------------------------------------------------------------------------------------------------
'		shl.run "cmd /c REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f"
'msgbox "Coupure11.1"
		'---- Création des valeurs et son type "REG_DWORD" ---------------------------------------------------------------------------------------------------------------------------
'		shl.run "cmd /c REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1 /f"
'msgbox "Coupure12"
      '  MsgBox "Je suis bien passé dans le If de CleRegistre = 0, passage à valeur 1 FAIT"
      ' Else
      '  MsgBox "Je suis bien passé dans le If de CleRegistre = 0, donc pas de modification"
'	End If
'End if
'msgbox "Coupure13"
 
'---- Destruction des objets ---------------------------------------------------------------------------------------------------------------------------------------------------------
'Set ObjetRegedit = Nothing
 
'---- Quitter le script ----------------------------------------------------------------------------------------------------------------------------------------------
'WScript.Quit
 
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
'	RENOMMAGE DES LECTEURS RESEAUX                                                                                                                                                   '
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
 
Set WshShell = WScript.CreateObject("WScript.Shell")
 
'msgbox "Coupure14"
Set WshShell = CreateObject("WScript.Shell")
 
pkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##XX-DSM#Autre\_LabelFromReg"
WshShell.RegWrite pKey, "Autre"
 
 
'---- Destruction des objets ------------------------------------------------------------------------------------------------------------------------------------------
Set ObjetRegedit = Nothing
 
'---- Quitter le script ----------------------------------------------------------------------------------------------------------------------------------------------
'WScript.Quit
 
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
'	MONTAGE ET CONNEXION DES LECTEURS RESEAUX                                                                                                                                        '
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
 
'/!\ PROBLEME :!\
 
'msgbox "Coupure15"
'---- Informations de connexion à la session -----------------------------------------------------------------------------------------------------------------------------------------
varUser = "XX"
varPassword = "XX"
 
'---- Definition du contenu de la variable -------------------------------------------------------------------------------------------------------------------------------------------
Set WSHNetwork = WScript.CreateObject("WScript.Network")
 
'---- Permet de continuer le script même s'il y a une erreur ----------------------------------------------------------------------------------------------------------------------------
'On Error on error
 
'msgbox "Coupure16"
 
'---- REMONTEES DES LECTEURS RESEAUX -------------------------------------------------------------------------------------------------------------------------------------------------
WSHNetwork.MapNetworkDrive "Q:" , "\\XX-DSM\Autre", False, varUser, varPassword
 
'msgbox "Coupure17"
'On Error GoTo 0
'msgbox "Coupure18"
'*** Destruction des objets
Set ObjetNetwork = Nothing
'msgbox "Coupure final Script Fini"
'WScript.Quit