Tuesday, March 27, 2007

Fun with command line variables

Some time ago I needed to set up a log rotation, renaming an existing log file to the current time and date. The thing is dutch dates use a comma and you can't have that. I needed a way to cut the time and date variables in pieces and create my own time and date notation.

I could have used some tools but I like to use the standard Windows tools. I decided to use the set command which has some nice operators:

Set the variable hour to the first 2 characters of the time (offset 0):
set hour=%time:~0,2%

Set the variable minute to the 4th and 5th characters of the time (offset 3):
set minute=%time:~3,2%

Set the variable seconds to the 6th and 7th characters of the time (offset 6):
set second=%time:~6,2%

Then add everything together: copy logfile "C:\Logfiles\%hour%.%minute%.%second%.log"

I just realised that you don't even need to store the hours, minutes and seconds in termporary values. The command copy logfile "C:\Logfiles\%time:~0,2%.%time:~3,2%.%time:~6,2% works just as nice!

Monday, March 26, 2007

Customize RDP connection files

Hi, I'm just back from a vacation in Valloire, FR check it out! Anyways, I promised myself to keep putting cool stuff here, so here we go...

You probably know you can save a remote desktop connection to a file, but have you ever wondered what's in there? Well, just open it up with notepad shall we?
screen mode id:i:1
session bpp:i:16
auto connect:i:1
full address:s:
password 51:b:01000000D08C9DDF0115D1118C7A....
alternate shell:s:
shell working directory:s:
disable wallpaper:i:1
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:1

The server you are connecting to is set by "full address". Your username and password are set in "username" and "password 51". Please note the password is encrypted for use by the currently logged in user.

With "desktopwidth" and "desktopheight" you can specify the size of the window. You can tweak the RDP session's size to your liking. You can specify the place of the session window on the local screen with "winposstr".

You can find a lot more info here and here.

Monday, March 12, 2007

Run VNC and RDP from hyperlinks

It looks like Google has finally spidered my new blog so I hope to get some more visitors soon. ;-)

Anyways, just wanted to share a handy way to connect to RDP and VNC servers. If you, as I do, use tools like Nagios to monitor my servers, wouldn't it be easy if you could just click a link to start the VNC or RDP connection? Well, you can:

Save the following text as C:\Windows\RDP.js:
var destination=(WScript.Arguments(0))
var search='rdp://'
var rdpexe='C:\\WINDOWS\\system32\\mstsc.exe'
destination=destination.replace(search, '')
destination=destination.replace('/', '')
var ws = new ActiveXObject("WScript.Shell")
//WScript.Echo(rdpexe + " /v:" + destination)
ws.Exec(rdpexe + " /v:" + destination)

Save the next piece as RDP.reg:
Windows Registry Editor Version 5.00
@="URL:Remote Desktop Connection"
"URL Protocol"=""
@="wscript.exe C:\\WINDOWS\\rdp.js %1"

Double click and presto! When you click something like rdp:// you will be connected to that server by RDP.

VNC is not much more difficult, edit the following text to point to your VNC and save as C:\Windows\VNC.js:
var destination=(WScript.Arguments(0))
var search='vnc://'
//Modify the path to VNC Viewer!
var vncexe='D:\\Apps\\VNC\\vncviewer.exe'
destination=destination.replace(search, '')
destination=destination.replace('/', '')
var ws = new ActiveXObject("WScript.Shell")
//WScript.Echo(vncexe + " " + destination)
ws.Exec(vncexe + " " + destination)

Save the next piece of text as VNC.reg and doubleclick:
Windows Registry Editor Version 5.00
@="URL:VNC Connection"
"URL Protocol"=""
@="wscript.exe C:\\WINDOWS\\vnc.js %1"

Tuesday, March 6, 2007

Time sync issues

Damn, damn, dammit! Just finished time synching some servers in seperate networks and if I had these tools before it would have taken half my time.

First the tool I used to diagnose the problem and check which servers were in sync: NTPmonitor.

Then I used this document to setup the server to use NTP sources and synced everything to a reliable NTP source.

Of course I used a stratum 2 source as these servers will not be available to the public. Use your preferred search engine to find public NTP servers.