IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Problème avec mon script


Sujet :

VBScript

  1. #41
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    je n'ai pas compris tes dernières réponses.

  2. #42
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 42
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par ced600 Voir le message
    je n'ai pas compris tes dernières réponses.
    Non en fait sur mon poste (sur lequel le logiciel Vbedit est installé et sur lequel j'ai créé et testé le script) au lieu de me mapper les lecteurs quand je me loge il me lance le script

    J'ai rajouté au début de mon script un bout de code pour supprimer tous les lecteurs réseaux présents sur les postes ça fonctionne mais pour certains postes, j'ai le message d'erreur que les lecteurs est déjà utilisé.

    Je ne suis pas censée avoir ça comme erreur puisque la partie que j'ai rajouté, supprime les lecteurs voici mon code:

    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
    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"),",")
     
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to oDrives.Count - 1 Step 2
    WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
    Next
     
    'MsgBox "Lecteurs supprimés"
     'Supprimer les anciens lecteurs
    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é"

  3. #43
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 42
    Points : 12
    Points
    12
    Par défaut
    Voici mon nouveau code:
    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
    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"),",")
    Set oNet= WScript.CreateObject("WScript.Network")
     
    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") 
     
    On error resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value
    On error goto 0
     
    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é"
    Pour certains utilisateurs ça passe sans problème et d'autres ça fait ramer leur pc et leur CPU est à fond

  4. #44
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 42
    Points : 12
    Points
    12
    Par défaut
    Je sais pas si ça peut aider mais je pense que c'est au niveau de cette ligne que ça pose problème:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    oNet.MapNetworkDrive objRecordSet.Fields("Name").Value, objRecordSet.Fields("uNCName").Value
    objRecordSet.MoveNext
    Je voudrais faire que si le lecteur existe déjà qu'il ne le mappe pas et qu'il passe au suivant comment faire?

  5. #45
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 42
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par RadPAT Voir le message
    ok,

    place ceci pour voir combien d'enregistrements sont trouvés :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    ....
    Set objRecordSet = objCommand.Execute
    msgbox objRecordset.RecordCount 
    
    objRecordSet.MoveFirst
    Do ....
    si ca te retourne 0, c'est que ta requete est à revoir.

    A++
    J'ai fait mon test aevc mon nouveau script. Il me retourne comme valeur 1

  6. #46
    Membre à l'essai
    Inscrit en
    Décembre 2008
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2008
    Messages : 42
    Points : 12
    Points
    12
    Par défaut
    Voilà je vous ai assez embeté:

    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
    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"),",")
     
    Set WshNetwork = WScript.CreateObject("WScript.Network")
     
    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
     
    Dim oNet 
    Set oNet = CreateObject("Wscript.Network")
     
    Do Until objRecordSet.EOF
     
     
     
        'Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
        'msgbox objRecordSet.Fields("Name").Value
        'msgbox objRecordSet.Fields("uNCName").Value
     
    On Error Resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value,True,True 
    On Error Goto 0
     
    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
     
    set WshShell = CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
     
     
    if WshShell.ExpandEnvironmentStrings("%OS%") <> "Windows_NT" then
      WshShell.Run "COMMAND.EXE /C NET TIME \\BTW-USER1 /SET /Y >NUL:"
     
      DomainName=WshShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MSNP32\NetworkProvider\AuthenticatingAgent")
      Set UserObj = GetObject("WinNT://" & DomainName & "/" & WshNetwork.username)
     
     
     'msgbox (UserObj.homeDrive)
     'msgbox (UserObj.HomeDirectory)
     
    else
     
      DomainName=WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
      Set UserObj = GetObject("WinNT://" & DomainName & "/" & WshNetwork.username)
     
    end if
     
    'wscript.echo "Bonjour "&WshNetwork.username&" connecté sur "&WshNetwork.computername
     
     
    'Init Groups
    Dim UserGroups
    Dim GroupObj
    UserGroups=""
    For Each GroupObj In UserObj.Groups
      UserGroups=UserGroups & "[" & GroupObj.Name & "]"
    Next
     
    'wscript.echo "Membre de "&UserGroups
     
     
     
    if InGroup("Nom du groupe") Then
     
    On Error Resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value,True,True 
      WshNetwork.MapNetworkDrive "Z:","\\mon serveur\mon partage"
    On Error Goto 0
    End if
     
    if InGroup("Nom du groupe") Then
     
    On Error Resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value,True,True 
    WshNetwork.MapNetworkDrive "K:","\\mon serveur\mon partage"
    On Error Goto 0
    End If
     
    if InGroup("Nom du groupe") Then
     
    On Error Resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value,True,True 
    WshNetwork.MapNetworkDrive "P:","\\mon serveur\mon partage"
    On Error Goto 0
    End If
     
    if InGroup("Nom du groupe") Then
     
    On Error Resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value,True,True 
    WshNetwork.MapNetworkDrive "V:","\\mon serveur\mon partage"
    On Error Goto 0
    End if
     
    if InGroup("Nom du groupe") Then
     
    On Error Resume next
    oNet.RemoveNetworkDrive objRecordSet.Fields("Name").Value,True,True 
    WshNetwork.MapNetworkDrive "V:","\\mon serveur\mon partage"
    On Error Goto 0
    End if
     
     
     
    '
    Function InGroup(strGroup)
     InGroup=False
     If InStr(UserGroups,"[" & strGroup & "]") Then
       InGroup=True
     End If
    End Function
     
    'MsgBox "Mappage effectué"

  7. #47
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Désolé je n'ai pas pu répondre dernièrement et j'ai perdu un peu le file de la discussion.

    Cette historie de lancement de script au démarrage, c normal je pense.

    Tu as fait quoi ? Tu as utilisé les GPO pour que ton script soit lancé à l'ouverture d'une session ?

    Pour mapper tes lecteurs il faut bien lancer le script nom ?

    mais pour certains postes, j'ai le message d'erreur que les lecteurs est déjà utilisé.
    Bah c peut être le cas, et dans ce cas là tu ne peux pas les supprimer de suites.
    L'utilisation est temporaire.
    Il faudrait que tu repères l'erreur mis dans l'objet err, et tu testes l'erreur.
    Tant que tu as l'erreur tu temporise puis retente la suppression.

+ Répondre à la discussion
Cette discussion est résolue.
Page 3 sur 3 PremièrePremière 123

Discussions similaires

  1. [PHP-JS] problème avec mon script de connexion
    Par agencep dans le forum Langage
    Réponses: 5
    Dernier message: 31/01/2008, 17h08
  2. [MySQL] Divers petits problèmes avec mon script
    Par fourniey dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 26/12/2007, 16h20
  3. Problème avec mon script shell case in esac
    Par Olivier Regnier dans le forum Shell et commandes GNU
    Réponses: 2
    Dernier message: 28/06/2007, 22h54
  4. Problème avec mon script
    Par Toinou0123 dans le forum PHP & Base de données
    Réponses: 10
    Dernier message: 30/09/2006, 18h37
  5. [Mail] Problème avec mon script d'envoi de mail
    Par leroivert dans le forum Langage
    Réponses: 18
    Dernier message: 02/12/2005, 00h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo