The VBScript Network and Systems Administrator's Cafe


May 2, 2009  6:19 PM

Using the VBScript datediff function to determine the age of a file by the last modified and the last accessed time

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently needed a way to tell if a file had been accessed or modified recently, something that has always been a question when you’re out of space on a server and can’t just add more space to it. What do you delete??? The Old files are the obvious answer… except if people are using them.

Here is teh script I wrote to tell if a file had been accessed or modified in the last X days. In the example I use 5 days, but you can use a different number of days when you call the function.

Enjoy!

Option Explicit

Dim fName
Const DateLastModified = 1, DateLastAccessed = 2

fName=”c:\temp2.txt”

if FileAge(fname,5,DateLastAccessed) = True Then
WScript.Echo (“The file was accessed recently enough!”)
Else
WScript.Echo (“The file was not accessed recently enough!”)
End If

if FileAge(fname,5,DateLastModified) = True Then
WScript.Echo (“The file was modified recently!”)
Else
WScript.Echo (“The file was not modified recently!”)
End If

Function FileAge(fName,fAge, CompareType)
‘function returns True if the file is older than the fAge (File Age) specified and false if it isn’t
Dim LastModified, LastAccessed, FSO, DateDifference

Set FSO = CreateObject(“Scripting.FileSystemObject”)
LastModified = FSO.GetFile(fname).DateLastModified
LastAccessed = FSO.GetFile(fname).DateLastAccessed

Select Case CompareType
Case 1
DateDifference = DateDiff(“n”,LastModified, Now())
Case 2
DateDifference = DateDiff(“n”,LastAccessed, Now())

End Select
If DateDifference > fage Then
FileAge = False
Else
FileAge = True
End If
End Function

May 1, 2009  1:11 PM

OneNote Tip: Take better notes during meetings the easy way!

Jerry Lees Jerry Lees Profile: Jerry Lees

Microsoft has a product called one note that i really didn’t know a lot about. They really haven’t pushed it a lot and it just comes bundled with Office so I’d never really tried to use it, however, I found an article over at Microsoft’s site that gives an excellent set of tips for how to use it to take better notes in meetings.

If you’re like me, you scribble notes (and doodle) on a notepad, open up word on your PDA, or if in a conference call full blown word on your laptop. You take notes as the meeting progresses and then later look back at your notes and wonder… “what was that I wrote about? That note doesn’t make any sense.”

Well Microsoft has a couple good tips at the one note site to make your life easier taking notes.

Check them out!


April 23, 2009  11:28 PM

How to Make Your Computer Boot Faster

Jerry Lees Jerry Lees Profile: Jerry Lees
VBA

I read an interesting article recently that gave some excellent tips at making your computer run faster– without an upgrade! I thought I’d pass some of these tips along and add a few of my own.

First, You can make your computer run faster (and free up space by uninstalling software that you no longer use. You can easily do this with an excellent piece of software called, PC Decrapifier.

The other thing you can do is ensure that you remove applications from your startup that you do not absolutely need. In Vista, you can manage startup applications through Windows Defender. Defender has an integrated tool called Software Explorer that lets you check programs that load at startup and disable anything unnecessary.

You can also access the list of startup applications in either Vista or XP through the Msconfig utility (type “msconfig” into the Run box in the Start menu). Select the Startup tab, then uncheck any applications you think might be slowing your startup.

Consult an online database of startup processes, such as Sysinfo, to find out what the process may be– keeping in mind that it may not be 100% accurate.

If you’re serious about shaving every last second of startup time, dig into the Boot tab in the Msconfig utility, which controls the settings for the boot.ini file. Generally, users should tread carefully when tinkering with boot.ini, because one slip up and you can have a non-bootable computer. But one easy edit is to check the “/noguiboot” option to time by skipping the Windows startup animation.

Another useful tip is to clean up the registry. There are various applications out there, Free programs such as CCleaner and Glary Utilities, as well as more fully featured software such as System Mechanic (System Mechanic just simply can’t be beat in my opinion, the others are free but sometimes don’t do as complete a job) are available for download online and will scrub the registry for “keys” left over from old applications no longer resident on your machine.

Doing some or all of these will no doubt result in some extra free space on your computer as well as some extra free time– who knows, you may not even have time to get that first cup of coffee in before your computer is totally logged in. ;-)

Enjoy!


April 20, 2009  1:44 PM

Parsing the Windows Event log for specific data

Jerry Lees Jerry Lees Profile: Jerry Lees

If you’ve ever tried to find a specific event log entry in a system you know what a chore it can be to find them. Sure, you can filter on the event ID and get closer but, some applications (and system components) log every event that’s from the same source as the same event ID.

IIS is terribly bad about this! Additionally, Microsoft’s search filtering isn’t powerful enough to search in the even description or the event message. The script below solves that problem!

GetLogInfo “ServerName”,”EventID”, “application”, “20081218”

Function GetLogInfo( StrComputer1, EventID, EventLogType, YYYYMMDD)

 Dim objWMIService, colItems, objItem
 Dim TempStr

 On Error Resume Next
  ‘ error control block
  Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}//” & strComputer1 & “\root\cimv2″)
  Set colItems = objWMIService.ExecQuery (“Select * from Win32_NTLogEvent Where EventCode=” & EventID & ” and logfile='” & EventlogType & “‘”)
  For Each objItem in colItems
       TempStr = “”
       If mid(objItem.timegenerated,1,8) = YYYYMMDD Then
         TempStr = objItem.message         
         If Replace(TempStr,”Exception message: Request timed out.”,””) <> TempStr Then 
            TempStr = Mid(TempStr,InStr(1,TempStr,”Request URL: “)+13, 100)
            TempStr = Mid(TempStr,1,InStr(1,TempStr,”.aspx”)+4)
            WScript.Echo StrComputer1 & “,” & TempStr
         End if
       End if
  Next
 On Error GoTo 0
End Function


April 16, 2009  1:23 AM

Downgrade Windows XP to Mac OS X– sort of

Jerry Lees Jerry Lees Profile: Jerry Lees

Please forgive the title folks, I just couldn’t resist the jab to get your attention!

I found this Windows UI Replacement a while back, looks like a pretty cool interface replacement for windows. It looks like it is actually a pretty cool prank… or a way to use a PC if you prefer the Mac.

Simply download the software from the link below and you will have A Windows User Interface repacement that pretty closely mimics that of the Macintosh!


April 13, 2009  3:18 PM

Finding the owner of a process remotely with VBScript via the Win32_process class

Jerry Lees Jerry Lees Profile: Jerry Lees

 Recently I had an issue where I needed to find the user running a series of processes on a large number of servers. Initially, it was a long process of logging onto each server then opening task manager and sorting by process name. After about 5 servers, I realized it was going to take hours to sort out the users running the processes… so I spent 30 minutes not preforming this process and wrote a script to do the rest of the work in less than a minute!

The function below uses the Win32_Process WMI class to enumerate processes running on a server that are named the same as the process name you give it. It then outputs the name of the user running the process.

Below is the function… Enjoy!

 Function FindProcessOwner( StrComputer1, ProcessName)

Dim objWMIService, colItems, objItem, Username, Domain

On Error Resume Next
‘ error control block
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}//” & strComputer1 & “\root\cimv2″)
If Err.Number <> 0 Then
WScript.Echo “An Error Occured (” & StrComputer1 & “): ” & Err.Description
End If
Set colItems = objWMIService.ExecQuery (“Select * from Win32_Process Where Name = ‘” & ProcessName & “‘”)
WScript.Echo “Searching for processes on ” & StrComputer1 & “.”
WScript.Echo colItems.count & ” processes found.”
For Each objItem in colItems
objItem.getowner Username, Domain
FindProcessOwner = FindProcessOwner & VbCrLf & strComputer1 & “: ” & objItem.name &_
“(PID: ” & objItem.processid & “) the owner is: ” & Domain & “\” & Username
Next
On Error GoTo 0
End Function


April 9, 2009  4:23 PM

Writing a BGINFO like Script: Displaying IP Address settings with WMI via the Win32_NetworkAdapterConfiguration class

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently had to provide the information displayed with BGINFO on a number of systems. Unfortunately, BGInfo only generates a bitmap, so far as I know, so I decided to write a script to generate the information and use this displayed information to send back to the person who requested it.

The function below is a part of the script I mentioned. It retrieves and returns text that represents the IP address settings for the network cards installed in a system.

You can view all the scripts in this BGINFO series here.

Here is the code:

Function GetIPAddresses(strComputer)
Dim colItems, objItem, address
Dim StrQuery
Dim objWMIService
Dim IP

StrQuery = “SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2″)
Set colItems = objWMIService.ExecQuery(strQuery,,48)

For Each objItem in colItems
For Each address In objItem.ipaddress
IP = replace(address,”:”,””)
‘IP = Replace(IP,vbnull,”No IP Assigned”)
GetIPAddresses = GetIPAddresses & vbTab & mid(objItem.caption,InStr(objItem.caption,”]”)+2) & “: ” & IP & vbcrLF
Next
Next
End Function


April 7, 2009  4:23 PM

Writing a BGINFO like Script: Displaying Operating System Information with WMI via the Win32_OperatingSystem class

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently had to provide the information displayed with BGINFO on a number of systems. Unfortunately, BGInfo only generates a bitmap, so far as I know, so I decided to write a script to generate the information and use this displayed information to send back to the person who requested it.

The function below is a part of the script I mentioned. It retrieves and returns text that represents the operating system and service pack information installed on a system.

You can view all the scripts in this BGINFO series here.

Here is the code:

Function GetOSVersion(strComputer)
Dim colItems, objItem, address
Dim StrQuery
Dim objWMIService
GetOSVersion = VbCrLfStrQuery = “SELECT * FROM Win32_OperatingSystem”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2″)
Set colItems = objWMIService.ExecQuery(strQuery,,48)

 

For Each objItem in colItems
GetOSVersion = GetOSVersion & vbTab & replace(objItem.caption,”(R)”,””) & VbCrLf
GetOSVersion = GetOSVersion & vbTab & “Service Pack ” & objitem.ServicePackMajorVersion & VbCrLf
Next
End Function


April 2, 2009  1:23 PM

Writing a BGINFO like Script: Displaying Page File information with WMI via the Win32_Pagefile class

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently had to provide the information displayed with BGINFO on a number of systems. Unfortunately, BGInfo only generates a bitmap, so far as I know, so I decided to write a script to generate the information and use this displayed information to send back to the person who requested it.

The function below is a part of the script I mentioned. It retrieves and returns text that represents the total page file space allocated in a system.

You can view all the scripts in this BGINFO series here.

Here is the code:

Function GetPageFile(strComputer)
Dim colItems, objItem, address
Dim StrQuery
Dim objWMIService
GetPageFile = VbCrLfStrQuery = “SELECT * FROM Win32_PageFile”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2″)
Set colItems = objWMIService.ExecQuery(strQuery,,48)

 

For Each objItem in colItems
GetPageFile = GetPageFile & vbTab & ((objItem.filesize/1024)/1024) & ” Mb” & vbcrlf
Next
End Function


April 1, 2009  7:20 AM

Microsoft takes an unprecedented new approach to lagging Vista Sales; bundles with Xbox 360

Jerry Lees Jerry Lees Profile: Jerry Lees

I read this article posted on Monday March 29th, 2009 over at a Xbox 360 gamer website I browse often basically said:

Due to lagging sales of Microsoft Vista Microsoft has begun bundling Vista Basic (not HOME BASIC!) with every new Xbox 360, along with a online coupon to upgrade it to Vista Ultimate for $99.00 online at thier site.

Microsoft spokesman Josh Nya said, “This is an unprecidented opportunity for those who have been waiting to upgrade to Vista to do so at a bargain because we’ve bundled it with the Xbox 360. And for those who have purchased a Xbox 360 or Vista in the last 6 months we’re offering the same bundle deal with proof of purchase by calling 1-800-MICROSOFT.”

Yes!!! So if you’ve bought Vista— or a 360 in the last 6 months— run on over and read the details on this promotion because they are bound to have a backlog once word gets out.

And Once you get confirmed be sure and let us all know here at the IT Knowledge Exchange!!!!


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: