473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Logging computer names with incorrect file sizes

Hello all,

My first post as a SysAdmin (I am more used to C* programming).

What I am trying to do is create a script that will scan PCs on my network and check for a file and verify that it's size is correct.

If the file size is != 1,101,824bytes in size, the name of that PC should be logged - that's it.

I am just not too used to VBScripting and am not very aware of functions, how to call them, and etc.

This is what I have been trying to throw together for the last 20 minutes or so - kind of pressed for time...

Expand|Select|Wrap|Line Numbers
  1. '---------LogToFile Configuration---------
  2. 'NOTE: Copy the configuration section To
  3. 'the beginning of an existing script. The
  4. 'values specified here must be set before
  5. 'calling the LogToFile sub.
  6.  
  7. 'You can disable logging globally by
  8. 'setting the bEnableLogging option to false.
  9. bEnableLogging = True
  10.  
  11. 'Setting this to true will time stamp Each
  12. 'message that is logged to the log file
  13. 'with the current date and time.
  14. bIncludeDateStamp = True
  15.  
  16. 'Specify the log file location here. Path
  17. 'must contain a trailing backslash. If you
  18. 'would like to log to the same location as
  19. 'the currently running script, set this
  20. 'value to "relative" or uncomment out the
  21. 'line below.
  22. sLogFileLocation = "C:\temp\log\"
  23. sLogFileLocation = "relative"
  24.  
  25. 'Specify the log file name here.
  26. sLogFileName = "noble4jslog.txt"
  27.  
  28. 'You can set whether or not you would like
  29. 'the script to append to an existing file,
  30. 'or if you would like it to overwrite
  31. 'existing copies. To overwrite set the
  32. 'sOverWriteORAppend variable to "overwrite"
  33. sOverWriteORAppend = "append"
  34.  
  35. path = "C:\Program Files\Windows Media Connect 2\WMCCFG.exe"
  36.  
  37. '-------END LogToFile Configuration-------
  38.  
  39. Sub LogToFile(Message)
  40.     'LogToFile.vbs 10-18-07
  41.  
  42.     If bEnableLogging = False Then Exit Sub
  43.  
  44.     Const ForReading = 1
  45.     Const ForWriting = 2
  46.     Const ForAppending = 8
  47.  
  48.     Set oLogFSO = CreateObject("Scripting.FileSystemObject")
  49.  
  50.     If sLogFileLocation = "relative" Then
  51.         Set oLogShell = CreateObject("Wscript.Shell")
  52.         sLogFileLocation = oLogShell.CurrentDirectory & "\"
  53.         Set oLogShell = Nothing
  54.     End If
  55.  
  56.     sLogFile = sLogFileLocation & sLogFileName
  57.  
  58.     If sOverWriteORAppend = "overwrite" Then
  59.         Set oLogFile = oLogFSO.OpenTextFile(sLogFile, ForWriting, True)
  60.         sOverWriteORAppend = "append"
  61.     Else
  62.         Set oLogFile = oLogFSO.OpenTextFile(sLogFile, ForAppending, True)
  63.     End If
  64.  
  65.     If bIncludeDateStamp Then
  66.         Message = Now & "   " & Message
  67.     End If
  68.  
  69.     oLogFile.WriteLine(Message)
  70.     oLogFile.Close
  71.  
  72.     oLogFSO = Null
  73. End Sub
  74.  
  75. Private Function FileLen(byVal path)
  76.     Dim objFSO, objFile
  77.     On Error Resume Next
  78.     Set objFSO    = Server.CreateObject("Scripting.FileSystemObject")
  79.     Set objFile    = objFSO.GetFile(path)
  80.     If Err Then
  81.         FileLen = Null
  82.     Else
  83.         FileLen = CLng( objFile.Size )
  84.     End If
  85.     Set objFile    = Nothing
  86.     Set objFSO    = Nothing
  87.     On Error GoTo 0
  88. End Function
  89.  
Thank you all in advance! This should help me with learning how to work with scripts a bit better. I will keep posting any new information I find out or that I think may help with this problem.

Any help you can give as soon as you can will be greatly appreciated.
Nov 19 '07 #1
3 1454
Okay,

After going through my code and making some changes, I have come up with the following:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim Shell, FSO, path, fFile, fSize, LocalComputer
  3. Set Shell = WScript.CreateObject("WScript.Shell")
  4. Set FSO = CreateObject("Scripting.FileSystemObject")
  5. path = "c:\temp\vinpa.dat"
  6.  
  7. If FSO.FileExists(path) Then
  8.         Set fFile = FSO.GetFile(path)
  9.         fSize = fFile.Size            
  10.         If fSize = 1101824 Then
  11.             WScript.Quit
  12.         Else
  13.                Localcomputer = UCase(Shell.ExpandEnvironmentStrings("%COMPUTERNAME%"))
  14.            End If
  15. End If
  16.  
Now I believe the only thing left for me to do is to somehow get the:

Expand|Select|Wrap|Line Numbers
  1.  Localcomputer = UCase(Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")) 
to append to a text file.

Any ideas?
Nov 19 '07 #2
Expand|Select|Wrap|Line Numbers
  1. Dim fFile, fSize
  2.  
  3. Name = "FourJs"
  4. Path = <path>
  5. OutputFileName = "E:\batfile\"& Name & "\desks.txt"
  6.  
  7. If Fso.FileExists(Path) Then
  8.         Set fFile = Fso.GetFile(Path)
  9.         fSize = fFile.Size
  10.         If Not fSize = 1101824 Then
  11.             Set File = Fso.openTextFile(OutputFileName, ForAppending, True)
  12.             File.WriteLine Computer_Name
  13.             File.Close
  14.            End If
  15. End If
  16.  
  17. Name = ""
  18. Path = ""
  19. OutputFileName = ""
  20.  
That's all folks! It's my main function/method - everything is declared at the top of my file.

Thanks for nothin'... :)
Nov 19 '07 #3
bartonc
6,596 Expert 4TB
Thanks for nothin'... :)
As you say, this is a Sys Admin forum. Not many used to VBScripting around here.

Thanks for posting your solution, though.
Nov 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tero Saarni | last post by:
I'm using Logging in my library module for producing trace log of certain events. For being more useful these log entries should be associated with the filename and line number of *users* code...
12
by: Rob Cranfill | last post by:
Hello, I've successfully coded Python to do what I want with a RotatingFileHandler, but am having trouble getting the same behavior via a config file. I wanted to create one log file each...
3
by: Chris Smith | last post by:
Hola, pythonisas: The documentation for the logging module is good, but a bit obscure. In particular, there seems to be a lot of action at a distance. The fact that getLogger() can actually be a...
1
by: bneron | last post by:
hello, I use the logging module include in Python 2.4 distribution, and I 'd like to have a logger witth several Handlers . I know how to do this by coding in python, but could I specify this...
0
by: robert | last post by:
As more and more python packages are starting to use the bloomy (Java-ish) 'logging' module in a mood of responsibility and as I am not overly happy with the current "thickener" style of usage, I...
1
by: nicholas.farrell | last post by:
Hi everyone. I've just been trying to add a bit more granularity to my logging code, as the jump from INFO (level 20) to DEBUG (level 10) is a bit too big. I was thinking of borrowing a few...
2
by: Robert | last post by:
Hi all I have been trying to set up a framework with logging implemented using the built in Python logging module. For better or worse, I have decided to base the logger names on the module...
12
by: Eric S. Johansson | last post by:
I need to to be able to conditionally log based on the method the log statement is in and one other factor like a log level. in order to do so, I need to be able to automatically find out the name...
4
by: samwyse | last post by:
In the Python 2.5 Library Reference, section 14.5.3 (Logging to multiple destinations), an example is given of logging to both a file and the console. This is done by using logging.basicConfig()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.