leSaleGauSS
Messages postés148Date d'inscriptionsamedi 4 novembre 2006StatutMembreDernière intervention 4 décembre 2008
-
15 déc. 2006 à 21:47
leSaleGauSS
Messages postés148Date d'inscriptionsamedi 4 novembre 2006StatutMembreDernière intervention 4 décembre 2008
-
18 déc. 2006 à 22:08
Salut à tous
j'ai une boucle for each du genre :
for each objDrive in colDrives
'creation networkDrive
next
Probleme : si colDrives est null alors il ne passe pas par la boucle
Question : comment savoir que colDrives est null ? (j'ai essayé de faire if coldrives="", <>"", =null)
Merci pour toutes réponses !
Que vient faire "WshNetwork.MapNetworkDrive" dans ton code ???
1) si tu utilises wbem et wmi, c'est pour se retrouver à la racine d'un server distant;
ex:
On Error Resume Next
Const WbemAuthenticationLevelPktPrivacy = 6
strCredentials = InputBox _
("Please enter the user name, a blank space, and then the password:", _
"Enter User Credentials","administrateur admin")
If strCredentials = "" Then
Wscript.Quit
End If
Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName
strComputer = InputBox _
("Please enter the name of the computer you want to connect to:", _
"Enter Computer Name")
If strComputer = "" Then
Wscript.Quit
End If
WScript.Echo strComputer
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
(strComputer, strNamespace, strUser, strPassword)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
' =====================================================================
' Insert your code here' Set colItems objWMIService.ExecQuery _
("Select * From Win32_OperatingSystem")
For Each objItem in ColItems
Wscript.Echo strComputer & ": " & objItem.Caption
Next
2) si tu veux seulement mapper certains disks d' un server distant, ce ne sera pas la même synthaxe.
a) tu dois repérer les DriveLetter de libre sur ton server local;
b) tu dois connaitre, par avance, les Driveletter que tu souhaites mapper sur ton server distant.
ex:
Const resultat = "D:\client_ACYR3PRO_espace_disk.txt" ' fichier .txt en output.
Const adressIP = [file://\\xxx.xxx.xxx.xx\ \\xxx.xxx.xxx.xx\] ' adresse IP du server distantC
Const user = "nom de connexion"
Const pssw = "password de connexion"Const libelle "Serveur Client - ACYR3PRO - " <?xml:namespace prefix o ns = "urn:schemas-microsoft-com:office:office" /??>
'lettre représente une des lettres (de mon poste local) que j'autorise pour le mappage
Dim lettre : lettre = Array("G","H","I","J","K","L","M","N","P","O","Q","R","S","T","V","W","X")
Dim fso, rapport, i
Set fso = CreateObject("Scripting.fileSystemObject")
Set rapport = fso.openTextFile(resultat, 2, True)
' Par rapport à mon tableau "lettre", je prends la 1ère lettre disponible sur mon server local
For i = 0 To UBound(lettre)
If Not fso.DriveExists(lettre(i)) Then
Call MapNetworkDrive(UCase(lettre(i) & ":"))
Exit For
End If
Next
Set WshShell = WScript.CreateObject("WScript.Shell")
s = s &vbCrLf& "Ce lecteur dispose de " & libre & " libres sur " &_
total & " (soit " & VerifPourcent(pourcentage) & vbCrLf
If (hd > 0) Then s = s & okomogo(hd) & " sont déjà occupés (soit " &
CStr(contrepourcentage) & " %)"
ShowFreeSpace = s
'MsgBox ShowFreeSpace,,"verif ShowFreeSpace"
End Function
Function VerifPourcent(pourcentage)
'MsgBox pourcentage,,"verif pourcentage"
If CStr(pourcentage) <= 10 Then
VerifPourcent CStr(pourcentage) & "%) ALERTE FREE SPACE inférieur ou égal à 10%> ouvrir PAC"
Else
VerifPourcent = CStr(pourcentage) & "%)"
End If
End Function
Function okomogo(brut)
kilo = 1024
mega = kilo * 1024
giga = mega * 1024
If brut > kilo Then
If brut < mega Then
fin = Round(brut / kilo, 3)
okomogo = CStr(fin) & " Ko"
Else
If brut > giga Then
fin = Round(brut / giga, 3)
okomogo = CStr(fin) & " Go"
Else
fin = Round(brut / mega, 2)
okomogo = CStr(fin) & " Mo"
End If
End If
Else
okomogo = CStr(brut) + " octets"
End If
End Function
Si depuis hier, je n'ai pas répondu à tes questions, c'est qu'il y a un "gros" malentendu !!!
Espérant que ces explications ne soient pas trop soporifiques. ça me fait bailler....
Il faut que je me force à arrêter de polluer "VBFrance" avec tous mes exemples répétitifs.
On en revient toujours à l'essentiel c-à-d. un bon énoncé dès le début du topic.
leSaleGauSS
Messages postés148Date d'inscriptionsamedi 4 novembre 2006StatutMembreDernière intervention 4 décembre 2008 15 déc. 2006 à 22:14
Oula j'ai oublié de rafraichir ...
615490 jmfmarques >> ma réponse est au dessus
=647037 mortalino >> déjà essayé ...
9517 JMO >> en fait voila une partie du script peut-être que tu comprendras ...
Set objWMIService = GetObject("winmgmts:{impersonationLevel= impersonate}!\\.\root\cimv2")
'Quelles sont les lecteurs réseaux de l'utilisateur ?Set colDrives <gras>objWMIService.ExecQuery ("Select * From Win32_LogicalDisk Where DriveType</gras> 4")
For Each objDrive in colDrives CreateNetworkDrive 'Là c'est une fonction
Next
Voila en gros mon code. Arrivé au for each il va directement vers Next
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 15 déc. 2006 à 22:23
Re,
Set objSWbemServices = GetObject("winmgmts:")
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalDisk")
Set colSWbemObjectSet = GetObject("winmgmts:").InstancesOf("Win32_LogicalDisk")
For Each objDisk In GetObject("winmgmts:").InstancesOf("Win32_LogicalDisk")
q = q & vbCrLf& objDisk.DeviceID
Next
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 15 déc. 2006 à 22:53
Re,
ou
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive",,48)
leSaleGauSS
Messages postés148Date d'inscriptionsamedi 4 novembre 2006StatutMembreDernière intervention 4 décembre 2008 16 déc. 2006 à 02:02
Set objSWbemServices = GetObject("winmgmts:")
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalDisk")
Set colSWbemObjectSet = GetObject("winmgmts:").InstancesOf("Win32_LogicalDisk")
set f=fso.opentextfile(sFile_Current)
do while not f.AtEndOfStream
TabListe = split(f.readLine, ";")
bVerif=False
For Each objGroup in objmemberOf
'appel de la fonction Groupe
sService=SubGroupe(objGroup)
select case sArgument
...
case "NetworkDrive"
If TabListe(NetworkDrive_State)="enable" then
For Each objDrive In GetObject("winmgmts:").InstancesOf("Win32_LogicalDisk")
if objDrive.DeviceID<>TabListe(sNetworkDrive_Letter) then
msgbox objDrive.DeviceID &" <> "& TabListe(NetworkDrive_Letter)
CreateNetworkDrive TabListe(NetworkDrive_Letter), TabListe(NetworkDrive_Path), TabListe(NetworkDrive_Update)
bVerif=True
exit for
end if
Next
end if
End select
next
...
If sArgument="NetworkDrive" then
For Each objDrive in colDrives
if bVerif=False then
deleteNetworkDrive TabListe(sNetworkdrive_Letter)
end if
Next
End if
loop
f.close
sub CreateNetworkDrive (sNetworkDrive_Letter , sNetworkDrive_Path, sNetworkDrive_Update)
LogFile.writeLine(now &" Création de "& sNetworkDrive_Path)'Ecriture dans fichier log
net.MapNetworkDrive sNetworkDrive_Letter , sNetworkDrive_Path, sNetworkDrive_Update
end sub
sub DeleteNetworkDrive (sNetworkDrive_Letter)
LogFile.writeLine(now & " Suppression de "&sNetworkDrive_Letter)'%%%%%
'Suppression du lecteur réseau
net.RemoveNetWorkDrive sNetworkDrive_Letter
end sub