Microsoft Windows archives - The VBScript Network and Systems Administrator's Cafe

The VBScript Network and Systems Administrator's Cafe:

Microsoft Windows

May 26 2009   2:49PM GMT

How to Add the Ability to Administer an IIS 6 Server From a XP Machine.



Posted by: Jerry Lees
IIS6, System Administration, iis, iis 6, web tools, webmaster, Microsoft Windows

In re-doing my laptop after a hard drive failure recently I’ve had to setup a bunch of stuff I had previously installed, one thing that several people have asked about (or didn’t know about) is the IIS6 MMC snap in. It allows you to Administer IIS6 from your desktop. It will give you the Internet Information Services (IIS6) Manager icon in Administrative tools and allow you to create custom MMC snap-ins for the web servers. It’s a huge time saver and allows you to do everything in IIS from your local machine (except administer SSL keys, so far as I can recall) that you can do while logged into the server—without logging onto the server!

First you’ll need IIS installed on your machine, via add/remove windows components in the add/remove programs control panel applet. After that run IIS 6 Mgr setup.exe from Microsoft’s Site here.

Apr 20 2009   1:44PM GMT

Parsing the Windows Event log for specific data



Posted by: Jerry Lees
Eventlogs, Win32_NTLogEvent, System Administration, systems management, VBScript

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


Apr 16 2009   1:23AM GMT

Downgrade Windows XP to Mac OS X– sort of



Posted by: Jerry Lees
pranks, interface replacements, windows, Microsoft Windows

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!


Apr 13 2009   3:18PM GMT

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



Posted by: Jerry Lees
WMI, Windows Management Interface, win32_process, System Administration, Systems Administration, Administration tools, VBScript, VBScript Functions, Functions

 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


Feb 26 2009   8:00AM GMT

Retrieving the account IIS is using as the anonymous user account with VBScript



Posted by: Jerry Lees
iis, System Administration, Systems Administration, systems management, VBScript Functions, VBScript, web sites, web tools, working with objects

I recently posted a script that retrieved the anonymous user password for a server in IIS. This script I posted, Using the IIS ADSI object to retrieve the anonymous user password for a server via VBScript, came in quite handy in a pinch, but not knowing the anonymous user account the password goes with can also be a pain.Luckily I had that piece of information in the script as well!

So, I’ve wrapped that part of the script into a function for your use as well. Below is a snippet from the script to display the user account.

Function Get_IUSR_Username(ServerName)
Dim IIsObject

Set IIsObject = GetObject (”IIS://” & ServerName & “/w3svc”)
on Error resume Next
Get_IUSR_Username = IIsObject.Get(”AnonymousUserName”)
On Error GoTo 0
End Function

Enjoy!


Feb 20 2009   3:53PM GMT

Using the IIS ADSI object to retrieve the anonymous user password for a server via VBScript



Posted by: Jerry Lees
iis, System Administration, Systems Administration, Toolkit, VBScipt, VBScript Functions, VBScript, working with objects

I recently had to change the anonymous user account for a change request for a site in IIS, but unfortunately the change did not work and we had to roll it back. However, I didn’t have and wouldn’t have known the account’s password since IIS and windows changes it periodically.

So, out came the scripting tool belt and I found that I had a script written previously that let me get the anonymous user account and password through the IIS ADSI object.

Below is a snippet from the script to display the password.

Function Get_IUSR_Password(ServerName)
   Dim IIsObject
   
   Set IIsObject = GetObject (”IIS://” & ServerName & “/w3svc”)
   on Error resume Next
   Get_IUSR_Password = IIsObject.Get(”AnonymousUserPass”)
   On Error GoTo 0
End Function

Enjoy!


Jan 30 2009   1:30AM GMT

Easy String Searches with the VBScript Instr function



Posted by: Jerry Lees
InStr function, String manipulation, strings, string, VBScript, Scripting

I recently had a situation where I needed to find string inside a string to parse the larger string into usable and separate chunks of data. In writing this script, I realized I’ve not shared this gem of a function with you previously… and it really makes matters easier when you are manipulating strings.

That function is the Instr function. When configured with the proper parameters, by default, it will return the FIRST location in a string where a sub-string occurs. (Hint: this is where a mid() function would come in handy after you have that starting location). If the sub-string is not found, the function returns 0. The syntax is as follows:

Instr(StartPostion, StringToSearch,StringtoFind, Compare)

 

 The script I wrote really is a blog entry of it’s own, and will be, but I wanted to first introduce you to this great function and let you have a chance to play with it and see some code in action. Below is an example script that takes a string and searched for specific sub strings, then returns the location in the string where the sub string occurs.

 

Option explicit
Dim StrSource

StrSource = “Now I can find a word In a long string of words in a sentance.”

WScript.Echo(InStr(1,StrSource,”In”))
WScript.Echo(InStr(1,StrSource,”in”))
WScript.Echo(InStr(1,StrSource,” in “))
WScript.Echo(InStr(1,StrSource,”now”))

Below is the output from the script. Notice, the following:

  • The case of in and In in the sub-string being searched for and the positions it returns?
  • Notice the substring “in ” returns something entirely different?
  • Notice the substring now returns 0?

 

23
12
48
0

 

Enjoy!


Jan 23 2009   7:21PM GMT

Tip: Searching Google for solutions to a Microsoft product problem



Posted by: Jerry Lees
tips and tricks, troubleshooting, searching google, google, Microsoft, Microsoft Knowledgebase, KB articles

Maybe this isn’t earth shattering, and most all of you already know this trick. However, I just stumbled upon it and am willing to bet at least a few people are troubled by searching google for answers to problems and finding the needle in the haystack. Here’s the scenario:\

You’re looking for Microsoft Knowledge Base articles on a error your getting with a particular Microsoft application and using google to do the search because you can search better with it compared to the Microsoft site. However, you get so much noise back in your results in links to pages that were never solved, the solution is ambiguous, or (frankly) the solutions that are given are coming from sources where you simply question which end of the gene pool they are standing in at the time they wrote the proposed answer… you know what I’m talking about. Those guys that give answers like Format and call me back later or “Re-install the OS to get the drivers updated”.

Well, I suddenly noticed a trend at the bottom of some KB articles I had to call MS to get an answer to a problem. They are tagging the articles with key words! Yes, I know it’s not earth shattering. However, the following might help you.

For troubleshooting articles, it seems they always tag it with: kbtshoot

For articles that mention a event log error message they always tag it with: kberrmsg

Soooo…. If you need to search google for a Microsoft product KB article put this in as part of your search! It greatly limits the number of noisy results in your search! For example, you get trouble shooting KB articles for Microsoft CRM try this in a Google search:

kbtshoot “Microsoft CRM”

Of course that’s very generic… but hopefully you get the idea. Enjoy!


Jan 19 2009   4:14AM GMT

Windows Tip: Clearing Internet Explorer cached data from the command line



Posted by: Jerry Lees
tips and tricks, windows tips, command line, batch commands, batch files, Internet Explorer, rundll.exe, windows secrets, undocumented windows

As a Network Administrator sometimes you need to clear the browsing history, cookies, or the like for a entire community of users. Sure, you could tell them how to do it thinking that you were being super smart by providing instructions for them. However, as you well know there will be some who will be unable to follow the directions and you will spend 3 times the amount of time it took you to write the directions and refine them to a point where any one could do it— or so you thought. All the while, thinking about the amount of time you will save by having the users do it.

Why not be really lazy!!!??!? And do it with a batch script? You could then put it in their login script and it would happen at their next logon, or every logon for that matter. Well, there’s an easy way to do this with windows’ built in functions– it’s just obscure enough to not be found anywhere you would normally look!

Yo can preform many of the things I mentioned (and more) with Microsoft’s RUNDLL.EXE file, plus you don’t have to write a line of VBScript to accomplish the task!

Here is a short list of some tasks you can preform on IE, along with the command to do it… give them a shot!

Temporary Internet Files
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

Cookies
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

History
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

Form Data
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

Passwords
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

Delete All
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

Delete All - “Also delete files and settings stored by add-ons”
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

 These commands should work in Internet Explorer 7


Jan 5 2009   2:03AM GMT

Retrieve environment variable values from a remote system with WMI



Posted by: Jerry Lees
WMI, Environment Variables, Win32_Environment, VBScript, Windows Management Interface, System Administration, Remote management, PATH variable

Back in October I shared with you a way to retrieve environment variables with a script titled Using Environment variables inside a VBScript script. The script worked like a champ and got me through several tight binds in gathering information, hopefully it has for you as well. However, it has one flaw… it doesn’t work on a remote system! In fact, it only works on the system that the script is running on.

So, I had to recently go back to the drawing board and create a script and series of functions that would work remotely so that I could wrap it in a function to gather information from a bunch of servers. I also Learned a thing or two in the process!

First, The script uses the Win32_environment classes in WMI and this class returns ALL envirnment variables for ALL users. That threw me for a loop when I saw multiple PATH environment variables– some that were different. Second, The search is case sensitive without using the SQL % wildcards (I didn’t need them, so implementing that is left up to you the reader.)

I have the three functions I wrote, that are really variations of one another below. Just add them to your script and call them with the appropriate values and you should be in business!

Function RemoteAllEnvironmentVariables(ServerName)
     ‘Lists all environment variables on the remote system
    
Dim objWMIService, colItems, objItem
 
     RemoteAllEnvironmentVariables = “”
     Set objWMIService = GetObject(”winmgmts:\\” & ServerName & “\root\cimv2″)
     Set colItems = objWMIService.ExecQuery(”Select * from Win32_Environment”)
     For Each objItem in colItems
         RemoteAllEnvironmentVariables = RemoteAllEnvironmentVariables & objitem.name & “: ” & objItem.VariableValue & VbCrLf
     Next
End Function

Function RemoteAllEnvironmentVariablesVariations(ServerName, VariableName)
     ‘Lists all environment variables on the remote system, along with every case variation
     Dim objWMIService, colItems, objItem
 
     RemoteAllEnvironmentVariablesVariations = “”
     Set objWMIService = GetObject(”winmgmts:\\” & ServerName & “\root\cimv2″)
     Set colItems = objWMIService.ExecQuery(”Select * from Win32_Environment”)
     For Each objItem in colItems
         If UCase objItem.name) = UCase(VariableName) Then
         RemoteAllEnvironmentVariablesVariations = RemoteAllEnvironmentVariablesVariations & objitem.name & “: ” & objItem.VariableValue & VbCrLf
         End If
     Next
End Function

 
Function RemoteEnvironmentVariable(ServerName, VariableName)
     ’Lists all environment variables on the remote system, exactly as you typed it in the function call.
     Dim objWMIService, colItems, objItem
 
     RemoteEnvironmentVariable = “”
     Set objWMIService = GetObject(”winmgmts:\\” & ServerName & “\root\cimv2″)
     Set colItems = objWMIService.ExecQuery(”Select * from Win32_Environment Where Name = ‘” & VariableName & “‘”)
     For Each objItem in colItems
         RemoteEnvironmentVariable = objItem.VariableValue
     Next
End Function