Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

vb insert space

Avatar of B0b_shiska
B0b_shiska asked on
ProgrammingVB Script
18 Comments1 Solution428 ViewsLast Modified:
Hello. I have a script that reads of a config file and retrieves file properties (file size,version&timestamp) and send the output to a txt file. How can i modify the script to include the following:
1. Currently timestamp and date are set to the current (when the script runs). Want it set to the last time the file being retrieved was modified.
2. include a space between each server output . For example, several servers are getting properties for adobe, others for java. Would like a space after the adobe output and before java.

Example output:
2/01/2009 2:02:19 PM: 10.x.x.1 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes
2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes                                                                                            
  (1 line space here)
2/01/2009 2:02:19 PM: 10.x.x.3 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes
2/01/2009 2:02:19 PM: 10.x.x.4 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes

3. Include a number count for each result.
Example:
1. 2/01/2009 2:02:19 PM: 10.x.x.4 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes
2. 2/01/2009 2:02:19 PM: 10.x.x.5 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes

4. Move the size output line (example below) to the same line. Currently, the file size in the output is showing up on the next line
 
Example:
2/01/2009 2:02:19 PM: 10.x.x.1 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes
2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes                                                                  
     (should be)
1. 2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1 2660352 Bytes
2. 2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1 2660352 Bytes

script:

Dim strServer
Dim strUsername
Dim strPassword
Dim StrFilename
Dim fConfig
dim objNetwork

Const ForReading = 1

Set objNetwork = CreateObject("WScript.Network")

strOutputFile = "C:\outputfile.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

set fConfig = objFSO.OpenTextFile("config.txt",ForReading, False)

Set objOutputFile = objFSO.CreateTextFile( strOutputFile, True, True )

do until fconfig.atendofstream
      strLine = fconfig.readline
      If UCase(Left(strLine, 6)) = "SERVER" Then strServer = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "USERNAME" Then strUsername = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "PASSWORD" Then strPassword = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "FILENAME" Then strFileName = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If strServer <> "" And strUsername <> "" And strPassword <> "" And strFileName <> "" Then
            If Ping(strServer) = True Then
                  processfile strServer, strUsername, strPassword, "z:\" & StrFilename
            Else
                  objOutputFile.WriteLine strServer & " is offline."
            End If
            strServer = ""
            strUsername = ""
            strPassword = ""
            strFileName = ""
      End If
Loop

objOutputFile.Close
MsgBox "finished."

Function ProcessFile(strSvr, strUser, strPass, strFilePath)
      Dim strMsg, strVersion, timestamp
      On Error Resume Next
      objnetwork.removenetworkdrive "z:", True, True
      Err.Clear
    objnetwork.mapnetworkdrive "z:", "\\" & strSvr & "\C$", False, strUser, strPass
    If Err.Number <> 0 Then
          MsgBox "Error mapping to " & strSvr & ". Please check you can map to the server." & VbCrLf & "Error " & Err.Number & ": " & Err.Description
          Err.Clear
    Else
          On Error GoTo 0
            ' Make sure the file exists
            If objFSO.FileExists( strFilePath ) = False Then
                  strMsg = strFile & " - File not found. "
            Else
                  ' Get the Version of the File and put it in a Message String
                  strVersion = objFSO.GetFileVersion(strFilePath)
                  strMsg = strSvr & " " & strFilePath & " " & strVersion
                  strtimestamp = time()
            End If
      
            ' Write the Message string to the Output File (with a CR LF)
            objOutputFile.Write Now & ": " & strMsg & VbCrLf
            Set ffile = objfso.getfile(strFilePath)
            objoutputfile.writeline ffile.size & " Bytes"
            
      End If
      objnetwork.removenetworkdrive "z:", True, True
      Err.Clear
      On Error GoTo 0
End Function

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function

Thanks in advance.