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

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

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

From the Wayback Machine

September 16, 2008 12:05 by randy

So… Here I am, setting up a new dev box. I have installed VS2008 and start the process of applying SP1. (Slow at best.)

I left it to do its thing and went on to do other work.

When I checked on the progress, I noticed something from the Wayback Machine.

In the lower right hand corner, just below the “Installer Progress” bar, is an old fashioned spinning line! For those of you who are too young to know what that is; back in the old days, we used to use the “|”, “/”, “-“ and “\” to show the user that the program was still running. Similar to the AJAX process indicators.

Holy cow – Do I feel old!

clip_image002

clip_image004

clip_image006

clip_image008


Be the first to rate this post

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

Custom Approval Workflow

September 12, 2008 16:15 by randy

What

One of the first tasks I needed to take care of for my current client was to create a multi-level workflow.  The client’s main requirement was that the workflow be designed in SharePoint Designer.  The second requirement was the data collection was to be done with an InfoPath form.

How

This was implemented by utilizing C# behind the IP form, published properties from the IP form, workflow variables in SharePoint Designer and custom tasks in SPD.

Flow (The other requirements)

The process to be controlled by the workflow is used to grant access to internal systems.  Access to these systems is granted by the company division that controls the systems.  In this case, there were three divisions.  The request is to be routed from division to division sequentially.Additionally, the request is rejected or approved as a whole.  If any division rejects the request the entire request is rejected.The initiating user was also to be kept in the loop as to the status of the request.  Email notification from the workflow was used to meet this requirement.

The Details

I have created a tutorial that outlines the steps that were taken to implement this solution:
http://cycogeek.fiesta25.com/blogs/cycogeek/page/Create-Custom-Approval-Workflow-with-SharePoint-Designer.aspx


Take a look.  Any and all feedback will be appreciated.

Thanks for listening.

Be the first to rate this post

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

Change Task List Associated with a Custom Workflow

September 4, 2008 16:51 by randy

When you create a custom work flow in SharePoint Designer, the work flow attaches the work flow tasks to the first list it finds.  This is usually the first list shown in the "List Gallery".

There are two ways to deal with this.

The first is to create a new list and name it in a way that will put it first in the list.  IE: AAA My Task List. Then create your new work flow.  This is not alway sconvenient as the work flow may already be created.

The second way it to edit the xxx.xoml.wfxconfig.xml and change the GUID related to the task list.  

1 <Association  
2         ListID="{F718E2A9-5EF0-4283-86DC-09368C070460}" 
3         TaskListID="{1C52F4AD-F0FA-4856-824B-B391B76260DB}" 
4         StartOnCreate="true" 
5 > 
6  


NOTE: This will need to be done in each of the supporting .aspx files as well.  The easiest way to do this is the good ole ctrl+h (Find and Replace).

To get the GUID for the new list:
1. Open the list you want to associate the work flow to in SharePoint
2. Goto Settings --> List Settings
3. Right click on "Audience targeting settings"
4. Select "Copy Shortcut"
5. Open Notepad (or other text editor)
6. Paste

It will look similar to this:
http://spsp/_layouts/ListEnableTargeting.aspx?List={f01fc4bf-6185-4d7f-a4bf-276b0beacf07}  

This is the GUID for the list.

Thanks for listening.


Be the first to rate this post

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