Wednesday, April 24, 2013

SOLVED [Simplest Way] : How to Run AutoHotKey to on Closed / Locked Remote Desktop


How to Run AutoHotKey / AHK / AutoKey on Closed / Locked Remote Desktop :


Hello All.


  • Found this Post : can a script made to work if the computer is lock
  • Thanks to ZK7 (the guy who posted the above), I am attaching below his simplest way of doing this (if you are not looking for some sophisticated solutions right now :-) ) : 
  • I had a problem running AutoHotKey script on a Windows 2008 server. Everything works perfectly when logged in with Remote Desktop, but as soon as I log out, all scripts stop working. The solution is relatively simple, but unfortunately no-one have mentioned it on this forum before.

    My specific requirements were to run a script which activates an FTP client (FileZilla) on my server and then log in and connect to another backup server syncronising the two servers on a weekly basis. This is then scheduled under the Task Scheduler to run automatically once a week. 

    The problem is that once you log out with remote desktop, then the server is locked and no scripts can run. I have tried various options, including ControlSend and ControlClick commands, but without any success.

    The solution is as follows:
    Create a batch file with the following commands and save it to the desktop of the workstation you want to keep unlocked:
    I have named my file Logoff.bat

    START C:\Windows\System32\tscon.exe 0 /dest:console
    START C:\Windows\System32\tscon.exe 1 /dest:console
    START C:\Windows\System32\tscon.exe 2 /dest:console
    START C:\Windows\System32\tscon.exe 2 /dest:console
    START C:\Windows\System32\tscon.exe 3 /dest:console
    START C:\Windows\System32\tscon.exe 4 /dest:console
    START C:\Windows\System32\tscon.exe 5 /dest:console


    Tscon.exe comes standard with your windows installation and is specifically created to leave a Previously-Locked Console Unlocked.
    See this link: http://support.microsoft.com/kb/302801

    The next time you log in to the workstation with remote desktop, do not log out the normal way, but run you batch file - in my case "Logoff.bat"
    This will terminate your Remote Desktop connection and log you out, but will then continue in an unlocked state for any scripts to run as if someone is actually logged in.

    Should you log out the normal way with remote desktop, then the workstation will be locked - so ensure to log out with your .bat shortcut on your desktop.


    As easy as that!
  • Just enjoy :-)

Thursday, June 14, 2012



Here is a vbscript / vbs / vb script example which collects hebrew results from an External Website (Google Results in Example):

Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
Set FSO = createobject("Scripting.FileSystemObject")

'Define Some http headers and options
 strUserAgentString = "http_requester/0.1"
 intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err
 blnEnableRedirects = True
 blnEnableHttpsToHttpRedirects = True
   
  objWinHttp.Option(0) = strUserAgentString
  objWinHttp.Option(4) = intSslErrorIgnoreFlags
  objWinHttp.Option(6) = blnEnableRedirects
  objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects

'If you need a Proxy define it here 
objWinHttp.SetProxy 2,"148.87.65.20:80"

'Define the Hebrew Google String you would like or any other Hebrew website.
URL = "https://www.google.co.il/search?sugexp=chrome,mod=3&sourceid=chrome&ie=UTF-8&q=%D7%99%D7%A9%D7%A8%D7%90%D7%9C"
objWinHttp.open "GET",URL
objWinHttp.setRequestHeader "Content-Type", "text/html; charset=UTF-8"
objWinHttp.send ""

'Generate an output file - This will fix UTF8 of objWinHttp.responseText to a file.
Set Fileout = FSO.CreateTextFile("c:\temp\google_utf8.xml", true, true)
Fileout.Write objWinHttp.responsetext
Fileout.Close

'Instead of using : 'WScript.Echo objWinHttp.responseText

How to implement :
Simply run it from CMD (windows)

ALL INFO APPEARS HERE THANKS TO :
http://www.tech-archive.net/Archive/Scripting/microsoft.public.scripting.vbscript/2007-04/msg00387.html