[vbs] message d'erreur Type incompatible: 'GetFileName' sur objFSO.GetFileName(o

GeorgesOrwell - 15 mars 2013 à 00:06
 GeorgesOrwell - 15 mars 2013 à 02:19
Bonsoir,

Je tente de faire un script avec des morceaux de codes pris sur le net et j'obtiens une erreur à la ligne suivante.

WScript.Echo userPath & "" & objFSO.GetFileName(objTextFile) & NetPath & strComputer & "_" & userUpn & "_" & Now() & "_pst.log"


Le message d'erreur est : Erreur d'exécution Microsoft VBScript (34, 1) : Type incompatible: 'GetFileName'

Voici mon code:

[list]
'Option Explicit
On Error Resume Next

Dim objShell,objFSO,objTextFile,objOutlook,objMAPI,WshNetwork,Varnow,Current,Vardate
Dim PSTfolder,userPath,pstPath,strSubString,UserUpn,strComputer,NetPath


Const OverwriteExisting = True
Varnow = now
Current = TimeHHMMSS()
Vardate = Day(varnow) & "-" & Month(varnow) & "-" & Year(varnow) & "_at_" & Current
Set objShell = CreateObject("wscript.shell") 
Set WshNetwork = WScript.CreateObject("WScript.Network") 
UserPath = objShell.ExpandEnvironmentStrings("%userprofile%") 
UserUpn = WshNetwork.UserName
strComputer = WshNetwork.ComputerName 
NetPath = "\\sa000e\LogsArch$"  
Set objFSO = CreateObject("scripting.filesystemobject")
Set objTextFile = objFSO.CreateTextFile _ 
    (userPath & "" & Vardate & "_pst.log") 
    														
    
Set objOutlook = createObject("Outlook.Application")
set objMAPI = objOutlook.GetNamespace("MAPI")			
for each PSTFolder In objMAPI.Folders					
  pstPath = GetPath(PSTFolder.StoreID)
  if pstPath <> "" Then 
objTextFile.WriteLine(PSTFolder.name & " : " & pstPath) 
  end if
Next

On Error goto 0

WScript.Echo userPath & "" & objFSO.GetFileName(objTextFile) & NetPath & strComputer & "_" & userUpn & "_" & Now() & "_pst.log"


function GetPath(input)										
  for i = 1 To Len(input) Step 2
    strSubString = Mid(input,i,2)
    if Not strSubString = "00" Then
       strPath = strPath & ChrW("&H" & strSubString)
    end If
  next

  select Case True
  case InStr(strPath,":") > 0
    GetPath = Mid(strPath,InStr(strPath,":")-1)
  case InStr(strPath,"\") > 0
    GetPath = Mid(strPath,InStr(strPath,"\"))
  end Select
end Function


Function TimeHHMMSS()
    Dim retv, d
    d = Now
    retv = Right("00" & Hour(d), 2) & "-" & Right("00" & Minute(d), 2) & "-" & Right("00" & Second(d), 2)
    TimeHHMMSS = retv
End Function
/list



Voilà cherche gourou du vbscript désespérément.

Je ne peux pas le faire en powershell car certains des postes sont en 2000 et XP.

Merci par avance de votre aide.


Goerges Orwell

2 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
15 mars 2013 à 01:23
Salut

Catégorie de la question modifiée.

objFSO.GetFileName(objTextFile)
Sous-entend que objTextFile soit une chaine de caractères.
Ici, c'est un objet.
Peut-être que ceci suffirait (à vérifier)
objFSO.GetFileName(objTextFile.FileName)
mais pas sûr que ça existe.
Ou sinon :
objFSO.GetFileName(userPath & "" & Vardate & "_pst.log")

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on le partage (Socrate)
0
GeorgesOrwell
15 mars 2013 à 02:19
Bonsoir Jack,
Merci pour ta réponse.
finalement j'avais la réponse plus haut dans mon code au niveau du CreateTextFile.

Wscript.Echo userPath & "" & Vardate & "_pst.log" & NetPath & strComputer & "_" & userUpn & "_" & Vardate & "_pst.log"


Merci pour la piste


Georges Orwell
0
Rejoignez-nous