MQP3 Dabbling in all things tech

30Mar/10Off

Batch File Scripting

I was messing around with the Windows Shell (aka cmd), which I do quite frequently, and I found out/remembered a few helpful hints that might make your batch scripting easier.  Note that this is just regular old command line, not PowerShell.

Initializing a cmd window

First, opening cmd can be pretty easy.  Running a single command is easy too, think ipconfig.  Combining both is only "difficult" if you want to have the window stay open when it's finished running the command.  I used to execute "ipconfig /all" from the run dialogue box only to have the little black window flash before my eyes before I could read any of the text.  After using a little bit of Google-fu I learned that "cmd /k ipconfig" will run cmd, run ipconfig and "/keep" the window open, at least that's what I'll pretend /k stands for.

tl;dr- How to keep the window open and run a command AT THE SAME TIME!:

cmd /k command

As a bonus, an easy way to run a cmd window as an administrator (on Vista/7) is hit the Windows key, type "cmd" then ctrl+shift+enter and the UAC should prompt you to confirm running as an administrator.

Environment Variables

I love Environment Variables in batch files because they are easily declared and easy to use.  Most likely you will use them through the "set" command, like so:

Declare and initialize a variable:

set varName=43

Declare and initialize to a value entered by the user, brackets not required:

set /p varName=[String to Display at the Prompt]

To display the variable or use it in a command simply type the variable name surrounded by %'s:

echo %varName%
del /q /f %varName%

There are a lot of built in variables that can be used to find out information about the computer you are using, to see some of them and their variables simply enter "set" and hit return.

Some of the most common ones that I use are %username%, %computername%, %date%, %time%.  They are especially useful for logfiles and the like.  Since most of my batch files are related to logging something, those variables are the best to recognize who is running the command, on what computer and when.

Sometimes you don't need the entire variable, that is where the ~ key comes in.  For a real world example, I needed to store the current drive in a filename as part of the logfiles name (because all the logfiles were being stored in the same place on the same directory).  If you view the %cd% variable it will look something like this:

C:\Users\Administrator\Desktop

As you all know : and \ can not be in a filename on windows, so it would be helpful if we could grab just a few characters from the beginning of the %cd% variable. %username:~0,5% will only display the 0th to the 5th characters of the %username% variable, or if you just wanted the current drive letter,

%cd:~0,1%

or to get the root of the system drive (where windows is installed):

%systemDrive:~0,1%

Directory Stacks

A directory stack works much like a computer stack does, meaning first of all it operates on a First In Last Out (FILO) or Last In First Out (LIFO) basis.  Directory stacks are very helpful if you need to perform a bunch of operations in many different directories.

The way Windows works is that when you run the "pushd" command it pushes the current directory into the directory stack, then cd's to the directory you set as the parameter.  The way to get back to the previous directories is to run the command "popd".

For an example, I want to run the dir command in a few different directories and then return to the original directory:

C:\Windows>pushd D:\Archive
D:\Archive>dir
D:\Archive>pushd C:\Games
C:\Games>dir
C:\Games>pushd P:\Movies
P:\Movies>dir
P:\Movies>popd
C:\Games>popd
D:\Archive>popd
C:\Windows>_

Jumping around different drives and different directories and running the dir command probably is not all that useful, but having a stack with previous directories in it certainly is.

That's it for now.

Filed under: Tech No Comments
26Mar/10Off

Wireshark Winner

I have officially been entered in to the Wireshark hall of fame.

Okay, maybe not.  But, for the first time in a non-scholastic environment, I used Wireshark to solve a real-life problem.

I was at home, trying to get my MacBook connected to my Win7 Pro "Server" machine, and stream a movie file located on a share.  I do this streaming several times a week, and always have problems.

On a (somewhat) side note, I am pretty sure that Apple is against Windows shares because they NEVER show up in the Network locations place.

Network Empty

Network Empty

This screenshot is taken on a network with a NAS with a samba share and two Windows 7 machines, both with shares available and open.  I can sit and wait for the refresh period build into Samba and it never shows up.  I hate networking with Windows on this MacBook.  I can CMD+K in Finder and smb://serverName/ and it'll open right up, but the servers never show up in the Network for some odd reason that I have yet to discover.  Suggestions welcome.

Back on topic, I was CMD+K'ing with my Win7 boxes name and every time I would try to connect it would throw and error.  I started cursing Steve Jobs name because he just hates Windows.  Cue Wireshark.

For help with the picture, dent.local is the name of my MacBook and 192.168.1.15 is the IP of my Win7 pro box.

I set a filter so I could see all traffic between me and the Win7 guy, so I could find out what is happening.  After a little (17.1k packets) while of capturing I found the gem I was looking for- an Error!

Wireshark Capture

Wireshark Capture

Sorry for those with small resolutions, that lightbox is going to fill your screen!

I found the problem, looked for a solution and ended up just restarting the Win7 box in order to connect to it.  It wasn't out of RAM, I could connect to it with other Windows boxes, but OS X just couldn't do it.  Strange behavior.  Thank goodness restarting always fixes even the worst of problems.

Filed under: Daily No Comments
25Mar/10Off

Google Wave Invites

I have lots of Google Wave invites. Lots.

I understand there is a small privacy flaw in this distribution method, but I don't want them any more.

First come, first served.

https://wave.google.com/wave/invite?a=pre&wtok=79e43704a0723898&wsig=ABk8uhRheYEpyCTgggVkNUxivO41U3UJ0w
https://wave.google.com/wave/invite?a=pre&wtok=522da1578d51a4bb&wsig=ABk8uhQTnIAdEg-PFJA3Hmt8jvcYQJtkWw
https://wave.google.com/wave/invite?a=pre&wtok=b047497d2ed6c20f&wsig=ABk8uhRidipG5hZYJ3eqsCxWk-OeRAfNSQ
https://wave.google.com/wave/invite?a=pre&wtok=f3c9b398654e8a8c&wsig=ABk8uhTDT7M5m309VAiuBNGTewf5sFdWmQ
https://wave.google.com/wave/invite?a=pre&wtok=bbd20b49a42c437e&wsig=ABk8uhT2-KUd7cGffh7-4e8bkbp0Ieuk9A
https://wave.google.com/wave/invite?a=pre&wtok=1522c218754e63cf&wsig=ABk8uhQ8T_dleSXY7wfgBNcaULaSroRSzg
https://wave.google.com/wave/invite?a=pre&wtok=12510db5648c214e&wsig=ABk8uhTY1ygGA5H8yPzKEliKgCtPmpjbYw
https://wave.google.com/wave/invite?a=pre&wtok=49b877b9e78e4623&wsig=ABk8uhQkzXrJoRjRPWeWofQ5RK7tmVijgQ
https://wave.google.com/wave/invite?a=pre&wtok=4e0c12ef6d147e39&wsig=ABk8uhSueMtNmYQ74MQboqAOiIgIHjzPxg
https://wave.google.com/wave/invite?a=pre&wtok=07a410bfb426cbe1&wsig=ABk8uhRVkFP7jZp2VnFf5aAAFJXx2QFaCg
https://wave.google.com/wave/invite?a=pre&wtok=1358ea488c26c54c&wsig=ABk8uhSFshODCfnYCHBrpDDnGQ6H3kuw0g
https://wave.google.com/wave/invite?a=pre&wtok=b54c48a5b4c524a3&wsig=ABk8uhRxn48jXAJHxYC0ZG5s2wVjiB50EA
https://wave.google.com/wave/invite?a=pre&wtok=31cc79f23541d090&wsig=ABk8uhRw3EophNc9WB7kHOZTpPTTX0B-ZQ
https://wave.google.com/wave/invite?a=pre&wtok=76840734fd3c8c4c&wsig=ABk8uhSgTbZRxpah_yTXF9AyN4UCHNoalQ
https://wave.google.com/wave/invite?a=pre&wtok=4a1b020c7662f754&wsig=ABk8uhRS_KDJDBw2hYuuc5vz4vXcGR0fcw
https://wave.google.com/wave/invite?a=pre&wtok=2556c69069724b96&wsig=ABk8uhRJHUtWZO7jxVrdPNfYxnGQfLnw2A
https://wave.google.com/wave/invite?a=pre&wtok=4e9c59443fe7f3a5&wsig=ABk8uhSDAQ6oOvnqfAujyN9FL39losndYQ
Filed under: Daily, Tech No Comments
18Mar/10Off

Google Alphabet

Apparently Google almost owns the world.  I am a pretty big fan of Google and like/use almost everything that they create.  In honor of our new technical overlords, I have made non-exhaustive list of what I'll call the Google Alphabet.  I realize some letters are missing, but that doesn't mean they don't have a service that starts with the letter.. I just could not find one.  Also recognize that many of the letters have multiple products that fall under that letter.  I chose whatever one I wanted to.  I hope you can find something new that Google offers, find it useful, then use it.  My top six: Voice, Reader, Chrome, Docs, Gmail and Picasa

Alerts, Books, Chrome, Docs, Earth, Finance, Groups, Health, Images, jQuery, Knol, Latitude, Maps, News, OS, Picasa, in Quotes, Reader, SketchUp, Talk, URL shortener, Voice, Wave, X, YouTube

Filed under: Opinion, Tech No Comments