Modifying Windows XP Services via Batch

The other day I found myself needing to both stop and disable a bunch of services in windows XP on multiple machines. After doing this manually through the Windows GUI on a few machines, I decided to figure out how to do it using the command line.

  • First, you’ll need to find the name of the service that you’d like to modify. Click Start > Run, type “services.msc” and click OK.050109_services1
  • The MMC will pop up and list every service on the machine along with its “Current Status” and “Startup Type”. Every service is either in the “Started” or “Stopped” state, and is set to run based on the value in “Startup Type” (Maunal, Automatic, or Disabled).050109_services2
  • Find the service you would like to modify using your batch script. For this example we will use DHCP Client. Double-click the service and a properties window will appear showing you the details of the selected service. The information you’ll need from this window is the Service Name. For the DHCP Client, the service name is “Dhcp”.050109_services3
  • Modifying services via the command line or via batch is done by using the command sc (Service Controller). For this example, I’ll discuss stopping and disabling the service, but you can see all that is possible by typing sc /? at a command prompt.
  • To stop a service, type sc stop [service name] at the command prompt. For this example, the command would be sc stop Dhcp
  • To disable a service, type sc config [service name] start= disabled at the command prompt. For this example, the command would be sc config Dhcp start= disabled (yes you need the space after the equals sign)

That’s it! You could then compile as many of these commands into one batch file for easy and/or remote execution. For details on creating Windows batch files, click here.

Finding the Best Tech Deals on Tech Equipment

If you are a tech junkie like me, you tend to buy a lot of tech products. So getting the best price on them is critical. Warning: going to the sites on a daily basis may entice you into buying things you normally wouldn’t buy. I still have 8 HDMI cables fom the 10 pack I bought. Of course the 10 pack only cost $20 and came to my door with free shipping. You would pay more than $20 for a single cable at your local electronics retailer.

Pricing and Reviews

When considering a purchase (online or otherwise) you need to be able to compare the cost of the product at multiple retailers. Froogle is the only site you need. (Sorry Google, I know you call it “Google Product Search” now, but that is lame. And if you didn’t want me to call it froogle, stop forwarding froogle.com to Google Product Search) Just put in whatever information you have (Ideally, a manufacturers product code) and hit Search Products. For this example, I will search for the Samsung TV (HL72A650) I have been considering.

If froogle returns an exact match (entries that can be directly compared), it will be listed as the first item. It will show you a price range as well as a Compare Prices button. Below this, all matches will be listed. Since I am looking for the best price on this unit, I’ll click the Compare Prices button.

froogle_prices

The result is a sortable list of multiple retailers’ prices (above). Some of them show the shipping cost as well. You can also access tech specs and reviews of the unit. Froogle is a great utility and I use it for every tech purchase.

Note: If you are specifically looking for computer components, pricewatch.com is the site to use.

Reviews are also a great way to determine the pros and cons of a product. I rely on amazon.com. I have found that on any given product, they usually have the largest array of original (non-aggregated) review data. They also display the data in a very usable way.

froogle_reviews

You can can browse all the reviews of course, but at the top they show you two specific reviews. They are the most favorable review that was deemed the most useful by the user community and the most critical review that was deemed the most useful by the user community. This setup provides and quick look into the most useful review data by cutting out both the “Dude this TV is awesome!!!!!!1″ and the “Mine came damged…LOL SamSung SuX!!!” reviews.

Deal of the Day

Many websites have a “Deal of the Day” where they sell a single product at a great price. Checking these daily will give you exposure to those impulse purchases. The hands-down best site for this is woot.com. Woot sells one product every day and when they run out, the deal is done. The best deals tend to be gone really quick, so check this one early. Every once in a while there is a “woot-off” where they have multiple deals that run one after another. There are usually some great deals to be had during a woot-off, but you have to be quick. The best items can disappear in seconds. Woot is also famous for their $5 shipping. Anything you buy costs $5 to ship. Even the 100 lb. pair of speakers I bought through them. Make sure you read the product stories as well, they are usually really funny.

deals

If you find yourself needing more, there is always sellout.woot.com. It is basically just another deal of the day, without all of the woot flare. Sometimes the deals on woot and sellout.woot go together. (I bought a subwoofer on sellout.woot the same day I bought speakers on woot).

Amazon’s gold box has some great daily deals so check that out too. Buy.com’s deal of the week is usually worth a look as well, and it is always a good price. (Ok, make sure to double-check that using froogle)

Aggregators

Here is where the real danger comes in. Tech deal aggregators are websites dedicated to pulling the best tech deals into one place. They do all the legwork of finding the deals for you.

aggregators

Techdealdigger.com and techdeals.net are pretty much the same thing. They do however often offer different products, so sign up for both RSS feeds. These sites have consistently great deals on speakers, TVs, computer peripherals, digital cameras, video games, etc, etc. Other sites like techspot’s hot deals, techbargains.com and cnet’s techdeals provide a similar service, but for one reason or another I find myself using them less frequently.

Finally, Gizmodo (a great tech site in general) has a daily (usually) roundup of deals. These deals (tag: dealzmodo) are categorized for you, and include what they call “hobomodo”, which provides links to forms and coupons that will get you free stuff (food, magazine subscriptions, etc).

I hope you enjoyed this roundup and please leave a comment if you have a good site for pricing, revies or aggregation that I can include in this post.

Mmmm Sandwiches

I love sanwiches - probably a little too much. On any given day, I’m eating one (okay - probably two or three). I make my own, I get them at restaurants, I’m even considering buying this shirt. Anyhow, here are a couple of cool websites dedicated to sandwiches.

scanwiches

For a quick fix, check out scanwiches. The concept is simple…

  • Step 1: buy sandwiches
  • Step 2: cut sandwiches in half
  • Step 3: scan sandwiches on a flatbed scanner
  • Step 4: profit?

Scanwiches is weird and fun, but when you want to get down to business, check out unbreaded. Reviews, recipes, and interviews - a one stop shop for the DIY sandwich artist and/or sandwich enthusiast. Enjoy!
unbreaded

Create a Font with Your Handwriting

blattifontHave you always loved the decreased readability of handwritten notes, but were turned off by their efficiency? Well check that problem off your list. Thanks to yourfonts.com (via lifehacker) you can now create a (free) font that mimics your handwriting.

All you need is a printer for the template, a scanner to scan in your chicken scratch (yes even a piece of crap Hewlett Packard can handle the job) and about 5 minutes you are willing to waste. Tada! All kidding aside - this is pretty cool - even though I’ll never use it.

blattifontexample

Back in Business

Well after a long hiatus I plan to get back to blogging. I spent a lot of time working on a theme from the ground up that I grew to hate by the time it was done. So I threw this one together in 30 minutes and finally got to the current version of WordPress. The site now has everything (all the way back to 2003) when I was making static posts without any blogging software (yes - we are talking Jackson Showdown territory).

You will notice things change over the next couple of weeks as I customize this theme and clean up the garbage. Until then, these are for you Ford.

Modifying Menubar Items in OS X

I had a lot of trouble figuring out how to do this so I figured it would be a good thing to post.

First of all, what is this called?

menubar.jpg

Is it the toolbar? The menubar? Trying finding the answer to something on google without being to identify one of the key terms can be taxing. Anyhow, whatever it is called (I’m going with menubar), it is controlled by the SystemUIServer process, that much I know. And what is shown up there depends on settings in multiple preference panes and applications. When it comes to preferences that you set in System Preferences.app, this information is stored in com.apple.systemuiserver.plist. You can see what is in that plist by typing defaults read com.apple.systemuiserver in Terminal.

Check the man page for defaults before you do any writing and be sure you understand what you are doing. (It probably wouldn’t hurt to make a backup of the plist as well (you whimp))

Using defaults write, we can set which items will appear in the menubar by editing com.apple.systemuiserver.plist. This could come in handy in any situation where you wanted to change between two different layouts of those items (using a script for example).

This command will wipe out your current defaults, and create an empty menubar.

defaults write com.apple.systemuiserver '{"menuExtras" = ();}'

This command will set the defaults so that only the clock and volume items show up in the menubar:

defaults write com.apple.systemuiserver '{"menuExtras" = ("/System/Library/CoreServices/Menu Extras/Clock.menu", "/System/Library/CoreServices/Menu Extras/Volume.menu");}'

Since you are only “writing” defaults with the above commands, you will need to re-launch the SystemUIServer process in order to see the change. Do this by typing killall SystemUIServer in Terminal.

I hope that you found this when you needed it without too much googling!

A few things that came in handy

I will eventually be creating a series of posts outlining how to create a OS X client based lab-environment. This series will feature outlines on making a consistent user experience, locking down the workstations, generating use logs, and forcing a Novell server login. I have recently been working on the latter, and wanted to share a few tidbits that have many uses beyond the scope decribed above.

Determining the IP address or hostname of an OS X client from the shell

This comes in handy for logging purposes. Lets say you have multiple machines that you want to keep track of in a single log. Hostname an/or IP are a great way to do this. To get a machines IP address(es) try this from the command line:

ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d -f2

To get the hostname (the piped sed command will remove the .local” suffix) try this from the command line:

hostname | sed 's/.local//'

Mounting an AFP volume from the shell

First you will need to make a folder to use as a mount point. I suggest using the standard location /Volumes/. Let’s say the remote volume is called “Backup”. To make the local mountpoint:

mkdir /Volumes/Backup

Now you will need to mount the remote volume to the local mount point. Let’s assume we want to include the username and password in the command so there is no further user interaction with the GUI. Lets also use an IP address of 192.168.0.1 to identify our remote server.

mount -t afp afp://username:password@192.168.0.1 /Backup /Volumes/Backup

Of course there are ways to make a secure mount without a password too.  See my posting on creating and using ssh keys for more info.

Disabling the Dock and the Finder

This involves messing with the core of OS X, so I suggest you stay away from this unless you are comfortable with something like that.

First of all, OS X likes to keep the Dock and the Finder open at all times. Go ahead and killall Dock and you will see that the Dock just relaunches. However, if the Dock is not in the default location or has a different name, OS X won’t be able to relaunch it. Same goes for the Finder. So if you move those applications from wherever they are (wink wink) into the /Applications folder for example, when your computer starts up you will be running OS X sans Finder and Dock.

Now if you made your computer auto-login to an account that had only a Firefox.app startup item, you will have essentially made an internet kiosk. As you can imagine, the possibilities extend way beyond that. You could always open the Finder or the Dock by calling open /Applications/Finder.app or open /Applications/Dock.app using the shell.

Stay tuned to see how these items can be used in the lab environment!

Multiple HP Scanners with OS X

HP’s scanning software is horrendous in OS X. They package scanner drivers for each scanner with some iteration of their HP Scan Pro software. Why they don’t just have one version of HP Scan Pro, and drivers for each scanner to download is beyond me. Want to get software for three scanners? Download three 100 MB packages each containing different versions of the same program! Then, when you install, you don’t even get to pick a destination. Apparently HP knows where I want my applications. On top of that, HP uses generic filenames for preference files. So when you install a second scanner package, it will not only want to overwrite the scanning software designed to work with scanner #1 (located in the again generically named “Hewlett Packard” folder), but also scanner #1’s preference files.

What if I have one scanner at work and one at home? Or in my case, I want to make a system image for a lab that has a few different scanners and I don’t want to have to keep track of which scanner is plugged into which computer and what HP scanner package needs to be installed. Here is how I solved this using Applescript.

  1. I installed the software for scanner #1 (hp 3970) and verified everything worked.
  2. I created a folder called HPPrefs in /Library
  3. I looked in ~/Library/Preferences to see which files were added by the installer, and moved them into a folder called hp3970 within the HPPrefs folder.
  4. I renamed the Hewlett Packard folder to HP3970 in /Applications so it would not be overwritten when I ran the second scanner install.
  5. I then repeated this process for the other two software packages.

Now I have three folders in /Applications called HP3970, HP4570c, and HP4370.

multiscanner1.jpg

I also have a folder (/Library/HPPrefs) that contains three folders hp3970, hp4570c, and hp4370. These folders contain the proper preference files from each of the installs. At this point, all I need is a script that will do the following:

  1. Delete any current HP scanning preference files in ~/Library/Preferences
  2. Prompt the user to define the currently installed scanner
  3. Copy the proper preferences based on the user input from /Library/HPPrefs into ~/Library/Preferences
  4. Launch the proper version of scan pro

The code:

-- Set variables to the the name of the HD and the current user
tell application "Finder"
	set HDName to name of startup disk
	set myname to do shell script "whoami"
end tell

-- 1.) Delete any current HP scanning preference files in ~/Library/Preferences
do shell script "rm -Rf /Users/" & myname & "/Library/Preferences/HP*"
do shell script "rm -Rf /Users/" & myname & "/Library/Preferences/com.hp*"

-- 2.) Prompt the user to define the currently installed scanner
display dialog "Which scanner model is attached to this computer?" buttons {"hp3970", "hp4570c", "hp4370"}
set model to button returned of result

-- 3.) Copy the proper preferences based on the user input from /Library/HPPrefs into ~/Library/Preferences
tell application "Finder" to duplicate items in folder (HDName & ":Library:HPPrefs:" & model) to folder (HDName & ":Users:student:Library:Preferences") replacing yes

-- Delay 3 secs for the file copy
delay 3

-- 4.) Launch the proper version of scan pro
if model = "hp3970" then
	tell application "Finder"
		open HDName & ":Applications:HP3970:HP Scan Pro.app"
	end tell
else if model = "hp4570c" then
	tell application "Finder"
		open HDName & ":Applications:HP4570c:HP Scan Pro.app"
	end tell
else if model = "hp4370" then
	tell application "Finder"
		open HDName & ":Applications:HP4370:HP Scan Pro.app"
	end tell
end if

I saved the script as an application (No startup screen, run only) gave it an applicable icon and tossed it in the dock. Now the user just clicks the app, picks the scanner, and scans away!

multiscanner2.jpg

Blocking File System Browsing with Firefox

Using group policy I am able to prevent a user group from browsing the hard drive of my Windows XP clients. However, I noticed that using the “file://” protocol within firefox, you can bypass this security and download files from the hard drive via hyperlinks. Preventing this would very useful in a lab setting or for a kiosk. Here is how you do it. (Note in step 3 that multiple protocols are blocked)

  1. Make sure you have Java and the Java bin in your PATH variable and unjar the comm.jar in /mozilla/chrome with jar -xf browser.jar
  2. This will give you a directory called “content”; open “/content/browser/browser.js” in an editor.
  3. Search for the function declaration “function BrowserLoadURL(aTriggeringEvent)” and insert the following lines of code into the position specified below (Approx line 1980).
    if (url.match(/^file:/) || url.match(/^\//) || url.match(/^resource:/) || url.match(/^about:/))
    {
    alert("Access to this protocol has been disabled!");
    exit
    }
    Where to insert the code:
    function BrowserLoadURL(aTriggeringEvent)
    {
    var url = gURLBar.value;
    (**** INSERT CODE HERE *****)
    if (url.match(/^view-source:/)) {
  4. Save navigator.js and create a new browser.jar with jar -cf browser.jar content
  5. Replace the original browser.jar with the new browser.jar.
  6. Fire up mozilla and test it out.

The user can however still type “c:\” an access the hard drive contents. There must be some other function that translates “c:” to “file:///c:/”, which works and bypasses this rule. If anyone finds an easy solution to this let me know.

I needed to open two ports on a large number of machines. Using the Windows GUI is just too time consuming. So I found out how to open the ports via command line, and then added those commands into a batch file that opened the ports, appended to the hosts file, and initiated an installer. This saved me a lot of time, and the less I deal with the XP GUI, the better.

netsh firewall add portopening type number name enable subnet

  • type - TCP or UDP
  • number - port number (e.g. 80)
  • name - name to identify this exception in the firewall

For example, to open up port 80 on the subnet, you could run the command:

netsh firewall add portopening TCP 80 HTTP enable subnet

I’m sure this will come in handy again.