Skip to main content

Posts

Generate GUID in Python running in Windows

GUID can be useful as a primary key for a databases and also for the records or rows of data that needs to be unique. There are a lot of tools that can generate a GUID but in this quickie blog, I am documenting how to generate a GUID using Python in Windows. To generate a GUID, import the code below: import pythoncom _guid = pythoncom . CreateGuid () _guid_str = str ( _guid ) print "%s GUID is %d long" %( _guid_str , len ( _guid_str )) ~ts~

Grab screen capture programatically

Pre-requisite: Python 2.5 for Windows Python Imaging Library ( PIL ). Install Python 2.5 for Microsoft Windows. Make sure that you have administrative rights to be able to install the application properly. After having verified that Python is installed and working, install Python Imaging Library. See below for a sample of screen capture python script. #--<-start code here->-- import ImageGrab ; img = ImageGrab . grab () img . save ( "D:\\test.jpg" ) #--<-end code here->-- ~ts~

Detecting the process using/locking a file

In Windows, if a file is being used, normally user cannot delete it. But there are cases, especially during development and/or troubleshooting, where a file needs to be deleted or renamed. The issue here is that deleting a locked/used file is not allowed in Windows. Windows Explorer does not give even a slight hint as to who has the lock on the file. Fortunately, Mark Russinovich of Microsoft , developed a tool to list the process that is having a lock on the file. The name of the tool is "handle" and can be downloaded from the site . If you have a file readme.txt and you want to delete it and for some reason their is a rouge application getting hold of it. To get the process name of the application that's using it, just issue the command: handle readme.txt ~ts~

Clear arp cache

Background: The address resolution protocol (arp) is a protocol used by the Internet Protocol (IP), specifically IPv4, to map IP network addresses to the hardware addresses used by a data link protocol. The protocol operates below the network layer as a part of the interface between the OSI network and OSI link layer. It is used when IPv4 is used over Ethernet. The term address resolution refers to the process of finding an address of a computer in a network. The address is "resolved" using a protocol in which a piece of information is sent by a client process executing on the local computer to a server process executing on a remote computer. The information received by the server allows the server to uniquely identify the network system for which the address was required and therefore to provide the required address. The address resolution procedure is completed when the client receives a response from the server containing the required address. An Ethernet network uses tw

Uninstall an application from the command line

Software automation testing sometimes need to perform installation and un-installation of software products. One of the new things that I learned was that a user can un-install a certain application from the command line. To determine how to uninstall a certain product, open registry and navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall. For the application that you want to uninstall look for the key "UninstallString". Copy and paste this string in the command line, hit on {ENTER} and it should uninstall the application for you. ~ts~

Determine the application that spawn a certain process

Maintaining the performance of a computer takes a lot of research and tinkering of the system. One of the tools that that I find really useful is Process Explorer formerly of Sys Internals which is now a part of Microsoft. It was originally and still is designed/maintained by Mark Russinovich, et al. One of the key features that I like with Process Explorer is that it shows a tree view of the running process in a system. And in addition to that it allows the user to search by process handle or a DLL substring. The best feature that I like with this tool is that it shows you the command line arguments used to run the application. If you think this is too good to be true, see for yourself. Head to http://www.microsoft.com/technet/sysinternals/utilities/ProcessExplorer.mspx and download the file. ~ts~