Bonjour,
je suis débutant en VBS et je souhaite remplacer le fichier host par un fichier host type se trouvant sur un serveur
J'ai fait des commandes qui marchent a la main mais pas dans le script
Je souhaiterai soit copié le fichier a partir du VBS soit faire appel a un .bat qui s'occupera de faire la copie (la première solution étant plus pratique)
Pour l'instant j'ai :
-----------------------------------------------------
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
| On Error Resume Next
Dim f
Set f = fso.GetFile("C:\WINDOWS\system32\drivers\etc\hosts")
Set WshShell=WScript.CreateObject("WScript.Shell")
set WshShell=CreateObject("WScript.Shell")
'Première solution
If Day(f.DateLastModified) < "26/02/2009 00:00:00" Then
strExec="XCOPY \\chemin\hosts C:\WINDOWS\system32\drivers\etc\hosts /Y"
strUser="/user:domain\user"
strPass="pass~"
strCmd="runas.exe " & strUser & " cmd"
WshShell.Run strCmd
WScript.Sleep 500
WshShell.SendKeys strPass
WshShell.Run strExec
Wscript.Quit
end if
'Deuxième solution
If Day(f.DateLastModified) < "26/02/2009 00:00:00" Then
strExec="\\chemin\copy.bat"
strUser="/user:domain\user"
strPass="pass~"
strCmd="runas.exe " & strUser & " " & strExec
WshShell.Run strCmd
WScript.Sleep 500
WshShell.SendKeys strPass
Wscript.Quit
end if |
Au niveau de la 2e solution, quand je lance la commande a la main ca marche nickel :
runas.exe /user:domain\user \\chemin\copy.bat
Je pense donc que le problème réside dans le renseignement du mot de passe avec le sendkeys nan?
Merci
Partager