Message d'erreur script vbs

whyata Messages postés 204 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 22 mars 2011 - 15 janv. 2009 à 18:18
whyata Messages postés 204 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 22 mars 2011 - 16 janv. 2009 à 10:27
Bonjour,


Le script suivant cherche les lecteurs à mapper selon mon OU et mappe les lecteurs à l'ouverture de session


Donc avec mon script

Code :
Dim WshShell
Dim objNet
Dim objRootDSE
Dim Tab
Dim DN
Dim i
Dim strComputer
DN = ""
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objNet = WScript.CreateObject("WScript.Network")' create network object for vars
Set objRootDSE = GetObject("LDAP://rootDSE")' bind to the rootDSE for portability
strADsConfPath = "LDAP://" & objRootDSE.Get("configurationNamingContext")' bind to configuration to get Domain Controllers later
strRootDSE = objRootDSE.Get("defaultNamingContext")' bind to the defaultContext for portability
strUserName = UCase(objNet.UserName)' pull user name from environment variable
Tab = Split(GetDNUser(strUserName,"person"),",")
 
For i=1to UBound(Tab)
If i = Ubound(Tab)Then
 
DN = DN + Tab(i)
Else
DN = DN + Tab(i) + ","
EndIf
Next
'MsgBox DN
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open"Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from " _
& "'LDAP://"&DN&"' where objectClass='volume'"
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
DoUntil objRecordSet.EOF
'Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
msgbox objRecordSet.Fields("Name").Value
msgbox objRecordSet.Fields("uNCName").Value
 
Dim oNet
Set oNet = CreateObject("Wscript.Network")
oNet.MapNetworkDrive objRecordSet.Fields("Name").Value, objRecordSet.Fields("uNCName").Value
objRecordSet.MoveNext
 
Loop
 
Function GetDNUser(param1,param2)
Set objDSE = GetObject("LDAP://rootDSE")
ONERRORRESUMENEXT
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open"Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT distinguishedName, Sn " & "FROM 'LDAP://" & objDSE.Get("defaultNamingContext") & "' " & "WHERE objectCategory='" & param2 & "' AND sAMAccountName='" & param1 & "' " & "ORDER BY sAMAccountName"
Set objRecordSet = objCommand.Execute
GetDNUser = objRecordSet.Fields("distinguishedName")
objConnection.Close
if err.number <> 0then
msgbox "ERREUR: le nom renseigné n'existe pas dans l'AD.",16,Wscript.ScriptName & " " & version
ERR.CLEAR
wscript.quit
endif
EndFunction
MsgBox "Mappage effectué"
 

j'ai mes lecteurs qui sont bien mappé mais mon soucis c'est que j'ai ce message qui arrive quand je me reloge


( windows script host):

Script: \\chemin de mon script

Line:36

Char:1

Error: Either BOF or EOF is true, or the current record has been deleted.request operation requires a current record.

Code: 800A0BCD

Source: ADODB.Recordest


Je suis nulle en vbscript, ce n'est pas moi qui l'ai fait mais on m'a
dit que je peux oté les msgbox j'en ai oté et depuis j'ai ce message à
l'ouverture de session.


( windows script host):

Script: \\chemin de mon script

Line: 41

Char:1

Error: the local device name is already in use

Code: 80070055

Source: WSHNetwork.MapNetworkDrive


et voici le nouveau script qui me donne le message d'erreur ci dessus:

Code :
Dim WshShell
Dim objNet
Dim objRootDSE
Dim Tab
Dim DN
Dim i
Dim strComputer
DN = ""
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objNet = WScript.CreateObject("WScript.Network")' create network object for vars
Set objRootDSE = GetObject("LDAP://rootDSE")' bind to the rootDSE for portability
strADsConfPath = "LDAP://" & objRootDSE.Get("configurationNamingContext")' bind to configuration to get Domain Controllers later
strRootDSE = objRootDSE.Get("defaultNamingContext")' bind to the defaultContext for portability
strUserName = UCase(objNet.UserName)' pull user name from environment variable
Tab = Split(GetDNUser(strUserName,"person"),",")
 
For i=1to UBound(Tab)
If i = Ubound(Tab)Then
 
DN = DN + Tab(i)
Else
DN = DN + Tab(i) + ","
EndIf
Next
 
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open"Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from " _
& "'LDAP://"&DN&"' where objectClass='volume'"
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
DoUntil objRecordSet.EOF
 
Dim oNet
Set oNet = CreateObject("Wscript.Network")
oNet.MapNetworkDrive objRecordSet.Fields("Name").Value, objRecordSet.Fields("uNCName").Value
objRecordSet.MoveNext
 
Loop
 
Function GetDNUser(param1,param2)
Set objDSE = GetObject("LDAP://rootDSE")
ONERRORRESUMENEXT
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open"Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT distinguishedName, Sn " & "FROM 'LDAP://" & objDSE.Get("defaultNamingContext") & "' " & "WHERE objectCategory='" & param2 & "' AND sAMAccountName='" & param1 & "' " & "ORDER BY sAMAccountName"
Set objRecordSet = objCommand.Execute
GetDNUser = objRecordSet.Fields("distinguishedName")
objConnection.Close
if err.number <> 0then
msgbox "ERREUR: le nom renseigné n'existe pas dans l'AD.",16,Wscript.ScriptName & " " & version
ERR.CLEAR
wscript.quit
endif
EndFunction
 

Je souhaiterai enlever toutes les msgbox, puisque le script
fonctionne tous mes lecteurs sont mappés et j'y ai accès correctement

3 réponses

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
15 janv. 2009 à 19:16
 Bonsoir,

Line: 41
Char:1
Error: the local device name is already in use

Il faut donc utiliser la méthode
RemoveNetworkDrive de l'objet NetWork
pour déconnecter le lecteur après son utilisation.
object.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]

On error resume next
oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value
On error goto 0
Set oNet = nothing

jean-marc
0
whyata Messages postés 204 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 22 mars 2011
16 janv. 2009 à 09:34
Merci pour ton aide jean-marc parce que je ne m'y connais vraiment pas, merci encore de te pencher sur mon problème. Donc :
" On error resume next
oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value
On error goto 0
Set oNet = nothing"

je dois le mettre où?
0
whyata Messages postés 204 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 22 mars 2011
16 janv. 2009 à 10:27
Maintenant dès que je lance VbsEdit j'ai ce message d'erreur
Line:51
Column:3
Error: (null)
code: 80004005
Source: (null)

Dim WshShell
Dim objNet
Dim objRootDSE
Dim Tab
Dim DN
Dim i
Dim strComputer
DN = ""
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objNet = WScript.CreateObject("WScript.Network")' create network object for vars
Set objRootDSE = GetObject("LDAP://rootDSE")' bind to the rootDSE for portability
strADsConfPath = "LDAP://" & objRootDSE.Get("configurationNamingContext")' bind to configuration to get Domain Controllers later
strRootDSE = objRootDSE.Get("defaultNamingContext")' bind to the defaultContext for portability
strUserName = UCase(objNet.UserName)' pull user name from environment variable
Tab =  Split(GetDNUser(strUserName,"person"),",")
 
For i=1 to UBound(Tab)
 If i = Ubound(Tab) Then
 
 DN = DN + Tab(i)
 Else
 DN = DN + Tab(i) + ","
 End If
Next
'MsgBox DN
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from " _
    & "'LDAP://"&DN&"' where objectClass='volume'"
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    'Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
    msgbox objRecordSet.Fields("Name").Value
    msgbox objRecordSet.Fields("uNCName").Value
 
Dim oNet
Set oNet = CreateObject("Wscript.Network")
oNet.MapNetworkDrive objRecordSet.Fields("Name").Value, objRecordSet.Fields("uNCName").Value
objRecordSet.MoveNext
 
Loop
 
Function GetDNUser(param1,param2)

  Set objDSE = GetObject("ldap://rootDSE")
  ON ERROR RESUME NEXT
  Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Provider=ADsDSOObject;"
  Set objCommand = CreateObject("ADODB.Command")
  objCommand.ActiveConnection = objConnection
  objCommand.CommandText = "SELECT distinguishedName, Sn " & "FROM 'LDAP://" & objDSE.Get("defaultNamingContext") & "' " & "WHERE objectCategory='" & param2 & "' AND sAMAccountName='" & param1 & "' " & "ORDER BY sAMAccountName"
  Set objRecordSet = objCommand.Execute
  GetDNUser = objRecordSet.Fields("distinguishedName")
  objConnection.Close
  if err.number <> 0 then
    msgbox "ERREUR: le nom renseigné n'existe pas dans l'AD.",16,Wscript.ScriptName & " " & version
    ERR.CLEAR
    wscript.quit
  end if
End Function
MsgBox "Mappage effectué"
0
Rejoignez-nous