locked
Vbscript RRS feed

  • Question

  • Hi team,

    This is my first questtion in this forum.

    I',ve give a task to write script to list user names that have filename.txt on there %Username%\Application data\Microsoft\folder from list of aomputers?

    Thursday, May 3, 2012 2:20 PM

Answers

  • I agree that batch is easier than VBScript for this kind of thing. Of course, powershell would be an even better choice, as it is less likely to choke on special characters that might exist in some file names or paths.

    Unfortunately, though, your script will not restrict where it is looking to the specific folder where the OP's vbscript puts the file in question. If a user happens to have a file of the same name on her desktop, that would make the results somewhat suspect in terms of showing which user profiles have received the file.

    I would handle a situation such as this in this manner:

       @echo off
          for /F "delims=" %%a in ('type c:\Scripts\Computers.txt') do (
             for /D %%p in (\\%%a\C$\Documents and Settings) do (
                if exist "%%p\Application Data\Sun\Java\Deployment\theFile.txt" echo/%%p
             )
          )
    


    Al Dunbar

    • Proposed as answer by Richard MuellerMVP Thursday, May 10, 2012 10:47 PM
    • Marked as answer by IamMred Saturday, May 12, 2012 12:53 AM
    Wednesday, May 9, 2012 2:42 AM

All replies

  • Hi,

    What's your question?

    Bill

    Thursday, May 3, 2012 2:21 PM
  • Hi team,

    This is my first questtion in this forum.

    I',ve give a task to write script to list user names that have filename.txt on there %Username%\Application data\Microsoft\folder from list of aomputers?

    New subject line:

    "Report on all user profiles that have a specific file"

    dir "c:\documents and settings\filename.txt" /s

    The username will be in the returned path.


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, May 3, 2012 3:45 PM
    Thursday, May 3, 2012 3:45 PM
  • I'm sorry I didn't finsh typing.

    My quetion is that:

    I use vbscript to copy files to user profiles on a list of PCs (c:\Documents and Settings\Username\Application Data\Sun\Java\Deployment), now I've been asked to produce a list of users that have that file copied on their profiles.

    So I have the list of computers and would like scripr that can find that particular file on each PC and list the location (c:\Documents and Settings\Username\Application Data\Sun\Java\Deployment\filename.txt) and save it to a log file.

    I hope what I'm trying to achieve make sence the way I put it?

    Your help is very much appreciated.

    Thanks.

    Thursday, May 3, 2012 5:12 PM
  • I'm sorry I didn't finsh typing.

    My quetion is that:

    I use vbscript to copy files to user profiles on a list of PCs (c:\Documents and Settings\Username\Application Data\Sun\Java\Deployment), now I've been asked to produce a list of users that have that file copied on their profiles.

    So I have the list of computers and would like scripr that can find that particular file on each PC and list the location (c:\Documents and Settings\Username\Application Data\Sun\Java\Deployment\filename.txt) and save it to a log file.

    I hope what I'm trying to achieve make sence the way I put it?

    Your help is very much appreciated.

    Thanks.

    The command I posted will do what you ask.  It will return all instances of the named file at any level of the tree.  Did you try it.

    Parse the result to get the user name and exact path.

    Can you please edit your topic to make it a question instead of just saying vbscipt.  That is not a very helpful topic or question. This is a public forum. One of its main purposes is to create content that others can find using a search engine.  A well asked question is helpful to others and helps fulfill the mission of the forum.

    Thank you.


    ¯\_(ツ)_/¯

    Thursday, May 3, 2012 6:04 PM
  • This is probably a case where the task is much easier to do in a batch file. The following batch file worked for me (where the file computers.txt is a list of computer names):


    @echo off
    for /F "delims=" %%a in ('type c:\Scripts\Computers.txt') do dir "\\%%a\C$\users\test.txt" /s

    -----


    This could also be done in VBScript, using WMI CIM_DataFile class, but there would be more code and it would be slow. Or, you could use the FileSystemObject and a recursive routine. Note also that I seach in "c:\users", since "c:\Documents and Settings" permissions do not allow even administrators to browse by default in new operating systems.


    Richard Mueller - MVP Directory Services

    Wednesday, May 9, 2012 12:57 AM
  • I agree that batch is easier than VBScript for this kind of thing. Of course, powershell would be an even better choice, as it is less likely to choke on special characters that might exist in some file names or paths.

    Unfortunately, though, your script will not restrict where it is looking to the specific folder where the OP's vbscript puts the file in question. If a user happens to have a file of the same name on her desktop, that would make the results somewhat suspect in terms of showing which user profiles have received the file.

    I would handle a situation such as this in this manner:

       @echo off
          for /F "delims=" %%a in ('type c:\Scripts\Computers.txt') do (
             for /D %%p in (\\%%a\C$\Documents and Settings) do (
                if exist "%%p\Application Data\Sun\Java\Deployment\theFile.txt" echo/%%p
             )
          )
    


    Al Dunbar

    • Proposed as answer by Richard MuellerMVP Thursday, May 10, 2012 10:47 PM
    • Marked as answer by IamMred Saturday, May 12, 2012 12:53 AM
    Wednesday, May 9, 2012 2:42 AM
  • Hi team,

    Thank you for the effort you putting to help me with this,  I tried both but don't seem to do the job.

    Can you help to modify the foloowing script I found that search for file on the drive using file extension, I want it to do search from folder path using "Example.txt"

    I found below script that works similar and disply the result on html file, but it does not search specific "Exampl.txt" in a specific folder path " c:adocuments and settings\%username%\Application data".

    Can one modify it for the following result please?

    1-uae list of networked Computers in text file

    2-search in a specific folder path as " c:\Documents and settings\%username%\Application data\script\". 

    2- search tor a file name as "Example.txt

    4- display the location of the file from all PCs on the list.

    =============================================================

     
    Dim fso, OutFile, sDrv, sFName, sReport, sFile, sTitle ,strHTML
    sTitle = "Recherche des Fichiers Par leurs Extensions © Hackoo"
    Set fso = CreateObject("Scripting.FileSystemObject")
    OutFile = "Recherche.html"
    If fso.FileExists(OutFile) Then fso.DeleteFile(OutFile)

    Set sReport = fso.OpenTextFile(OutFile, 8, True)
    sDrv = InputBox("Entrez la lettre du lecteur à la recherche (lettre seulement)" & vbcrlf&_
    "ou bien " & vbcrlf & "(Saisissez * pour rechercher dans toutes les lettres de lecteur local)", sTitle)
    If sDrv = "" Then WScript.Quit

    sFName = InputBox ("Entrez l'extension du fichier à rechercher exemple JPG ou bien GIF ou bien DOC ou bien XLS etc ....", sTitle)
    If sFName = "" Then WScript.Quit

    strHTML="<html><body text=white bgcolor=#1234568><style type='text/css'>"&_
    "a:link {color: #F19105;}"&_
    "a:visited {color: #F19105;}"&_
    "a:active {color: #F19105;}"&_
    "a:hover {color: #FF9900;background-color: rgb(255, 255, 255);}"&_
    "</style>"

    strHTML=strHTML &"<center><h2><B> <font color=Red>[COUNT] </font>Fichiers Trouvés dont l'extension est <font color=red>"""& sFName &""" </font> sur le lecteur <font color=red>"& UCase(sDrv) & ":</B></font></h2></center>"&_
    "<center><table border='3' cellpadding='1' style='border-collapse: collapse; font size:11pt' bordercolor='#CCCCCC' width='100%' id='Table1'></center>" & _
    "<td><center><strong>Chemin</strong></center></td>"&_
    "<td><center><strong>Date de Création</strong></center></td>"& _
    "<td><center><strong>Date de Modification</strong></center></td>"&_
    "<td><center><strong>Taille</strong></center></td>"&_
    "<td><center><strong>Attributs</strong></center></td>"

    If sDrv = "*" Then
    Dim d,dc,racine
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dc = fso.Drives
    For Each d in dc
    racine = d.Driveletter & ":"
    If d.IsReady Then
    GetResults racine , sFName
    End If
    Next
    Else
    GetResults sDrv & ":", sFName
    End If
    sReport.WriteLine strHTML &"</table></body></html>"
    Wscript.CreateObject("WScript.Shell").Run OutFile

    Sub GetResults(drv, fname)
    On Error Resume Next
    Dim sWQL, oFile, sAttrib,sFilePath,size
    ext = Array("png","jpg","jpeg","gif","bmp","psd","tif")
    sWQL = "select * from cim_datafile where Drive='" & _
    drv & "' AND Extension = '" & fname & "'"
    Results = 0
    For Each oFile In GetObject("winmgmts:").execquery(sWQL)
    Results = Results + 1
    sFile = oFile.Name
    Set f = fso.GetFile(sFile)

    SizeKo = Round(FormatNumber(f.Size)/(1024),0) & " Ko" 'Taille en Ko
    SizeMo = Round(FormatNumber(f.Size)/(1048576),0) & " Mo" 'Taille en Mo
    SizeGo = Round(FormatNumber(f.Size)/(1073741824),0) & " Go" 'Taille en Go

    If f.size < 1024 Then
    Size = f.size & " Octets"
    elseif f.size < 1048576 Then
    Size = SizeKo
    elseif f.size < 1073741824 Then
    Size = SizeMo
    else
    Size = SizeGo
    end if
    sFilePath = f.Path
    If oFile.Archive Then sAttrib = "Archive "
    If oFile.Compressed Then sAttrib = sAttrib & " Compressé "
    If oFile.Encrypted Then sAttrib = sAttrib & " Crypté "
    If oFile.Hidden Then sAttrib = sAttrib & " Caché "
    If oFile.System Then sAttrib = sAttrib & " Système "
    If oFile.Readable Then sAttrib = sAttrib & " Lecture "
    If oFile.Writeable Then sAttrib = sAttrib & " Ecriture "

    If UCase(ext(0)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(1)) = UCase(fso.GetExtensionName(oFile.Name))or UCase(ext(2)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(3)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(4)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(5)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(6)) = UCase(fso.GetExtensionName(oFile.Name)) Then

    ImgFileName = oFile.Name
    strHTML=strHTML & "<tr><td><center><a target=_Blank href='"& sFilePath &"'>"&ImgFileName&"<br><img src='"& sFilePath &"' border=1 height=50 width=80></center></td><td><center>" & f.DateCreated & "</center></td>" & _
    "<td><center>" & f.DateLastModified & "</center></td><td><center>"& Size & "</center></td>"&_
    "<td><center>" & sAttrib & "</center></td></tr>"
    else
    strHTML=strHTML & "<tr><td><a target=_Blank href='" & sFilePath & "'>" & _
    sFilePath & "</a></td><td><center>" & f.DateCreated & "</center></td>" & _
    "<td><center>" & f.DateLastModified & "</center></td><td><center>"& Size & "</center></td>"&_
    "<td><center>" & sAttrib & "</center></td></tr>"
    end if
    Next
    strHTML = Replace(strHTML, "[COUNT]", Results)
    End Sub

    ================================================================================

      

    Wednesday, May 9, 2012 1:19 PM
  • Feel free to modify this in any way you like.  This is your responsibility.  We have given you methods that are know to work.  You have not correctly implemented the suggestions and say no more that they don't work.  This is not very helpful.  You must say how they don't work.

    The code you posted may appear to do what you want.  You are free to try to use it.  We cannot rewrite it for you.


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, May 9, 2012 8:07 PM
    Wednesday, May 9, 2012 1:43 PM
  • Hi team,

    Thank you for the effort you putting to help me with this,  I tried both but don't seem to do the job.

    <snip>  


    You do realize, do you  not, that the script examples that Richard and I provided are not in vbscript, but in batch? along the lines of JR's comment below, these are provided as prototypes that in all probablility need to be adapted to run properly in your environment.

    Al Dunbar

    Wednesday, May 9, 2012 7:14 PM