Check for Registry Keys on Remote Computers with VBScript

December 9, 2008 14:35 by randy

I guess this would be Part 2 on VBScripting – for today.

In the first post, Check Running Processes on Remote Computers with VBScript, I outlined a VBScript process to determine if a specific process was running on a remote computer on the same network.

In this post, I have a VBScript that will scan the registry of remote computers on the same network for a specific registry key.  List the remote processes script, this process utilizes a file containing a list of all machines on the network.  The registry key name is a local variable. It would not be too hard to take this script and put it into a function and pass the registry key name (and machine list file name for that matter) as a parameter.

This script also utilizes Scripting API for WMI to interrogate the remote machine.

Take a look.

' Set up some Constants
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForAppending = 8
Const ForReading = 1
 
' Build the date tag for the log file name
sDate = right("00" & cstr(month(date())),2) & right("00" & cstr(day(date())),2) & right("200" & cstr(year(date())),4) & right("00" & cstr(hour(time)),2) & right("00" & cstr(minute(time)),2) & right("00" & cstr(second(time)),2)
' Build the full log file name
sOutFileName = "C:\Temp\reg_scan_log_" & sDate & ".txt"
 
' set this to the registry key to search
sKeyPath = "SYSTEM\CurrentControlSet\Services"
 
' Get the FSO moving
Set oFSO = CreateObject("Scripting.FileSystemObject")
 
' Open the file with containing all of the computers to scan (name or IP address)
Set objTextFile_List = oFSO.OpenTextFile ("C:\Temp\machineList.txt", ForReading)
' Create and open the file for logging
Set objTextFile = oFSO.OpenTextFile(sOutFileName, ForAppending, True)
 
' Loop through the file containing machine names/IP addresses
Do Until objTextFile_List.AtEndOfStream
    sMachine = objTextFile_List.Readline
 
 
    Set WshShell = CreateObject("WScript.Shell")
    bPing = Not CBool(WshShell.run("ping -n 1 " & sMachine, 0, True))      
 
    If bPing = True Then         
        Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sMachine & "\root\default:StdRegProv")
         
        ' Create an enum of the key values
        oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyPath, arrValueNames, arrValueTypes
         
        ' duh 
        ON ERROR RESUME NEXT
        
        ' check the array count
        If UBound(arrValueNames) > 0 Then
            objTextFile.WriteLine(sMachine & ": " & cstr(UBound(arrValueNames)))
        End If
        
        ' write the error message
        If err.number > 0 Then
            objTextFile.WriteLine(sMachine & ": " & err.Description)
        End If
 
    Else
        ' Set the appropriate response
        objTextFile.WriteLine(sMachine & ": Not on network")
    End If
 
loop

Thanks for listening


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Check Running Processes on Remote Computers with VBScript

December 9, 2008 14:09 by randy

When things get muddy in a small IT shop, it is time for everyone to help out!

That is how a developer gets pulled into helping the network and Help Desk folks.

That said, I created this quick (kinda) and dirty (definitely) VBScript to check for a specific process running on each of the machines on the network.  The process utilizes a file containing a list of all machines on the network.  The process name is a local variable. It would not be too hard to take this script and put it into a function and pass the process name (and machine list file name for that matter) as a parameter.

This script utilizes Scripting API for WMI to interrogate the remote machines.

Take a look.

' Set up some constants
Const ForReading = 1
Const ForAppending = 8
 
' get the FSO open
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
' Process you are looking for
sProcess = "csrsc.exe"
 
' Build the date tag for the log file name
sDate = right("00" & cstr(month(date())),2) & right("00" & cstr(day(date())),2) & right("200" & cstr(year(date())),4) & right("00" & cstr(hour(time)),2) & right("00" & cstr(minute(time)),2) & right("00" & cstr(second(time)),2)
' Build the full log file name
sOutFileName = "C:\Temp\scan_log_" & sDate & ".txt"
 
' Open the file with containing all of the computers to scan (name or IP address)
Set objTextFile = objFSO.OpenTextFile ("C:\Temp\machineList.txt", ForReading)
' Create and open the file for logging
Set objTextFile_Write = objFSO.OpenTextFile(sOutFileName, ForAppending, True)
 
' Loop through the file containing machine names/IP addresses
Do Until objTextFile.AtEndOfStream
    ' get the machine name from the current row of the file
    sMachine = objTextFile.Readline
    
    ' duh
    Dim Process, sResponse, sWriteMe
 
    ' Default the test response
    sResponse = "No"
 
    ' duh
    ON ERROR RESUME NEXT
    
    '   Ping the machine to make sure it is on the network
    Set WshShell = CreateObject("WScript.Shell")
    bPing = Not CBool(WshShell.run("ping -n 1 " & sMachine, 0, True))      
 
    ' only check for the process if the machine is on the network
    If bPing = True Then
        Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set cProcList = objWMI.ExecQuery ("Select * from Win32_Process Where Name = '" & sProcess & "'")
  
        ' if there are items in the collection ....
        If cProcList.Count > 0 Then
            ' Found it!
            sResponse = "Yes"
        End If
   
    Else
        ' Set the appropriate response
        sResponse = "Not on network"
    End If
    
    ' If there was an error ... Log it!    
    If err.number > 0 Then
        sResponse = err.Description
    End If
    
    sWriteMe = sMachine & ": " & "Running " & sProcess & " - " & sResponse
    objTextFile_Write.WriteLine(sWriteMe)
    
  Loop

Thanks for listening


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Dynamic Column Names in SQL Server Reporting Services 2005

December 4, 2008 11:57 by randy

I have been working on a SSRS report that produces financial data for a rolling 20 month period.  The SQL behind the report is pretty straight forward.  The challenge was dynamically setting each of the column names on the report to accurately reflect the month/year data presented by the SQL.

This task is made a little simpler since the column names are derived from dates, making it possible to calculate the values of the column names.

The other challenge with this process is that the report can be run for any specific date.  The obvious solution, and the one I used, is to pass a date parameter to a SQL stored procedure (You could have used straight SQL in SSRS and used the parameter as part of the WHERE clause – I just prefer to use stored procedures).  The fun part of this getting SQL Server and SSRS to play nice together (I know this sounds obvious and should be straight forward.)

 

Steps

1. Create the stored procedure allowing for an input parameter to accept the date.

USE someDB
GO
 
IF OBJECT_ID('someDB.dbo.uspSampleProc') IS NOT NULL
    DROP PROCEDURE uspSampleProc
GO
 
CREATE PROCEDURE [dbo].[uspSampleProc]
    ( @BaseDate        DATETIME
    )
 
AS
...

2. Create the report template in SSRS

 image

3. Create the report parameter and associate with the SQL parameter.

To get there:

  1. Go to the Data page for the report
  2. Click the ellipse (“…”) next to the Dataset Drop down
    image
     
  3. Then select the Parameters tab in the Dataset dialog box

image 

5. Edit the expression in the column heading text box(es) to reflect the rolling month/year indicated by the report data.

=RIGHT("0" & CSTR(Month(DateAdd("M", 1,Parameters!BaseDate.Value))),2) & "-" & YEAR(DateAdd("M", 1, Parameters!BaseDate.Value))
 

What’s going on here?

The above example would be used in the second column header label on the report.

Using the report date parameter as the base, it is possible to calculate the text value for the column headers.

The column name will show the month and the year that the column represents. EX: 01-2008

To ensure that the month and year displayed are in synch with the rolling monthly data, two separate string functions are combined to form the final text.

The “Month” part

The first string function determines the month indicator.  For this report, the month indicator needs to show with two characters.  As the “Month” function in SSRS does not do this for us, it is necessary to add a leading “0” to the numeric identifier for months January through September. 

To do this:

  1. Append a “0” to the left side of the numeric value that represents the month.
  2. Use the “Right” string function to pull the two right most characters from the string.

 

The second part of this string function determines the appropriate month to report.  This is done using the “DateAdd” function.  This function allows you to add or subtract from a date value to get anther date (more info on the DateAdd function here: MSDN SSRS DateAdd Function).  The example shows that the BaseDate report parameter will be incremented by one month.

The “Year” Part

This string function determines the year that corresponds to the rolling month value.  It utilizes the same “DateAdd” functionality as the “Month” string function.  The only difference is that the year is extracted from the new date value using the “Year” function.

HEY!  This expression will need to be applied to each column.  Each implementation of this expression will need to be updated to correlate to the appropriate rolling month.  Meaning: The units parameter of the DateAdd function will need to be updated to reflect the correct value. For Example, The third column header on the report, you would enter “3” for the units parameter of the DateAdd.

Done!

image

 

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Citrix in MOSS 2007 Without WISP 2007

November 18, 2008 10:09 by randy

I have been working on a solution for my current client that would allow the uses to access the Citrix web interface through their SharePoint home page.

There are a few ways to do this:

  1. Add a link to the SP home page that opens up the Citrix Web Portal
  2. Add a Page Viewer web part to the SP page, opening the Citrix Web Portal
  3. Install Citrix Web Interface for SharePoint 2007 (WISP 2007), and utilize the supplies Citrix specific web parts

Each of these solutions has it’s pros and cons.

  1. Adding a link to the home page is quick and easy, but not the most elegant way of doing things.
  2. Adding the Page Viewer web part to the front page offers a more intuitive solution.  This provides the users with an obvious place to login to the Citrix server and will also present their available applications in a familiar environment.
  3. The most robust solution is to install WISP 2007.  This solution provides an integrated solution to presenting the user with their Citrix application options.  This tool integrates Single Sign On, SharePoint and core Citrix functionality very nicely.

My client opted for solution #2: Add a Page Viewer web part to the home page.

To do this:

1. Add a Page Viewer web part to the pageAdd the Web Part

2. Edit the web part properties to add the URL for the Citrix Web Portal

Update the URL

HEY! In order for the Citrix Web Portal to function properly, the full domain will need to be added as a trusted domain on the client.

 Add site as trusted

3. After the domain is trusted by the client, the users will be presented with the familiar login interface of the Citrix Web Portal

Citrix Login Screen

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

A Great Link for ALL Programmers!

October 16, 2008 08:07 by oodnar

I know ... Two posts in a row with links.  Lame.  I know.  BUT -- This is a great article.

If you are or are planning to be a programmer - you MUST read this article by over at Coding The Wheel.

The Programming Aphorisms of Strunk and White

Enjoy!

 

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Cheat Sheets on PacketLife

October 15, 2008 13:57 by oodnar
HEY!

I just came across this link on Delicious:

http://packetlife.net/cheatsheets/

This is a great reference for network (and some non-network) geeks!

Enjoy.

 

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Using InfoPath Data in SharePoint Lists

October 10, 2008 14:37 by randy

When submitting an InfoPath for to a SharePoint list, the data from the IP form can be used to to populate values in the document list or other lists on the SharePoint site.

Here are the steps.

InfoPath

After the IP form is complete, the fields that are to be exposed to SharePoint need to be promoted as properties. 

1. Select the Form Options selection from the Tools menu
2. Select the Property Promotion option on the left side of the Form Options Dialog

clip_image002

3. Click the Add button to add a field to the list

clip_image004

a. The Select a Field or Group dialog box will show all of the fields used in the IP form.
b. Select the field you want to make available to SharePoint
c. Update the Column Name to the name you want to show in SharePoint

HEY! This name does NOT need to be the same as the field name you selected from the list. IP/SharePoint keep a reference to the field, not the pushing name.

HEY! When you select the field from the list, IP will attempt to create a user friendly name for the field. The result of this is the addition of spaces added to the name. Sometimes this makes sense, not often. So make sure you check the name before you click OK.

 

d. Click OK
e. Repeat this for all of the fields you want to be available in SharePoint

clip_image006

4. Publish the form to SharePoint

SharePoint

In the list used to store the data from the IP document (this can be the same list used to store the IP document or a different list altogether), create new column(s) to store the data.

1. Select the List Settings option from the Setting menu option
clip_image008

2. Under the Columns group, select Create Column
3. Enter the data for the new column: Name, Type, Description, etc…
4. Click OK
5. Repeat steps 2-4 as necessary to add all of the columns needed

SharePoint Designer

After the IP form has been completed and submitted to SharePoint and the workflow is started, the fields that where promoted will be available to the work flow.

This example is based on a custom work flow in SharePoint Designer


To reference the fields from the Conditions logic section:

1. Utilize the first condition block or add a new one
2. Select the “Compare <Your List Name Here > field” option

clip_image010

3. Select the Field label on the new condition description

clip_image012

4. The promoted fields, along with all other list fields, will show in the list
5. Select the field you want to test
6. Select the Value label
7. Enter or select the appropriate value for the conditional test

clip_image014


To use the promoted fields to populate the current list:

1. Create a new Action
2. Select the Update List Item option

clip_image016

HEY! The order of items in this list is dynamic. Items will not always show in this order. The order of the items is based on the last one used.

3. Leave the List selection as Current Item
4. In the Update List Item dialog box click the Add button
    a. From the Set this field dropdown, select the field (column) to update
    b. Select the clip_image018 (function) button next to the To this value box
          i. Leave the Source field as Current Item
          ii. From the field dropdown, select the promoted field to use
          iii. Click OK
     c. Click OK

     clip_image020

     d. Repeat for each column that is to be updated with the IP form data

5. Click OK


To use the promoted fields to create a new list item in a different list:

1. Add a new Action
2. Select the Create List Item option

clip_image022

3. Select the this list option
4. From the List dropdown, select the list to use

HEY! After the list is selected, the Field/Value list will show all of the required fields (columns) for the list

5. In the Create New List Item dialog box click the Add button
     a. From the Set this field dropdown, select the field (column) to update
     b. Select the clip_image018[1] (function) button to the right of the To this value box
          i. Leave the Source field as Current Item
          ii. From the field dropdown, select the promoted field to use
          iii. Click OK
     c. Click OK
     d. Repeat for each column you want to update with the IP form data
6. Click OK

To use the promoted fields to update an existing list item in a different list

1. Create a new Action
2. Select the Update List Item option

clip_image024

3. Select the this list option
4. From the List dropdown, select the list to use
5. In the Create New List Item dialog box click the Add button
     a. From the Set this field dropdown, select the field (column) to update
     b. Select the clip_image018[2] (function) button to the right of the “To this value” box
          i. Leave the “Source” field as Current Item
          ii. From the field dropdown, select the promoted field you want to use
          iii. Click OK
     c. Click OK
     d. Repeat for each column you want to update with the IP form data
6. Select the appropriate list item to update
     a. From the Fields dropdown (at the bottom of the dialog), select the field to use as a unique reference for the item to be updated
     b. Enter the value to be used as the key to identify the list item to be updated. (if the data is stored as a work flow variable or a promoted field, use theclip_image018[3] (function) button to reference that data)

     clip_image026

7. Click OK

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Develop a custom OR approval workflow in SharePoint Designer

October 2, 2008 09:04 by oodnar

I have moved the contents of this post to the Tutorials page.  Things just got a little too crowded!

 SharePoint Designer provides a good interface for workflow development.  One, of the few, drawback is that; it is not always intuitive.  One case of this is creating a custom approval workflow.

I have blogged before about creating a custom approval workflow with multiple approvers.  This example shows how to create the approval workflow with multiple approvers.  Each approver is required to review and act.

This example shows how to create an approval workflow that allows for multiple approvers, but only one is required to act.

Develop a Custom OR Approval Workflow with SharePoint Designer

Thanks for listening!

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

VS 2010!!!!!!

September 29, 2008 11:31 by randy

Microsoft announced the latest version of Visual Studio today!  VS2010!

Take a look at the new web page:

http://msdn.microsoft.com/en-us/vstudio/products/cc948977.aspx

Pretty cool!!!!!!!!!

Here is a link to the press release too:

http://www.microsoft.com/presspass/press/2008/sep08/09-29VS10PR.mspx

 

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

AZ SharePoint User's Group Meeting

September 26, 2008 08:35 by randy

 

A big THANKS! to the folks (Tim and Doug) over at AZSharePointPros.com for last night's AZ SharePoint User's Group meeting.

The meeting was very informative and there was a a full house.

Rick Taylor's presentation on forms based authentication for MOSS was particularly interesting to me.  This technique will allow me to save one of my clients some monthly money by moving their SharePoint extranet inside.  This will give them immediate control of the users and content.  They are going to soooo excited!

Tim Baggs' did a great job with everyday workflows in SharePoint Designer. (I don't know anyone that speaks that fast!)  I think everyone learned something.  Thanks to Tim, I have a new method for creating great forms for data collection in my custom workflows.  Can you say "data view", I knew you could.

Thanks again guys!

Thanks for listening.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5