Caveman's Blog

My commitment to learning.

Archive for the ‘Tools’ Category

PSExec: Execute batch files remotely

with 2 comments

PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software. PsExec’s most powerful uses include launching interactive command-prompts on remote systems. [1]

Ad-hoc execution of batch files from on server remotely using psexec is an easy and a time saving activity. Here is an example of how to execute a batch file using psexec:

psexec \\REMOTESERVERNAME -u [USERNAME] -p [PASSWORD] /accepteula -d -i cmd /c D:\FILE.bat

cmd /c – this gives a context to the psexec to

/accepteula – this switch will simulate the accepting eula agreement.

D:\ – drive on the remote server

-d – Don’t wait for application to terminate. Only use this option for non-interactive applications.

-i – Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.

The output of the execution would be that cmd exited on with error code 0.

Update: 09-13-2012

All of a sudden the above command started to fail. At this point my guess is that some network settings/permissions must have got updated preventing the command to execute successfully. Following is the error

Error: The parameter is incorrect.

Fix: psexec \\REMOTESERVERNAME -u [USERNAME] -p [PASSWORD] /accepteula -h cmd /c D:\FILE.bat


1. PsExec v1.98

Written by cavemansblog

June 22, 2012 at 10:32 pm

OpenXML + Linq = Awesome Office files

leave a comment »

Office Open XML (also informally known as OOXML or OpenXML) is a zipped, XML-based file format developed by Microsoft for representing spreadsheets, charts, presentations and word processing documents. [1] If someone is looking for software to generate MS-Office file programatically, I would highly recommend considering this library. I have recently used OpenXML to generate Excel reports from a windows service. The library was very fast in generating reports with a lot of data and the best part about this library is that it is free ūüôā Microsoft provides a SDK that can be downloaded from here and can very easy used to generate awesome Office reports. Following are some resources for OpenXML development:

Here is a utility function that converts a List of objects into a DataTable, that can be easily exported to an OpenXML file. Basically in the code below, while loop through the contents of the List object, we use reflection to read the List object properties to create the column names of a DataRow object. Data from each List object is then populated in the DataRow object which will then be used to fill our DataTable.

public DataTable ConvertToDataTable(List<EmployeeData> varlist)
    DataTable dtReturn = new DataTable();
    // column names
    PropertyInfo[] oProps = null;

    if (varlist == null) return dtReturn;
    foreach (EmployeeData rec in varlist)
        if (oProps == null)
            oProps = ((Type)rec.GetType()).GetProperties();
            foreach (PropertyInfo pi in oProps)
                Type colType = pi.PropertyType;

                if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
                == typeof(Nullable)))
                    colType = colType.GetGenericArguments()[0];

                dtReturn.Columns.Add(new DataColumn(pi.Name, colType));

        DataRow dr = dtReturn.NewRow();
        foreach (PropertyInfo pi in oProps)
            dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
            (rec, null);

    return dtReturn;

1. Office Open XML – Wikipedia
2. Open XML SDK 2.0

Written by cavemansblog

September 21, 2011 at 1:37 am

Creating multiple websites on IIS 5.0 + Win XP

leave a comment »

Some time back I was using windows XP Pro for development at work. One thing that I was unable to figure out was to create one website per project with in IIS. The answer to this is that there isn’t a way to accomplish this using the IIS Management Console. I did some searching on the web and found a couple of awesome free tools that serves the purpose.

XP PRO IIS Admin [1] and IISAdmin.Net [2] are of tremendous help with setting up and allowing you to easily add new websites, and switch between them. One thing to keep in mind is that we can only have one active website at a time. I wonder why microsoft left out on this feature from the IIS mmc.

1. IIsAdmin.NET: Create Multiple Web Sites Under Windows XP by Mark Belles, Gabe Wishnie

2. XP Pro IIS Admin by JetStat

Written by cavemansblog

February 14, 2011 at 2:03 pm

PSExec: Remote command execution

leave a comment »

Ever wondered how to remotely execute a command on a remote machine. Here is what I had to deal with, leading to my research and a subsequent discovery of this powerful utility. We have this ASP.Net project that was getting deployed to the various in-house environments using Hudson, a continuous deployment tool. There was this requirement that the web.config had to be encrypted. In our project configuration setup, the files from the build (CI) server will be deployed/coped to various environments, however the web.config cannot be pre-encrypted, rather it has to be encrypted in the hosting environment.

I have created a batch file  that has to be executed on the deployed environment to be able to encrypt the web.config file. PSExec came to my rescue by being able to execute the batch file on the host environments from the continuous integration server. The account that is used to run Hudson should also have rights on the host machines to be able to run PSExec.

PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software. PsExec’s most powerful uses include launching interactive command-prompts on remote systems and remote-enabling tools like IpConfig that otherwise do not have the ability to show information about remote systems. [1]

Example 1:
psexec \\MACHINE_NAME c:\temp\encrypt.bat

Example 2: This is very useful when you have to perform am IISReset remote

Example: 3 - Explicitly pass user credentials

Example: 4 - Use this to encrypt the web.config settings after a deployment using Hudson
psexec aspnet_regiis -pef appSettings

I hope I made my point in showcasing a capability of this tool. Here is a good read about the inner working of psexec.

1. PSExec – by Mark Russinovich

Written by cavemansblog

September 15, 2009 at 3:33 pm

SQL Server: Data dictionary

leave a comment »

Data dictionary creator [1] is a simple-to-use free tool that helped me immensely with a SQL Server database documentation. It stores all the information in Extended Properties, so it’s easier to keep the documentation in sync with the database as it changes. I was able to generate a data dictionary with a couple of of mouse clicks after I have entered the connection string. The dictionary can be exported to various formats: Excel, XML, Word and HTML. Click on the reference [1] for a step by step tutorial on the usage of this utility. (The current version does not seem to support SQL Server 2008). This can be download from codeplex.

Data Dictionary-90

1. Data Dictionary Creator

Written by cavemansblog

July 15, 2009 at 9:49 am

Posted in Sql Server, Tools

Tagged with