Tuesday, September 29, 2009

Microsoft Security Essentials

Woo! Hoo! It's available!

I have been waiting for this for some time. At last Microsoft has released a free antivirus! You can go and pick it up now at:  http://www.microsoft.com/security_essentials/

I've heard good things from the Beta; like it is supposed to be really light weight and it is supposed to be easy to use and unobtrusive. I'm uninstalling AVG right now and I'm installing Microsoft Security Essentials. Let's see how it goes!

Monday, September 28, 2009

RoboCopy

So you have a huge number of files that you want to copy from one place and put them somewhere else. Perhaps you have updated some of the files and want to make sure the changes are copied but you don't remember which files were changed.

The easiest way to do this would be to drag and drop the folders to merge them but if you have done this before you probably know that this is likely to take long enough that you wonder if there might be a better way.

Fortunately for those using Windows Server 2008, Vista or Windows 7 there is. Robocopy to the rescue! For Windows XP and Server 2003 you can get it via a download from Microsoft.

For this purpose robocopy has some advantages over it's predecessors copy and xcopy and it's alternate bitsadmin in that it copies folders, it has the ability to check to see if a file needs to be copied before copying and it is relatively easy to use.

In my example I will take clipart stored on c:\ and copy it to z:\ I want to log the results and I don't want to copy the thumbnail database so here is my command line.

Set Source=c:\Images\Clipart
Set Dest=z:\Images\Clipart
Set LogFile=ClipartCopyLog.txt
Set SkipFile=Thumbs.db

robocopy "%Source%" "%Dest%" /E /LOG:%LogFile% /TEE /V /FP /XF %SkipFile%

The /E switch tells robocopy to copy empty folders. /LOG is the switch which tells where to write a log to. /TEE logs the results both the the log and displays in the console window. /V presents verbose output which is good for debugging but not needed to run. /FP is also for logging instructing to use full path names. /XF is what allows Thumbs .db to be skipped in the file copy. For more information type robocopy /? in an open command window.

The biggest advantage by far is that if the file already exists and is up to date then it won't try to copy the file which speeds things up quite a bit when merging folders.

Thursday, September 17, 2009

Office Web

Writers Reference Encyclopedia.docx - Microsoft Word Live (preview program) - Windows Internet Explorer

Whoot! From the tiny Thumbnail you might not be able to tell exactly what the screen shot is of, but it's something I'm excided about.

I opened up my SkyDrive today and found I had been accepted to the Office Web Apps Technical Preview.  Which means I get to be one of the first to be able to view Word Docs, view and edit Excel spreadsheets all in side of SkyDrive  in the browser.

Writers Reference Encyclopedia.docx - Microsoft Word Live (preview program) - Windows Internet Explorer

The one thing which has really surprised me so far, is that it could actually handle opening my almost a ream of paper document!! I'm impressed. It is limited though, I tried a few of my crazier spread sheets which wouldn't open online. It isn't designed to replace Office in any right anyway but is a nice offering so far.

Thursday, September 10, 2009

Filtering the Path

This is a little project I have been trying to figure out ever since I read a line in the help for the "For" command:

%~$PATH:I   - searches the directories listed in the PATH
               environment variable and expands %I to the
               fully qualified name of the first one found.
               If the environment variable name is not
               defined or the file is not found by the
               search, then this modifier expands to the
               empty string

Running multiple scripts that continually add to the path list can muck up the path list. I hoped I could design a function that searches to find out if a path exists in the path list and if it does it wont add the new one.

@Echo Off

PATH=C:\WINNT\system32\;C:\WINNT\;C:\Program Files\Test1\

    Call :AddToPath "C:\Program Files\Test1\"
    Call :AddToPath "C:\Program Files\Test2\LICENSE.txt"
    Call :AddToPath "C:\Program Files\Test3\"
    Call :AddToPath "C:\Program Files\Test4"

    Echo %Path%

GoTo :EOF

:AddToPath
    If Not ""=="%~x1" Call :SetToPath "%~dp1"
    If "%~1"=="%~dp1" Call :SetToPath "%~1"
    If "%~nx1"=="%~n1" If Not ""=="%~nx1" Call :SetToPath "%~1\"
GoTo :EOF

:SetToPath
    Set t=%path%
    @Rem Deleting the path if it exists
    Call Set t=%%t:%~1=%%
    If "%path%"=="%t%" Path %Path%;%~1
GoTo :EOF

This is as far I have been able to get the script. For the most part it works except if the new path is already part of the path of another path in the path list. There may be better ways to implement this.

One thing to note is that it is best that the path being added has already been created. Sometimes splitting out the different parts doesn't work if it doesn't exist.

Wednesday, September 9, 2009

32 Bit on 64 Bit Program Files

When 32 bit programs install on a 64 bit Windows they are dumps %ProgramFiles% into %ProgramFiles(x86)% and the default command line in 64 bit Windows is the one that is 64 bit which directs %ProgramFiles% to %ProgramFiles%. So if you want to access a 32 bit program you have to use %ProgramFiles(x86)%. This can really complicate matters if you need to access the same program on both 32 bit and 64 bit Windows. So what can you do? Try this:

@Echo Off

Set Programs=%ProgramFiles%

If "%PROCESSOR_ARCHITECTURE%" == "x86" Set Programs=%ProgramFiles%
If "%PROCESSOR_ARCHITECTURE%" == "AMD64" Set Programs=%ProgramFiles(x86)%
If "%PROCESSOR_ARCHITECTURE%" == "IA64" Set Programs=%ProgramFiles(x86)%

CD /d %Programs%

This method is extensible so that you can add any additional operating system processor types as they become available and it allows you to select the correct path for each one.

One little fun note is in the dummy CD call I'm using /d which changes the current drive as well as changing the directory for the drive. Fun!

Tuesday, September 8, 2009

Popups

Dear Netflix, University of Phoenix, and others who blatantly continue to use the blight of popup advertizing,

I wanted to let you know that I will personally continue to abstain from use of your services so long as you continue to use popup advertizing.

Thank you.

~____

Wednesday, September 2, 2009

Rebooting a Remote Machine

It is quite common for me at work to be remoting into a computer working on it and realize I need to reboot it for one reason or another only the machine I'm remoting into is a client OS (Windows XP, Windows Vista, Windows 7) that has the reboot icon removed from the start menu in the remote desktop window.

If the machine is under my desk I can just switch over to it to reboot or hard reboot with the button on the front but sometimes the machine is in another room in another building in another city in another state or another country. Then I have no access to the physical machine.

On occasion if I'm using a Lab machine they will have some interface that I can use to reboot but not always. So what do you do?

It's actually quite simple, open up an elevated command window and run the following command:

Shutdown /r /t 0

The flag to restart is /r, then the flag /t plus a number sets the time delay before the command restarts the machine, a value of "0" reboots immediately.

For more information on this command run "Shutdown /?" from a command prompt.

The Geeky Workplace

One of the cool things about working at Microsoft is just how geeky people are. You can be in a meeting and there might be one or two people who follow sports (strangely it is possible they would be mostly women) and one of them would say something like how about that game last night and most of the people in the room would look at them confused thinking of World of Warcraft or some other sort of video game rather than a ball game.

Oh so much fun.

Tuesday, September 1, 2009

Get a File's Date and Time

Have you ever come across the need to log the date and time a file was created only to discover dir doesn't do it?

I did. I spent a couple of days frustratingly trying to find a way to capture the information with little luck. Finally I found documentation in the call command that explained that "%~t1"  expands %1 to date/time of file. This gave me enough information that I could come up with the following script:

@Echo Off

    Call :FileTimeDateSize "MyDate" "MyTime" "MySize" "%WinDir%\notepad.exe"
    @Echo:%MyDate%
    @Echo:%MyTime%
    @Echo:%MySize%

GoTo :EOF

:FileTimeDateSize
    Call :AsignDateTimeSize "%~1" "%~2" "%~3" %~t4 "%~z4"
GoTo :EOF

:AssignDateTimeSize
    Set %~1=%~4 & Set %~2=%~5 %~6 & Set %~3=%~7 bytes
GoTo :EOF

I was able to extract the date and time using "%~t3" but I wanted the date separated from the time so I wrote the second function to split out the date and the time by feeding "%~t3 to the function :AsignDateTime without quotes so that it will be split out into three tokens which are assigned independently to the desired variables to be used later.

If you run the script you can see that it is working because the date Notepad was built appears on one line and then the time on the next. I have also expanded this so that it reports the file size as well.

Now all I have to do to log the date and time so I can parse it later is @Echo:%MyDate%,%MyTime%,%MySize%>>LogFile.log