Repetitive tasks – the easy way..

Now this fall under the category, easy solutions to complex problems…

I recently had to remove about 150 computer objects from a MOM 2005 console, it was not possible to select all and choose remove so you had to right click each and every one of them – click “remove” and then answer “Yes” to the “Are you sure….” dialog…  Now imagine how long this would take to do manually!?  Well you could probably do some scripting that would solve the problem – however that would require some research to find, test and then implement..  but then it struck me, a flashback from back in Windows 3.1 where you had a macro recorder, this macro recorder would allow you to record keyboard and mouse actions and then play it back as many times as you would like (I remember making a macro sending emails and thus spamming some of my fellow students, great fun at the time), now someone must have made a freeware tool that will do this under modern versions of Windows, and sure enough – “Do it again” to the rescue…  “Do it Again” will allow you to make macros and play them back as many times as you’d like, it’s free and easy to use..

1. Get the util from here; http://www.spacetornado.com/DoItAgain/

2. Install it

3. Start “Do it again” and click “create new task” and perform the task you want repeated.

4. Press “Scroll lock” (the button) once you are done with your task.

5. Name the macro in “Do it again” (a dialog box will pop up).

6. Under options set the number of times you want the task to repeat

7. Double click the macro you just created

8. Sit back in amazement and watch someone else making all the hard work for you, now it will still take time but you can sit back and drink coffee while it does.. NICE..  a simple solution to a time consuming problem…

UPDATE;
Sadly I found out this does NOT work on Vista/Win7 🙁 – bummer, however I guess there will be some other util out there that will…

UPDATE2;
I just found a util  “Windows Macro Recorder” that claims to work on all windows versions, same concept as the above;
http://www.freelabs.info/MacroRecorder.aspx

How to Enable, Disable and Maintain LCS (Live Communications Server) User Attributes using VBScript

Just a quick link if you ever need to implement Microsoft Live Communications Server, here is a script that can assist you in modifying your AD users.

http://www.activedir.org/Articles/tabid/54/articleType/ArticleView/articleId/15/Default.aspx

Delete files older than XX days

Do you have a temporary directory on your pc/server, you know one of those places where you put stuff to look at later but always forget to delete again?  It is likely that your answer is yes, but the more important question ought to be how do I automate cleanup of this directory?

There are numerous ways to do this, but I’ll just give you one here – google the rest if you are not satisfied..

It’s actually not as hard as it sound, you need to download a utility called “forfiles.exe” (put  it in c:\windows\system32 or similar) and then create a script much like this (here I presume the directory to cleanup is C:\tempdata);

rem Delete files on the server older than 14 days.
forfiles -p c:\tempdata-s -d -14 -c "cmd /c del /Q /F ""@FILE"""
or
rem Delete files older than 90 days
forfiles -p c:\tempdata-s -d -90 -c "cmd /c del /Q /F ""@FILE"""

And that is about it 🙂

Windows Update – script it

So you need to fiddle a bit with Windows Update, the reasons can be many;

  1. you want to centrally initiate an update
  2. you are paranoid and want to script a daily/weekly or monthly Windows Update (in case the automatic detection fail).

Well, for help on how to launch it on different remote machines I suggest you visit Dave’s Blog;
http://skatterbrainz.blogspot.com/2009/01/script-code-batch-running-wuauclt.html

A Desktop shortcut;
You could also simply create a desktop shortcut linking to

wuauclt.exe /resetauthorization /detectnow

This would force a Windows Updates detection to run upon clicking the shortcut, somewhat easier than launching the website.

The script you would need locally could look something like this;

@Echo off
Echo Stopping Windows Update Service
net stop wuauserv
Echo Starting Windows Update Service
net start wuauserv
Echo Forcing Windows Update detection
%windir%system32wuauclt.exe /detectnow

I also stumbled across some neat commands to try in case you are debugging Windows Update (update not working);
http://www.techsupportforum.com/microsoft-support/windows-xp-support/279270-automatic-update-not-started-error-1058-a.html

net stop wuauserv 
del /f /s /q %windir%SoftwareDistribution*.*
net start wuauserv 
wuauclt.exe /detectnow
_____________________

net stop bits 
net stop wuauserv 
%windir%system32
egsvr32.exe /s %windir%system32atl.dll 
%windir%system32
egsvr32.exe /s %windir%system32jscript.dll 
%windir%system32
egsvr32.exe /s %windir%system32msxml3.dll 
%windir%system32
egsvr32.exe /s %windir%system32softpub.dll 
%windir%system32
egsvr32.exe /s %windir%system32wuapi.dll 
%windir%system32
egsvr32.exe /s %windir%system32wuaueng.dll 
%windir%system32
egsvr32.exe /s %windir%system32wuaueng1.dll 
%windir%system32
egsvr32.exe /s %windir%system32wucltui.dll 
%windir%system32
egsvr32.exe /s %windir%system32wups.dll 
%windir%system32
egsvr32.exe /s %windir%system32wuweb.dll 
net start bits 
net start wuauserv 
wuauclt /resetauthorization /detectnow
_____________________________

net stop bits 
net stop wuauserv 
regsvr32 /u wuaueng.dll /s
del /f /s /q %windir%SoftwareDistribution*.*
del /f /s /q %windir%windowsupdate.log
regsvr32 wuaueng.dll /s
net start bits
net start wuauserv
wuauclt.exe /resetauthorization /detectnow

PPS. Vista/Win2008 users beware.
Stopping services etc under windows vista/2008/7  require the scripts to be run as an administrator.

Delete files older than data using a batch file

Forfiles -p c:ackup -s -m *.* -d -5 -c “cmd /c del /q @path”

This will delete all files in my backup directory older than 5 days. To test it first, use this:

Forfiles -p c:ackup -s -m *.* -d -5 -c “Cmd /C Echo 0x22@Path@File0x22”

Workarounds for XP users might be;
http://windowsitpro.com/article/articleid/71600/jsi-tip-0274—delete-files-older-than-xx-days.html (but this require additional software to be ‘installed’).

Hmm the below seem to be some unix variant, but maybe something similar is possible in Windows.

http://lifehacker.com/software/command-line/cli-fun–delete-files-older-than-x-days-239124.php (seem cool)
find /path/to/files* -mtime +5 -exec rm {} ;
http://lifehacker.com/software/geek-to-live/geek-to-live-hard-drive-janitor-133190.php (the deluxe edition)

Microsoft SMS Sender

sms2 Bit of an oldie here, and still untested with newer GSM Phones, however should you want to have SMS capability in your organization this may be a cheap way to go.

It requires a compatible phone (and cable) and then you can fire off scripts (or commandlines) to send sms messages.  Seem easy enough, but sadly I don’t have a data cable to the old Nokia phone in our storage room 🙁

Do let me know if you try it and it works 🙂

 

http://www.microsoft.com/globaldev/outreach/dnloads/smssender.mspx

SMSSender.msi

Update:
I finnally had the chance to test this (I had no data cable for my cell phone), anyway it is all very straight forward until you try to send an sms from command line, this will fail with a message like this “there is no device previously used by SMS sender…….”.

Unfortunately the SMS sender software has a bug that causes it NOT to write your choice from the GUI to registry :-(,  so you need to enter the device name manually to registry.

smsreg

 

 

 

 

 

 

The keyname is;
HKEY_CURRENT_USER\Software\Microsoft\SMSSender
The key is a sting;
DeviceName
And the value is the name of your device/cell phone (as displayed in the GUI)
eg. “Nokia 6230i USB Modem” (without quotes)

once this is done you can send command line sms’s (as shown below P=phone number M=message L=Log message);

C:\Program Files\Microsoft SMS Sender>smssender.exe /p:12345678 /m:"Hello World" /l

smsreg1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

There are more details plus some C++ code for semi implementation into your own software here (it’s a rather basic launch routine for the exe file);

http://veskokolev.blogspot.com/2009/07/how-to-send-sms-under-windows-using.html

One problem with the SMS sender software if you use it in scripting, it will once the SMS is send bring up a message window telling you that the sms was send succesfully, now this is not that practical it this actually ‘halts’ thr process until the message window is closed (the above C++ code will as I can see solve this by killing the window afterwards).  Another issue, ONLY ONE sms can be send at the time, if you try to send several SMS’s in a row the software will fail – guess that is logical enough but not that practical if the script that sends the sms can somehow be called several times at nearly the same time..

Aparantly there also exists an Outlook 2003/2007 extention (MOSA) that will do something similar vai Outlook, I have not had time to test this but as it’s also from Microsoft it should work just as well or maybe even better(however this requires Outlook);
http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=240080b4-986e-4afb-ab21-3af2be63508b&displayLang=en

Creating and using a custom Policy file (adm template)

So you for some reason or other need a custom GroupPolicy template (.adm template) to set some strange setting for some odd software.

You can use a Policy.ADM file to set custom registry values either for your own pc (may seem like a bit overkill) or more likely for your domain.

Well I have created a few of these back in the good old NT4 days and it was not all that difficult once you got the hang of it, and thus when I had the need again lately I was confident I could get it to work without too much of a hassle.

I was wrong :-/

Ok, creating a simple policy.adm file is easy;

policy1

And if you enter a keyname like;
”SoftwarePoliciesMicrosoftwhatever”

Things will work brilliantly, however lets say you want to change some obscure value for the adobe reader!?  This is outside the “Policies” section of the registry.. things will look like this when you enter the GPM MMC console.

policy2

This is where I lost my temper and started cursing at my monitor, see again once I put “Policies” in the keyname everything worked like a charm (but my setting was NOT in the Policy region of the registry)..

So Google to the rescue, it would seem that things have changed since the good old Poledit days, and that you need to do a bit of editor tweaking to get those ‘dirty’ settings available under NT4+ systems now-er-days.

Here is the secret;

policy3 
View, Filtering, “Only show policy settings that can be fully managed”..

Once this is done you can see everything – just like in the good old days 😀

policy4

Also it’s worth noting the other filter settings, I did not even know they existed, now you can actually limit your view to only those settings that are set, and this DO make it a lot easier to overlook the more complex policies.

Good luck making your new policies its easy as pie you know..

Links;
http://episteme.arstechnica.com/eve/forums/a/tpc/f/12009443/m/645000852731/inc/-1
http://www.windowsecurity.com/articles/ADM-Template-Repository.html
http://technet.microsoft.com/en-us/library/cc738443.aspx