Win Short AHK script to start XBMC windowed if in a Remote Session
#1
Hi,

I've working on my HTPC via RDP and have been frustrated if I left XBMC in Fullscreen mode after watching in my living room, so I wrote this little AutoHotKey script to edit the guisettings.xml file to change it back to windowed mode if it detects that a remote session is in progress. I am just posting the relevant part of the script, but it could be used as a hotkey or to launch XBMC after the script runs.
-Ken

Code:
#SingleInstance, Force
RS = False
fname = guisettings.xml
XBMCDir = %A_AppData%\XBMC\userdata\%fname%
SysGet, SessionRS, 4096 ; Check if it is a remote session

If SessionRS <> 0
RS = True

If RS = True
{
    FileRead fcont, %XBMCDir%
    StringReplace fnew, fcont, <screenmode>DESKTOP</screenmode>, <screenmode>WINDOW</screenmode>, UseErrorLevel
    If ErrorLevel <> 0
    {
        FileDelete %XBMCDir%
        FileAppend %fnew%, %XBMCDir%
    }
    fnew =
    fcont =
}

;Place whatever code you use to launch XBMC here if desired
Reply
#2
Aaaah - very useful indeed: thanks!
Reply
#3
I have found that this method seems more reliable. At least in Windows 7 x64. I also provided some positive feedback in the way of a message box.

Code:
#SingleInstance, Force
RS = False
;fname = test.xml
fname = guisettings.xml
XBMCDir = %A_AppData%\XBMC\userdata\%fname%
;SysGet, SessionRS, 4096 ; Check if it is a remote session
RegRead, SN, HKCU, Volatile Environment\1, SessionName


IfInString SN, RDP
RS = True

If RS = True
{
    MsgBox Starting windowed for remote session
    FileRead fcont, %XBMCDir%
    StringReplace fnew, fcont, <screenmode>DESKTOP</screenmode>, <screenmode>WINDOW</screenmode>, UseErrorLevel
    If ErrorLevel <> 0
    {
        FileDelete %XBMCDir%
        FileAppend %fnew%, %XBMCDir%
    }
    fnew =
    fcont =
}
;Place whatever code you use to launch XBMC here
Run C:\Program Files (x86)\XBMC\XBMC.exe, C:\Program Files (x86)\XBMC
Reply
#4
Hi

Will this work with TeamViewer?
And will it be possible to make set it back to DESKTOP mode if not connected with TeamViewer?
Petter :-)
Many thanks for all the effort YOU all do! THANKS! :-)
nVidia Shield TV (2015), Samsung QE75Q70R and Yamaha RX-V767
Reply
#5
No. I'm afraid it won't since this looks specifically to see if microsoft's RDP is being used. However, you could create two different scripts and put shortcuts on the desktop (or wherever you prefer) called something like 'XBMC windowed' and 'XBMC fullscreen'.

XBMC windowed:
Code:
#SingleInstance, Force

fname = guisettings.xml
XBMCDir = %A_AppData%\XBMC\userdata\%fname%
MsgBox Starting windowed for remote session
FileRead fcont, %XBMCDir%
StringReplace fnew, fcont, <screenmode>DESKTOP</screenmode>, <screenmode>WINDOW</screenmode>, UseErrorLevel
If ErrorLevel <> 0
    {
        FileDelete %XBMCDir%
        FileAppend %fnew%, %XBMCDir%
    }
fnew =
fcont =
;Place whatever code you use to launch XBMC here
Run C:\Program Files (x86)\XBMC\XBMC.exe, C:\Program Files (x86)\XBMC

XBMC fullscreen:
Code:
#SingleInstance, Force

fname = guisettings.xml
XBMCDir = %A_AppData%\XBMC\userdata\%fname%
FileRead fcont, %XBMCDir%
StringReplace fnew, fcont, <screenmode>WINDOW</screenmode>, <screenmode>DESKTOP</screenmode>, UseErrorLevel
If ErrorLevel <> 0
    {
        FileDelete %XBMCDir%
        FileAppend %fnew%, %XBMCDir%
    }
fnew =
fcont =
;Place whatever code you use to launch XBMC here
Run C:\Program Files (x86)\XBMC\XBMC.exe, C:\Program Files (x86)\XBMC
Reply
#6
This I will try. But, how do I save this to work?
*.bat or *.exe f.eks?
Petter :-)
Many thanks for all the effort YOU all do! THANKS! :-)
nVidia Shield TV (2015), Samsung QE75Q70R and Yamaha RX-V767
Reply
#7
AHK = autohotkey (http://www.autohotkey.com/)
I'm sure that some that is schooled in windows script could rewrite this too.
After you install AHK, use notepad to create two files with .ahk extensions and paste the code above into them.
Reply
#8
Ok, thanks. I will look into it. Thank you for the help so far.

It worked great. Thanks.
Petter :-)
Many thanks for all the effort YOU all do! THANKS! :-)
nVidia Shield TV (2015), Samsung QE75Q70R and Yamaha RX-V767
Reply

Logout Mark Read Team Forum Stats Members Help
Short AHK script to start XBMC windowed if in a Remote Session0