Script de copie réseau avec variable hostname

Résolu
bigkifran Messages postés 10 Date d'inscription vendredi 31 juillet 2009 Statut Membre Dernière intervention 30 mars 2011 - 18 mars 2011 à 10:17
bigkifran Messages postés 10 Date d'inscription vendredi 31 juillet 2009 Statut Membre Dernière intervention 30 mars 2011 - 25 mars 2011 à 14:04
Bonjour à tous.

Je débute en vbs et malgré mes recherche je bloque sur cette fonction, à savoir la copie d'un répertoire local vers un poste distant à renseigner dans une intputbox.

voici le code:

DIM objShell
hostname=InputBox("Nom de Machine / IP ")
Set objShell = CreateObject("Wscript.Shell")
DIM oFSO
set oFSO = CreateObject("Scripting.FileSystemObject")
SourceFolder = "C:\Deploy\Intel\INtel_HD_Graphics"
DestinationFolder = "& hostame & " & "\c$\drivers"
oFSO.Copyfolder "SourceFolder", "DestinationFolder", true


et là ... il me met en ligne 8, char 1: path not found ...
alors je me dis que je doit modifier la syntaxe mais même en mettant "\" en plus ... idem
auriez-vous une petite idée ?

merci de votre aide :P

Big-K

4 réponses

bigkifran Messages postés 10 Date d'inscription vendredi 31 juillet 2009 Statut Membre Dernière intervention 30 mars 2011
25 mars 2011 à 14:04
Bonjour à tous ^^

J'ai contourné le problème (notamment à cause d'un .msi)

voici le code qui fonctionne :


Dim objNetwork 
Dim objFSO 
Dim sSourcePath 'dossier source où se situe le fichier à sauvagarder
Dim sSaveName 'fichier à sauvegarder 
Dim Hostname 'ressource cible
Dim strPathDestination 'dossier destination où copier le fichier 
Dim objShell

Hostname=InputBox("Nom de Machine / IP ")
Set objShell = CreateObject("Wscript.Shell")
sSourcePath = "C:\temp\drivers"
sSaveName= "driver.msi"
strPathDestination ="\" & Hostname & "\C$\temp"

Set objFSO =CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile sSourcePath & sSaveName, strPathDestination
objShell.Run "cmd /k psexec -c -f -high \"& hostname &" c:\temp\drivers\deploy.cmd "

Set ObjFSO= Nothing



du coup le deploy cmd permet juste de lancer le msi ...

C:\emeadts\driver.msi /quiet


Maintenant je vais m'attaquer à
- la copie d'un soft à installer vers tous les pc contenus dans un fichier texte
-l'installation de ce même soft sur l'ensemble des pc du fichiers textes
-la suppression du fichier copié après l'installation ...

si quelqu'un à une idée ... ^^
3
cs_loulou69 Messages postés 672 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 2 juin 2016 1
18 mars 2011 à 16:37
Bonjour

Solution : mapper une ressource réseau (attention nom d'utilisateuur et mot de passe nécessaire, c'est pas étonnant)

Dim objNetwork
Dim objFSO
Dim strDriveLetter
Dim strRemotePath 'remote path / ressource partagée distante
Dim strUsername ' remote user / utilisateur distant
Dim strPassword 'mot de passe utilisateur distant
Dim sSourcePath 'dossier source où se situe le fichier à sauvagarder
Dim sSaveName 'fichier à sauvegarder
Dim strPathDestination 'dossier destination où copier le fichier

strUsername="user"
strPassword ="password"
sSaveName= "Fichier.ext"
strDriveLetter = "Q:"
strRemotePath = "\\nom_serveur\nom_ressource_partagée"
strPathDestination =""

Set objNetwork = CreateObject("WScript.Network")
Set objFSO =CreateObject("Scripting.FileSystemObject")

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strUsername, strPassword
WScript.Sleep 1000
objFSO.CopyFile sSourcePath & sSaveName, strDriveLetter & strPathDestination
objNetwork.RemoveNetworkDrive(strDriveLetter)
Set objNetwork = Nothing
Set ObjFSO= Nothing
0
bigkifran Messages postés 10 Date d'inscription vendredi 31 juillet 2009 Statut Membre Dernière intervention 30 mars 2011
21 mars 2011 à 14:35
Merci,

c'est carrément plus long que je ne pensais ^^
par contre je comprend mieux le cheminement du code :D
j'ai testé en ajoutant ma variable mais du coup j'ai un type mismatch sur :

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strUsername, strPassword


code entier :
Dim objNetwork 
Dim objFSO 
Dim strDriveLetter 
Dim strRemotePath 'remote path / ressource partagée distante 
Dim strUsername ' remote user / utilisateur distant 
Dim strPassword 'mot de passe utilisateur distant 
Dim sSourcePath 'dossier source où se situe le fichier à sauvagarder 
Dim sSaveName 'fichier à sauvegarder 
Dim strPathDestination 'dossier destination où copier le fichier 
DIM objShell

hostname=InputBox("Nom de Machine / IP ")
Set objShell = CreateObject("Wscript.Shell")


strUsername="DOMAIN\USER"
strPassword ="MoDePass"
sSaveName= "Intel_HD"
strDriveLetter = "L:"
strRemotePath = "\\SERVER\applis"
strPathDestination ="\"&"& hostname & "&"\c$\drivers"

Set objNetwork = CreateObject("WScript.Network") 
Set objFSO =CreateObject("Scripting.FileSystemObject") 

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strUsername, strPassword
WScript.Sleep 1000 
objFSO.CopyFolder sSourcePath & sSaveName, strDriveLetter & strPathDestination
objNetwork.RemoveNetworkDrive(strDriveLetter) 
Set objNetwork = Nothing 
Set ObjFSO= Nothing


Merci encore pour votre aide !!
0
bigkifran Messages postés 10 Date d'inscription vendredi 31 juillet 2009 Statut Membre Dernière intervention 30 mars 2011
22 mars 2011 à 16:42
Re- XD

je pense que le problème viens de la ligne :

strPathDestination ="\"&"& hostname & "&"\c$\drivers"


j'ai l'impression qui narrive pas à interpréter la ligne comme \\hostname\c$\drivers...

hostname devant être renseigner grâce à l'inputbox...

dès que j'ai un peu de temps au taf, je testerai les différentes syntaxes possible ...

Merci encore de votre aide ^^
0
Rejoignez-nous