Monday, February 23, 2009

MaxiVista in different environments

I'm using MaxiVista a lot, as well at home as at the office. It's great to be able to easily extend your desktop over the network onto an old pc, resulting in a very large screen managed with only one keyboard and mouse.

But I was facing the following problem when switching between my home environment and work environment: different IP addresses are used, resulting in MaxiVista to only function correctly when some manual configuration was updated and the PC rebooted, each time! While looking into this, I noticed the IP address of the server to connect to, was kept into the regstry key: HKEY_CURRENT_USER\Software\MaxiVista\A3\username\b1, b2 and b3. So by changing these values to the correct IP, and only then starting up MaxiVista, I was able to quickly switch between my environments. But yet I was facing another issue, I couldn't use static IP in one of my environments, so I wanted to automatically detect the correct IP address linked to a hostname. So, I wrote the following little batch script to get everything working nicely. One can copy-paste this into a .bat textfile, replace maxivistaserverhostname and username and run it. This way of working can of course be used anywhere else when to link a hostname to an IP address within a batch script.

@echo off
rem stop applications
taskkill /F /IM MaxiVistaA.exe
rem ping host
SET HOSTNAME=maxivistaserverhostname
ping -n 1 -w 1 %HOSTNAME% > %TEMP%.\ping.txt
setlocal enabledelayedexpansion
set ip=
for /f "usebackq delims=[] tokens=2" %%i in (`find "[" "%TEMP%\ping.txt"`) do (
  set ip=%%i
> %TEMP%.\ping.txt ECHO %ip%
for /f "usebackq tokens=1,2,3,4 delims=. " %%i in (%TEMP%\ping.txt) do (
  reg add "HKCU\Software\MaxiVista\A3\%USERNAME%" /v "b1" /t REG_DWORD /d "%%i" /f
  reg add "HKCU\Software\MaxiVista\A3\%USERNAME%" /v "b2" /t REG_DWORD /d "%%j" /f
  reg add "HKCU\Software\MaxiVista\A3\%USERNAME%" /v "b3" /t REG_DWORD /d "%%k" /f
  reg add "HKCU\Software\MaxiVista\A3\%USERNAME%" /v "b4" /t REG_DWORD /d "%%l" /f
:: Delete the temporary ping file
DEL %TEMP%.\ping.txt
start "MaxiVista" "C:\Program Files\MaxiVista\MaxiVistaA.exe"
@echo on

No comments:

Post a Comment