Archive for February, 2009

Windows domain-wide setting of Environment Variables at Logon

Wednesday, February 25th, 2009

This post succinctly sums up significant research that I did over the last few days on the available means of setting environment variables for a Windows Domain Group of users at logon time. A Java Swing-based desktop application I’m helping a client with reads environment variables for its connectivity settings (server IP, etc.), so, it is logical that there needs to be a way to distribute these environment variables all all users from the Domain Controller. Below are the results of that research.

Oh, and be sure to hop over to this question at StackOverflow.com and add your own unique knowledge to the mix.

My research says there are four ways to do this. I started at the Microsoft Logon Script documentation pages and fanned out from there.

Login Script Batch File

Windows Server 2000, 2003, 2008

Login batch file (.BAT) scripts are just a temporary instance of a CMD window, and the environment variables set in there go away as soon as the login window closes.

set MYVAR=MyValue

Won’t work for the aforementioned reason.

So, alternatively, I can try to set the variable via directly writing to the registry like so for a System Environment Variable:

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v MYVAR /t REG_EXPAND_SZ /d MyValue

or to the User Environment Variables like so:

reg add HKCU\Environment /v MYVAR /t REG_EXPAND_SZ /d MyValue

The drawback here is that the variables, though written to registry, are not read until the next login for all I can see. A new CMD window shows no trace of them until the user re-logs-in.

Login Script WSH VBS File

Windows Server 2000, 2003, 2008

With a Visual Basic Script (VBS) login script, you can use a more programmatic method to access the environment variables. This is looking like my most viable approach. This example would append to the end of PATH.

Set WSHShell = WScript.CreateObject("WScript.Shell")Set WshEnv = WshShell.Environment("SYSTEM")WshEnv("Path") = WshEnv("Path") & ";M:\DB\whatever\"

This example would just set the variable.

Set WSHShell = WScript.CreateObject("WScript.Shell")Set WshEnv = WshShell.Environment("SYSTEM")WshEnv("MYVAR") = "MyNewValue"

This approach yields variables that are immediately available via a CMD window. No reboot is required like the batch file registry writes.

ADM File

Windows Server 2000, 2003, 2008

ADM files are a way to expose custom functionality of settings to the Group Policy Editor. It seems tricky to get them installed and visible on the domain controller so I’m jumping over this option.

Microsoft Support TechNet Reference on ADM File Locations.
Another article about ADM files and using them to set Registry settings.
Tom’s Hardware on ADM Files.

---- set.adm ---- CLASS MACHINE CATEGORY "Environment" POLICY "Self dfined variables" KEYNAME "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" PART "Set MyVar1 =" EDITTEXT DEFAULT "MyValue1" VALUENAME MyVar1 ; EXPANDABLETEXT ; add expandabletext if it can contain Variables itself END PART END POLICY END CATEGORY ---- set.adm ----

Group Policy Preferences (GPP)

Windows Server 2008

Windows Server 2008 has a new feature called the Environment Extensions for the Group Policy Preferences. It allows you to conveniently set what otherwise required complex batch scripts. The new items exposed include registry values, environment variables, and more. A quick how-to guide is available here.

I can’t use this option because my clients don’t have Windows Server 2008.

Using the Maven Command Line Interface Plugin

Thursday, February 19th, 2009

Maven 1.0 users were spoiled with the console plugin, and now Maven 2.0 users can get a nearly equivalent experience with a high-performance bootstrapped prompt via the Command Line Interface plugin. Watch this quick screencast for a tour of using this plugin and start saving even more time with Maven.

Git Cleanup Screencast

Thursday, February 19th, 2009

Are you a new user of Git? Here’s some basic help with cleaning up your Git working directories & files. This quick screencast shows you the basics of how Git enables you to ignore files that you never want to track, purge files that are untracked while leaving your tracked files intact, and lastly, roll back all your changes to tracked files to the last-known-good state.

iTerm Screencast

Tuesday, February 17th, 2009

I’m a big fan of iTerm as a replacement for Terminal.app for developers. It offers a host of productivity boosts. To name a few:

  1. Named tabs
  2. Favorite location bookmarks
  3. Window, font, and background colors per-bookmark
  4. Transparency levels and blur of the underlying windows
  5. Middle click copy and paste
  6. URL launching from any URL recognized text

I’ve put together a quick screencast to show off a number of these features and how to configure them.



iTerm Developer Tips from Matthew McCullough on Vimeo.

RESTful Java Web Services must not return void to iPhone HTTP Services

Tuesday, February 17th, 2009

After many sessions of debugging and even memory inspection not yielding fruit, I’ve finally discovered what caused my previous RESTful demo apps to have sporadic behavior, in addition to the memory leak of the synchronous call.

Today’s problem solving summary:

  1. XCode projects cannot have commas anywhere in the path up to the location where they are stored or else you’ll get an error message of:
    ld: -filelist file not found: <Project Path>
  2. All RESTful web services called via the NSURLConnection APIs must return a non-null payload.

    This bit me because my “Add Contestant” function was adding the contestant and returning void. I now return a string of “Success” to satisfy this requirement. The observable failure is very quiet, which made it so hard to debug; every other web service call appears valid, but never actually makes a call across the wire. This was proven via TCPDump. All the web service call callbacks are properly called in the Objective C side of the program. It just silently failed and passed back a null payload in the response data structure.

All the code for this project is available on GitHub and will be updated with the results of the adjustments based on the above findings by tomorrow.

iPhone & Java Web Services Development, Mind Map Image

Saturday, February 14th, 2009

I’m working on some updated course materials for iPhone & Java Web Services training and, by popular demand, am putting up the Mind Map I created as the master reference for the courseware. The graphic is open source for the community to leverage and benefit from. Have fun with your iPhone exploring of some new topics you might see on this Mind Map, and let me know in the comments the parts that interest you the most…

Also, here’s a link to my iPhone tagged Delicious bookmarks.

iPhone Development MindMap

Creative Commons License
iPhone Development Mind Map by Matthew J. McCullough is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

Clean your Git up to Pull successfully

Saturday, February 14th, 2009

Here’s a quick Git pulling & merging tip for those of you learning this awesome Distributed Version Control System.

Git Pull’s Double Duty

As you may be aware, the git pull command actually does two things under the covers. It does a git fetch to freshen your tracked remote branch and it does a git merge to merge it into the linked local branch. Sometimes this can go awry if you’ve been experimenting with files locally and forgot to return them to a checked-in state. Git errors out nicely, saying “I don’t know what you want me to do, but I’m going to be cautious here and just let you tell me exactly how to handle this.”

Error Message

One of the possible error messages you’ll see is:

error: Entry 'myapp/src/main/resources/scripts/launchapp.bat' not uptodate

Solutions

If your local changes are unimportant to you and you just want to get back in alignment with the remote branch, you have two options to apply depending on the state of your local files. First, you can reset any tracked files to their last committed state via the following command. This discards any local changes to any tracked files.

git reset --hard

Second, you can discard any untracked local files via the git clean command, in the case that they are colliding with files that the remote branch has actually added and is now tracking. You can purge your repository’s current branch of untracked local files by typing:

git clean -f

And in case you are paranoid about what this will remove, you can get a safe preview of what it would do by typing:

git clean -n

Which outputs a preview list like so:

[~/Documents/Code/myproj.git]: git clean -n
Would remove morecruft.java
Would remove unwatedfile.txt

Bespin, the Mozilla Web Based Editor

Thursday, February 12th, 2009

200902122259.jpg Mozilla has just released a web based programmer’s editor that runs entirely in your browser. It is aptly named Bespin, because it runs entirely in the cloud. Skeptics beware, this has the potential to blow your mind. A quick review of the screencast shows of the power and possibilities that a web based editor is strategically poised to execute. Collaborative editing. Collaborative code review. Plugins. Borrowing someone else’s setup of plugins. A developer’s mind quickly pants with excitement for this to move from alpha to beta as soon as possible. Go Dion!

iPhone SDK Memory Leak Acknowledged

Thursday, February 5th, 2009

I was pleased to see an email sitting in my inbox this morning from Apple replying to the memory leak of the iPhone SDK around the sendSynchronousRequest call. However, the body was a bit disappointing. Paraphrased:

Hello Matthew,

This is a follow up to Bug ID# 6503844. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 6548496.

Thank you for submitting this bug report. We truly appreciate your assistance in helping us discover and isolate bugs.

The part that is odd is that the “Original Bug ID” is a larger number than mine. I was pretty sure that the bug IDs were sequential. Perhaps not.

This particular call appears to have been leaking since I first jumped on board iPhone SDK development over a year ago. Let’s hope it becomes a priority in a soon-upcoming release of the software and SDK.

Still, on the whole, development on the iPhone is awesome, and if you are in Minneapolis, Seattle, or Denver, I’d be pleased to have you in the audience at the NFJS talks.