Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2940 connectés 

  FORUM HardWare.fr
  Windows & Software
  Win NT/2K/XP

  Comment forcer la mise à jour d'un script sous Windows 2000 Server ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment forcer la mise à jour d'un script sous Windows 2000 Server ?

n°2655631
flashy_fib​er
Posté le 06-03-2007 à 18:15:26  profilanswer
 

Je suis en Win 2000 Server SP4.
 
Dans le script(.bat) de connexion d'un utilisateur, je l'ai mis à jour en changeant l'imprimante par défaut, mais à chaque fois que je me reconnecte, j'ai tjs la meme imprimante qu'auparavant, et la nouvelle imprimante n'est tjs pas créée.
 
La ligne que j'ai modifié est la suivante :
 
\\Serveur\SYSVOL\domaine.fr\scripts\con2prt /cd \\ServeurImpression\PartageImprimante
 
Si qq un a une idée pour forcer cette mise à jour, merci d'avance

mood
Publicité
Posté le 06-03-2007 à 18:15:26  profilanswer
 

n°2655661
Requin
Posté le 06-03-2007 à 18:54:00  profilanswer
 

Perso je referais le script en VBS, c'est plus fiable, plus rapide et bcp plus souple que ces vieux batch...
 
En voici un qui fait pas mal de choses, connexions de lecteurs réseaux en fonction du groupe auquel appartient un utilisateur, connexions d'imprimantes, définir laquelle est par défaut, copie d'icône sur le bureau patchage de la registry à l'aide fichiers regs (tu peux aussi le faire via GPO)... évidemment à adapter / compléter. Tu trouves de la doc VBScript sur les MSDN, sinon tu as les Script Center chez MS dans le Technet.
 

'
' Customer  : Nom du client
' Filename  : logon.vbs
' Author    : Cédric Rathgeb
' Date      : 2005-06-20
' Update    : 2006-01-09
' Version   : 2.2.4
' Copyright : Public Domain
' Warranty  : None
'  
 
On Error Resume Next
 
bDebug = False
dTime1 = now()
 
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
BS = Chr(92) ' Backslash
DBS = BS & BS ' Double Backslash
 
Set wshNetwork = WScript.CreateObject("WScript.Network" )
Set wshShell = WScript.CreateObject("WScript.Shell" )
Set wshSysEnv = wshShell.Environment("SYSTEM" )
sUser = LCase(wshShell.ExpandEnvironmentStrings("%USERNAME%" ))
sComputer =  LCase(wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%" ))
sServer = "NOMSERVEUR"
sRunOnceFile = "U:\runoncefile.txt"
sLDAPPath = "LDAP://dc=domaine,dc=local"
sGroup = GetPrimaryGroup(sUser, sLDAPPath)
 
Select Case LCase(sGroup)
  Case "juridique", "marketing", "secrétariat général"
    sGroupUser = "état major" & BS & sGroup
    sGroup = "état major"
  Case "cave", "divers", "services aux locataires", "valeurs"
    sGroupUser = "divers" & BS & sGroup
    sGroup = "divers"
  Case Else
    sGroupUser = sGroup
End Select
 
dTime2 = Now()
 
' The pairs are "drive" and "share"
aryShares   = Array(Array("T:", DBS & sServer & BS & "ClientApps" ), _
                    Array("U:", DBS & sServer & BS & "utilisateurs$" & BS & sGroupUser & BS & sUser), _
                    Array("V:", DBS & sServer & BS & "groupes$" & BS & sGroup & BS & "@commun" ), _
                    Array("W:", DBS & sServer & BS & "groupes$" ), _
                    Array("X:", DBS & sServer & BS & "commun$" ))
' The pairs are "printers" and "default printer for computers"
aryPrinters = Array(Array(DBS & sServer   & BS & "comptabilite_hp_laserjet_color_4600n", "apicella;laureau" ), _
                    Array(DBS & sServer   & BS & "comptabilite_hp_laserjet_2420", "andre" ), _
                    Array(DBS & sServer   & BS & "couloir_hp_laserjet_4050n", "bchatelain;ecuyer;reception1;reserve;schmid" ), _
                    Array(DBS & sServer   & BS & "couloir_hp_laserjet_5si", "" ), _
                    Array(DBS & sServer   & BS & "couloir_photocopieuse_sharp", "" ), _
                    Array(DBS & sServer   & BS & "couloir_hp_business_inkjet_2800_a3", "" ), _
                    Array(DBS & "golay"   & BS & "quai_hp_psc_2210", "" ), _
                    Array(DBS & "magasin" & BS & "quai_hp_laserjet_3015", "magasin", "" ), _
                    Array(DBS & "treand"  & BS & "quai_hp_laserjet_1012", "treand;lacotte", "" ), _
                    Array(DBS & "arianne" & BS & "etatmajor_brother_hl_1230", "arianne;may", "" ), _
                    Array(DBS & "lavanchy" & BS & "brotherm", "", "" ), _
                    Array(DBS & "benoist" & BS & "valeur_hp_980cxi", "benoist;flilipone" ))
 
' Search account in Active Directory
'   Return AD distinguished name or an empty string if not found
Function GetADDistinguishedName(sAccount, sADPath)
  Set oConnection = CreateObject("ADODB.Connection" )
  oConnection.Open "Provider=ADsDSOObject;"
  Set oCommand = CreateObject("ADODB.Command" )
  oCommand.ActiveConnection = oConnection
  oCommand.CommandText = "<" & sADPath & ">;(&(objectCategory=User)(samAccountName=" & sAccount & " ));samAccountName,distinguishedName;subtree"
  Set oRecordSet = oCommand.Execute
  If oRecordset.RecordCount = 0 Then
    ' Not found !
    GetADDistinguishedName = ""
  Else
    GetADDistinguishedName = oRecordset.Fields("distinguishedName" )
  End If
  oConnection.Close
End Function
 
' Get groups a user belongs to
'   Return an array or empty
Function GetADGroupsUserBelongsTo(sAccount, sADPath)
  Set oUser = GetObject("LDAP://" & GetADDistinguishedName(sAccount, sADPath))
  aryMemberOf = oUser.GetEx("memberOf" )
  If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    ' Not Fount !
    GetADGroupsUserBelongsTo = Array()
  Else
    GetADGroupsUserBelongsTo = aryMemberOf
  End If
End Function
 
' Get primary group for this user
'    Return a string with groupname (note : removes "Groupe " from groupname)
'    an empty string if not found
Function GetPrimaryGroup(sAccount, sADPath)
  Set oUser = GetObject("LDAP://" & GetADDistinguishedName(sAccount, sADPath))
  iPrimaryGroupID = oUser.Get("primaryGroupID" )
  If Not(Err.Number = E_ADS_PROPERTY_NOT_FOUND) Then
    Set oConnection = CreateObject("ADODB.Connection" )
    oConnection.Open "Provider=ADsDSOObject;"
   
    Set oCommand = CreateObject("ADODB.Command" )
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<" & sADPath & ">;(objectCategory=Group);distinguishedName,primaryGroupToken;subtree"  
    Set oRecordSet = oCommand.Execute
    Do Until oRecordset.EOF
      If oRecordset.Fields("primaryGroupToken" ) = iPrimaryGroupID Then
        sGroup = oRecordset.Fields("distinguishedName" )
      End If
      oRecordset.MoveNext
    Loop
    sGroup = Right(sGroup, Len(sGroup) - 10)
    sGroup = Left(sGroup, InStr(sGroup, "," ) - 1)
    GetPrimaryGroup = sGroup
    oConnection.Close
  Else
    GetPrimaryGroup = ""
  End If
End Function
 
' Disconnects all drives
Sub DisconnectDrives()
  ' Connect drives
  Set colDrives = wshNetwork.EnumNetworkDrives
  For i = 0 To colDrives.Count - 1 Step 2
    wshNetwork.RemoveNetworkDrive colDrives(i)
  Next
End Sub
 
' Map drive
Sub MapDrive(sDrive, sShare)
  wshNetwork.MapNetworkDrive sDrive, sShare
End Sub
 
' Disconnect all printers
Sub DisconnectPrinters()
  Set colPrinters = wshNetwork.EnumPrinterConnections
  For i = 0 To colPrinters.Count - 1 Step 2
    wshNetwork.RemovePrinterConnection colPrinters(i)
  Next
End Sub
 
' Map printer
Sub MapPrinter(sPrinter)
  wshNetwork.AddWindowsPrinterConnection sPrinter
End Sub
 
' Set Default Printer
Sub SetDefaultPrinter(sPrinter)
  wshNetwork.SetDefaultPrinter sPrinter
End Sub
 
 
dTime3 = Now()
' Remove previous connections
DisconnectDrives
 
dTime4 = Now()
' Connect shares to local drives
For i = LBound(aryShares) to UBound(aryShares)
  aryAux = aryShares(i)
  MapDrive aryAux(0), aryAux(1)
Next
 
dTime5= Now()
' Check if printers are allready installed
Set oFSO = CreateObject("Scripting.FileSystemObject" )
' Get file in user's share and read it
bPrintersInstalled = False
If oFSO.FileExists(sRunOnceFile ) Then
  Set oTextFile = oFSO.OpenTextFile(sRunOnceFile , 1, 0)
  sPrintersText = oTextFile.ReadAll
  oTextFile.Close
  Set oTextFile = Nothing
  ' Search if computer is already installed
  If InStr(sPrintersText, sComputer) > 0 Then
    bPrintersInstalled = True
  End If
End If
' Do not install printers on the server
If sComputer = "pfegsrv1" Then
  bPrintersInstalled = True
End If
 
' Do not do this part at the airport, and don't redo this part
' of code if printers are allready installed on the computer
If (LCase(sComputer) <> "lavanchy" AND LCase(sComputer) <> "aeroport-01" ) AND Not(bPrintersInstalled) Then
   
  DisconnectPrinters
 
  ' Connect printers
  For i = LBound(aryPrinters) to UBound(aryPrinters)
    aryAux = aryPrinters(i)
    MapPrinter aryAux(0)
    aryComputers = Split(aryAux(1), ";" )
    For j = LBound(aryComputers) to UBound(aryComputers)
      If sComputer = aryComputers(j) Then
        SetDefaultPrinter(aryAux(0))
      End If
    Next
  Next
 
  ' Copy Icons on User's Desktop
  sSource = DBS & "pfegsrv1" & BS & "ClientApps" & BS & "icons" & BS & "*.*"
  sDestination = "C:" & BS & "documents and settings" & BS & sUser & BS & "bureau"
  oFSO.CopyFile sSource, sDestination, True
 
  ' Add default paths keys for Word and Excel XP & 2003
  wshShell.Run("regedit /s word_excel_paths.reg" )
  wshShell.Run("regedit /s num_lock_on.reg" )
 
  ' Add to printer's file the current computer name
  Set oTextFile = oFSO.CreateTextFile(sRunOnceFile , True, False)
  sPrintersText = sPrintersText & sComputer & vbCrLf
  oTextFile.Write sPrintersText
  oTextFile.Close
  Set oTextFile = Nothing
   
End If
 
If bDebug Then
  msgbox "Ordinateur : " & sComputer & ". " &_
         "Temps AD : " & datediff("s", dTime1, dTime2) & ". " &_
         "Temps définition : " & datediff("s", dTime2, dTime3) & ". " &_
         "Temps disques déconnexion : " & datediff("s", dTime3, dTime4) & ". " &_
         "Temps disques connexion : " & datediff("s", dTime4, dTime5)  & ". " &_
         "Temps imprimantes : " & datediff("s", dTime5, Now()) & ". " &_
         "Temps total : " & datediff("s", dTime1, Now()) & "."
End If
 
' Delete objects
Set oFSO = Nothing
Set wshNetwork = Nothing
Set wshShell   = Nothing
Set wshSysEnv  = Nothing


Message édité par Requin le 06-03-2007 à 18:55:23
n°2655715
flashy_fib​er
Posté le 06-03-2007 à 20:32:08  profilanswer
 

Ok merci pour cet exemple. C'est clair que c'est un langage plus évolué que le batch utilisé sur nos serveurs, mais pour le moment je maitrise pas du tout ce langage , mais j'ai bien pris note de ton exemple.
 
Sinon, si t'as une idée pour faire fonctionner cette ligne de commande , merci d'avance
 
Si d'autres ont des idées aussi , n'hesitez pas, merci

n°2655734
flashy_fib​er
Posté le 06-03-2007 à 21:10:47  profilanswer
 

:bounce:

n°2655774
flashy_fib​er
Posté le 06-03-2007 à 22:18:38  profilanswer
 

:bounce:

n°2893923
hfrfc
Bob c'est plus simple à dire..
Posté le 16-09-2009 à 12:12:59  profilanswer
 

flag


---------------
D3/Hots/Hs Doc#2847

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Windows & Software
  Win NT/2K/XP

  Comment forcer la mise à jour d'un script sous Windows 2000 Server ?

 

Sujets relatifs
Micro inaudible ou muet sous windows xp (résolu)aider moi (Windows vista)
demande de renseignement concernant microsoft exchange 2003 serverIcônes ecran accueil Windows surlignées ????
PB d'installation Windows x64 depuis RIS (32bits)Windows 32 ou 64 bit pour athlon 64?
peripheriques audio windows[Résolu] Problème SNMP sous Windows 2003 Server
Excel 2000 : cellule ou texte clignotant 
Plus de sujets relatifs à : Comment forcer la mise à jour d'un script sous Windows 2000 Server ?


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR