Bon je tente d'expliquer mon probleme, si je suis pas clair n'hesiter a me le laisser savoir
La ligne qui me donne du trouble
wsh.Run "%comspec% /c ipconfig >" & TempFil, 1, True
Si j'ouvre mon fichier C:\myip2.txt il est vide, cependant si j'effectue cette meme command manuellement avec "RUN"
%comspec% /c ipconfig > C:\MY1.TXT
tout est correct. Donc, si vous meme vous executer cette commande vous obtiendrez votre adresse IP dans le fichier C:\MY1.TXT
Merci au gourou
La ligne qui me donne du trouble
wsh.Run "%comspec% /c ipconfig >" & TempFil, 1, True
Si j'ouvre mon fichier C:\myip2.txt il est vide, cependant si j'effectue cette meme command manuellement avec "RUN"
%comspec% /c ipconfig > C:\MY1.TXT
tout est correct. Donc, si vous meme vous executer cette commande vous obtiendrez votre adresse IP dans le fichier C:\MY1.TXT
Merci au gourou
Code:
Function IPReturn(outputtype As Integer)
Dim wsh As Object
Dim RegEx As Object, RegM As Object
Dim FSO As Object, fil As Object
Dim ts As Object, txtAll As String, TempFil As String
Dim target As String
Set wsh = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set RegEx = CreateObject("vbscript.regexp")
TempFil = "C:\myip2.txt"
' Save ipconfig info to temporary file
wsh.Run "%comspec% /c ipconfig >" & TempFil, 1, True
'this can be run manually %comspec% /c ipconfig > C:\MY1.TXT
Set fil = FSO.GetFile(TempFil)
' Access temporary file
Set ts = fil.OpenAsTextStream(ForReading)
If outputtype = 1 Then target = "IP Address"
If outputtype = 2 Then target = "Subnet Mask"
If outputtype = 3 Then target = "Default Gateway"
txtAll = Trim(ts.ReadLine)
Do Until Left(txtAll, Len(target)) = target Or ts.atendofstream
txtAll = Trim(ts.ReadLine)
Loop
If ts.atendofstream = True And Left(txtAll, Len(target)) <> target Then ts.Close: Exit Function
ts.Close
With RegEx
.Pattern = "(\d{1,3}\.){3}\d{1,3}"
.Global = False
End With
Set RegM = RegEx.Execute(txtAll)
IPReturn = RegM(0)
Kill TempFil
Set ts = Nothing
Set wsh = Nothing
Set fil = Nothing
Set FSO = Nothing
Set RegM = Nothing
Set RegEx = Nothing
End Function