Thursday, September 23, 2010

Create Service-Stopping Batch Files to Optimize Your PC for Specific Tasks

You may have lots of software installed on your PC, but you don't need it running all the time. If you want to save some system resources, or just create a distraction-free environment in one click, a simple batch file can help.

First I'll walk through how to create a batch file for anyone unfamiliar with the handy Windows scripts, and then explain how to use some simple commands to start or stop resource-draining services or kill distracting applications.

Creating a Batch File and Starting Applications
To create a batch file, all you need to do is create a new, plain-text file with the .bat extension, and enter any commands in the file the same way that you would use them on the command line. You then execute the batch file (by, say, double-clicking it), and it'll run through the commands in the order you've written them into the file. Simple enough?

If you wanted to start a new instance of an application you should precede it with the start command. For example, to create a batch file that would start Notepad and open a new Explorer window that shows a certain folder, you could put these two lines into the batch file:
start notepad
start explorer c:\path\to\start












The batch file displays each command as output on the console, so if you would like to prevent that you can add the @ symbol before the command to eliminate extra output, or you can simply put this line at the top of the file:

@echo off

Now that we've got a few simple batch-file basics out of the way, lets move on to more useful batch file tasks. (Remember, you can copy and paste any of the commands below into a plain text file, save it with the .bat extension, and you've got yourself a batch file.)


Stop or Start Services in a Batch File

Many applications these days install a bunch of supporting services that help the application, but they really don't need to be running all the time. On my system, I've found this is especially true for virtual machine software, which often installs a bunch of heavy services that use a lot of extra resources. If you aren't running a virtual machine all the time, they really don't need to be running.

What we can do is create a batch file that stops the services, and another batch file that starts them back up. To do this, you can simply use the net command with start or stop as the first parameter, and then the name of the service after it. You can either use the service short name, or the display name in quotes, like one of these two examples:

net stop wuaserv
net
stop "Windows Update"

You can find the service names easily enough by opening the Services tool (use your Start menu search to find Services and run it) and double-clicking on one of the services. You'll see the short service name highlighted in the example below:















(For another way to look at the services that are currently running on your system, pull up the Windows Task Manager (Ctrl+Shift+Escape) and click the Services tab.)

You can start the services again by using the opposite command, like so:

net start wuaserv

Note that if you're using Windows 7 or Vista and you've still got UAC enabled, you'll need to run the batch file as administrator to actually stop the service. You can create a shortcut to the batch file and specify to always start as administrator in the shortcut properties to eliminate having to right-click every time.


Kill Applications with a Batch File

While stopping services is helpful to free up some system resources, you'll be able to free up a lot more resources by killing applications that don't need to be running—which can also be very helpful in killing distracting notifications and the like when you really want to focus. For instance, if you really should be writing that paper, you could have a KillDistractions.bat file that turns off everything else other than your preferred text editor.

To kill an application from the command line or a batch file, all you have to do is use the taskkill command with the /IM parameter, which matches the image name column from Task Manager—which is really just the file name of the application executable. For instance, to kill Notepad you would use the command like this:

taskkill /IM notepad.exe

This command by default will simulate clicking the red X in the corner of the window, so you'll be prompted to save your work if necessary. If you wanted to kill applications instantly without saving anything, you could use the /F parameter to force kill instead, like this:

taskkill /F /IM notepad.exe

taskkill /F /IM chrome.exe
You've got plenty of other parameters to choose from with the taskkill command, which you can browse with the /? parameter (i.e., type taskkill /?).


Create a Shortcut to Start the Batch File
Now that we've walked through the basic commands you'll need to create a batch file that starts or stops all the services and applications we don't need running, we can make the last line of the batch file start up the application that we're planning on running, and then customize the shortcut to start the batch file minimized so the Command Prompt window isn't flashing on the screen. So right-click your desktop or in any Explorer window, go to New -> Shortcut, and point it toward your batch script.












If you click the Advanced button on the shortcut window, you'll be able to specify to run the application as administrator if necessary. If you're stopping services in the batch file, you'll need to use this option, though you should note that any applications you start in the batch file will also be started as administrator. Of course, if you've disabled UAC, this won't matter either way.

Putting It All Together
Now that you know how to stop services, kill applications, and create the proper shortcuts, it's time to put it all together into a useful combination. Here's an example script that I use to kill distractions when I'm ready to switch into writing mode, but you could customize this to fit anything you might need.

taskkill /IM tweetdeck.exe
taskkill /IM chrome.exe
taskkill /IM firefox.exe

taskkill /IM pidgin.exe
taskkill /IM notepad.exe

Since I often use virtual machines to do my testing, I've also created batch files that start and stop the services when necessary to make sure that I'm only wasting resources when I actually need the virtual machines running. To stop the services, I've created a file called stopvmware.bat, though I've also set all these services to manual startup, so I only need to use this after I close VMware.


net stop VMAuthdService

net stop VMnetDHCP
net stop "VMware NAT Service"

net stop "VMUSBArbService"

Then when I need to start VMware again, I can simply use my startvmware.bat file, which starts up the services and then launches the VMware application.

net start VMAuthdService
net start VMnetDHCP
net start "VMware NAT Service"

net start "VMUSBArbService"
start "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe"

You can customize these scripts to do anything you might want, and tailor them to your environment, but this should give you the tools you need to get started creating your own time-saving batch files.

Friday, September 17, 2010

Securely Delete Files in Mac OS X

    I want to share a little known fact about Mac OS X with you but first I want to explain why this is important.  In today’s world, there are identity thieves around every corner just waiting for the chance to steal your personal information.  In addition, the theft of computers, especially laptop computers, is at an all time high.  Therefore, it is important that each of us remain vigilant against this threat. 
   
    Hard drives store data magnetically.  Meaning that if you simply delete a file, that file remains on your hard drive until it is overwritten.  This may be a matter of days or months depending on how you use your computer.  Mac OS X provides a way for you to easily and securely delete your files when you empty your trash can.  Here is how to do it.

    After you place the “deleted” files into your trash can, open up the finder preferences tab and find a check box that says securely delete files.  Click on that and now every time you empty your trash can, Mac OS X deletes your files and then writes random data over the area of the hard drive where those files lived rendering it virtually impossible to recover.

    Yes, I know this is an overly simplified explanation but I believe it will suffice for our purposes here.  If you want to learn more about how computers store data, visit this link http://www.ontrackdatarecovery.co.uk/data-recovery-articles/how-data-recovery-works/

    Thanks for taking the time to read this post and I hope you remember to take computer security seriously!

Thursday, September 16, 2010

Adding to text fields together in Microsoft Access

I have a very short post for you guys today but it can save you lots of time.  I needed to add a person's last, first, and middle names together in one field for a report.  Each one of these is a separate field in my database.  I accomplished this by creating a query and adding all the appropriate fields that I needed.  Next, I clicked in a blank field in the query designer and added the following line of code. 

Full_Name: [Name_Last] & "" & ", " & "" & [Name_First_MI] & "" & " " & "" & [Name_Middle]


This concatenated all these fields together with a comma and a space after the last name and a space after the first name.   After that it was easy to create the report based on this query.  It looks great and I have adapted this technique to other data types as well. 

I hope this will be useful to you in the future. 

Wednesday, September 15, 2010

Internet Explorer 9 Beta

Today in San Francisco, Microsoft will officially unveil Internet Explorer 9 and make it available to the general public. It is, without question, the most ambitious browser release Microsoft has ever undertaken, and despite the beta label it is an impressively polished product.

For the record, I haven’t used Internet Explorer in years.  I usually stick with Safari on my Mac and Firefox on my PC.  However, with the release of IE9 I might have to change my default browser back to IE. 

The new IE has a greatly improved javascript engine and it renders HTML much better than previous versions.  It is also embracing HTML5 which is something IE has needed to do for sometime now. 

The biggest difference to me is the UI.  It is very minimal and there is almost no branding beyond the logo on the task bar.  This browser focuses more on the content of the web page than on the browser. 

At any rate, you should check out the beta version for yourself and give it an honest try.  It may win you back to the Internet Explorer users group!

Friday, September 10, 2010

Keyboard Shortcut for Access 2007

I have a small tip for you Microsoft Access people out there.  If you want to make a keyboard shortcut for a button click event or a shortcut for some type of an event in a form, I have a simple way to accomplish this. 

Use the “&” sign followed by the key you want to use as the shortcut after the caption definition and there you have it.  For example, if you have a button with a caption called Close you can create the shortcut by typing the “&C” after the word close.  After you have completed that you should notice the letter C on the button is underlined.  This means typing the letter c on your keyboard will activate the button.  Now you have a keyboard shortcut.  Have fun and don’t forget to comment!

If you have any topic ideas, or you have an article that you want to submit for posting on this blog, email me at jeff.trehern@gmail.com

Thanks!

Jeff

Welcome!

    Hello and welcome to my new blog.  Since this is my first post I wanted to write a little something to introduce myself.  My name is Jeff Trehern and I am a 31 year old IT professional.  I have a bachelor’s in Information Systems Security and I currently work for a local government.  Some of my responsibilities are to develop database driven applications, maintain current and develop new network infrastructure, and create and enforce information security policies. 

    This blog will primarily focus on technology driven subjects that will range from the beginning home user to the advanced application developer.   If at anytime you have an idea for a topic or just need some advice on a topic, feel free to write me at jeff.trehern@gmail.com. 

Thank you for taking the time to read this.  More is on the way soon!