Jump to content
Sign in to follow this  
Ascend4nt

Internet Shortcut Sanitizer (.URL and .website files)

Recommended Posts

Internet Shortcut Sanitizer


With the newest Firefox and IE browsers, there's a bit of an issue with Internet Shortcuts created, which have been traditionally saved in a .URL file on Windows (an INI-structured file).

Firefox now adds Icon information to the file which points it at a location within %localappdata%MozillaProfiles.  This to me is annoying and unnecessary. While it may reflect the favicon of a website, its got a few problems:

  1. When the cache is cleared or the bookmark is moved to another computer or put on a fresh install, that icon isn't there anymore.
  2. These shortcuts contain your logon name (part of %localappdata%), so be aware of this if you are going to share them! (or just use a generic logon)

 

Here's the content of a typical Firefox .URL file (<LogonName> is your Windows logon):

[InternetShortcut]
URL=http://www.google.com/
IDList=
HotKey=0
IconFile=C:\Users\<LogonName>\AppData\Local\Mozilla\Firefox\Profiles\a3n21a.default\shortcutCache\md34sdyu7s_g==.ico
IconIndex=0

_

Update: if you have Firefox 21, you can follow and edit Firefox's about:config settings to fix the way URL shortcuts are created.

Internet Explorer (IE 9+) now has its own new shortcut extension (.website), which seems to only work with the IE browser.  These files are basically 'enhanced' internet shortcuts. The extra information included is cryptic, and appears to be of no use outside of IE.  However, the INI-format is the same, and the [internetShortcut] section is the same, so it can simply be renamed to have a .URL extension.

Here's the content of a typical Internet Explorer 9+ .website file:

[{000214A0-0000-0000-C000-000000000046}]
Prop4=31,Google
Prop3=19,2
[{A7AF692E-098D-4C08-A225-D433CA835ED0}]
Prop5=3,0
Prop9=19,0
[InternetShortcut]
URL=http://www.google.com/
IDList=
IconFile=http://www.google.com/favicon.ico
IconIndex=1
[{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}]
Prop12=19,2
Prop5=8,Microsoft.Website.9CB8E698.8730F9E8

_

(Note the embedded [internetShortcut] section)

Sanitize your shortcuts!

The fix for these problems?  A little Internet Shortcut Sanitizer program.  If you're like me and just want Internet Shortcuts to be just that - a simple file with a URL in it, then this program will give you what you need.  It strips everything out but the 2 lines necessary to work as a .URL file:

[InternetShortcut]
URL=http://www.website.com

_

The script will also create .URL's from .website files and remove all the IE related stuff.  Currently it either takes 1 parameter or allows you to select 1 file to change.  However, it can be adapted to work on multiple files with a little extra effort.  However, I'd recommend something like grepWin to clear out folders (see 3rd post), and maybe a batch file renamer to deal with .website -> .URL conversion.

Below is the script.

Changelog:

2013-05-17:

- Packaged the main functionality of the script into the embedded UDF: _InternetShortcutSanitize()

; ==================================================================================================================
; <InternetShortcutSanitizer.au3>
;
;   'Sanitizes' Internet shortcuts, both of the traditional Windows .URL format and of the newer IE .website format
;    In the case of the latter, it will delete the .website variant and create a URL version
;
; Author: Ascend4nt
; ==================================================================================================================

Local $sFile

If $CmdLine[0] < 1  Then
    $sFile=FileOpenDialog("Select Internet Shortcut to Sanitize","","Internet Shortcut Files (*.URL;*.website)|All Files (*.*)",3)
    If @error Or $sFile="" Then Exit
Else
    $sFile = $CmdLine[1]
EndIf
$sFile = StringStripWS($sFile,3)
If Not FileExists($sFile) Then Exit

;~ ConsoleWrite("Internet Shortcut file to sanitize = "&$sFile&@CRLF)

_InternetShortcutSanitize($sFile)



; ===================================================================================================
; Func _InternetShortcutSanitize($sFile)
;
; 'Sanitizes' the Internet shortcut file passed. This keeps URL files to a 2-line file of this format:
;   [InternetShortcut]
;   URL=http://www.website.com
;
; In the case the input file is an Internet Explorer .website shortcut (in IE 9+), it will
; create a .URL file of the same name, and upon successful write, it will delete the .website file.
;
; $sFile = Full path to file to sanitize
;
; Return:
;  Success: True
;  Failure: False with @error set
;
; Author: Ascend4nt
; ===================================================================================================

Func _InternetShortcutSanitize($sFile)
    If $sFile = "" Then Return SetError(1,@error,False)

    ; Get rid of whitespace at beginning & end
    $sFile = StringStripWS($sFile,3)

    Local $sFileOut, $nRet
    Local $sURL = "", $sFileContent = ""

    $sURL = IniRead($sFile, "InternetShortcut", "URL", "")
    If @error Or $sURL = "" Then Return SetError(-1,@error,False)

;~  ConsoleWrite("URL = "&$sURL&@CRLF)

    ; Standard URL format
    $sFileContent = "[InternetShortcut]"&@CRLF&"URL="&$sURL&@CRLF

    ; $sFileOut: If not .website, we keep it the same.
    ;  Otherwise, we transfer it to a .URL file
    If StringRight($sFile, 8) = ".website" Then
        $sFileOut = StringReplace($sFile, ".website", ".URL", -1)
    Else
        $sFileOut = $sFile
    EndIf

    ; Create/Overwrite the URL file
    $hFile = FileOpen($sFileOut, 2)
    If $hFile = -1 Then Return SetError(3, 0, False)

    $nRet = FileWrite($hFile, $sFileContent)

    FileClose($hFile)

    ; FileWrite error?
    If Not $nRet Then
;~      ConsoleWrite("File Write error"&@CRLF)
        Return SetError(4,0,False)
    EndIf

    ; .website -> .URL 'translation' performed?  Delete .website file
    If $sFile <> $sFileOut Then
        ; Make sure we actually created the .URL file before delete:
        If FileExists($sFileOut) Then FileDelete($sFile)
    EndIf

    Return True
EndFunc
Edited by Ascend4nt

Share this post


Link to post
Share on other sites

Thaks for sharing this.

I was unaware of the issue. I love stripping and deleting superfulous data from dumb proprietary formats.

Share this post


Link to post
Share on other sites

Glad ya found it helpful.  I should just put it in a UDF function, that'd be the sensible thing to do.  Right now I just tend to use it on individual files after creating shortcuts, along with the simple shell app Open++ to run the script based on the filetype.

Btw, if anyone just wants to strip out the personal info with something like grepWin, this Regular Expression will work (on *.url files):

IconFile=.:\\.*\v+IconIndex=\d*\v+

Share this post


Link to post
Share on other sites

 

I should just put it in a UDF function

I would prefer this too. Plus, seems you're into grepWIn right now.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

For Firefox look also:

http://support.mozilla.org/en-US/questions/942316?page=4

tenbucks posted 5/15/13 3:13 AM

 

"Finally. It's here with FF 21. You need to add the browser.shell.shortcutFavicons entry in about:config. It doesn't come with it. Make it boolean and set it to false. Restart FF."

 

Paul

 

Nice!  I just updated to Firefox 21 and added that. It works nicely, thanks for the tip! :)


Share this post


Link to post
Share on other sites

I would prefer this too. Plus, seems you're into grepWIn right now.

 

Haha, yes you can probably see the trail I left leading from PortableFreeware to here and back again!  Seems if there's some tool I need, its either there or here - or yet to be created.

Oh, and I did a little editing so now the 'sanitize' code is in a UDF (inside the main script).

Changelog:

2013-05-17:

- Packaged the main functionality of the script into the embedded UDF: _InternetShortcutSanitize()


Share this post


Link to post
Share on other sites

Cheers Ascend4nt.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

Hi all!

I don't have any Autoit experience, but I updated the script in a quick and dirty way, such that it can handle multiple files at once (via command line - i.e. you can drag and drop many files onto your executable). I think Autoit can only process 63 commandline elements at a time - and i didn't add any checks, etc. - but I think this version will do for quite a lot of use cases.

Cheers =)

#include <MsgBoxConstants.au3>

; ==================================================================================================================
; <InternetShortcutSanitizer.au3>
;
;   'Sanitizes' Internet shortcuts, both of the traditional Windows .URL format and of the newer IE .website format
;    In the case of the latter, it will delete the .website variant and create a URL version
;
; Author: Ascend4nt
; ==================================================================================================================

Local $sFile
Local $iParamCount
Local $fBoolFirstElementSkipped
$iParamCount = $CmdLine[0]

If $iParamCount < 1 Then
    $sFile=FileOpenDialog("Select Internet Shortcut to Sanitize","","Internet Shortcut Files (*.URL;*.website)|All Files (*.*)",3)
    If @error Or $sFile="" Then Exit
Else
    $fBoolFirstElementSkipped = False

    For $sElement In $CmdLine
        If $fBoolFirstElementSkipped = False Then
            $fBoolFirstElementSkipped = True
        Else
            $sFile = $sElement
            $sFile = StringStripWS($sFile,3)
            ;MsgBox($MB_SYSTEMMODAL, "Current File (5 Sec Timeout)", $sFile, 5)
            If Not FileExists($sFile) Then Exit
            ;~ ConsoleWrite("Internet Shortcut file to sanitize = "&$sFile&@CRLF)
            _InternetShortcutSanitize($sFile)
        EndIf
    Next
EndIf

; ===================================================================================================
; Func _InternetShortcutSanitize($sFile)
;
; 'Sanitizes' the Internet shortcut file passed. This keeps URL files to a 2-line file of this format:
;   [InternetShortcut]
;   URL=http://www.website.com
;
; In the case the input file is an Internet Explorer .website shortcut (in IE 9+), it will
; create a .URL file of the same name, and upon successful write, it will delete the .website file.
;
; $sFile = Full path to file to sanitize
;
; Return:
;  Success: True
;  Failure: False with @error set
;
; Author: Ascend4nt
; ===================================================================================================

Func _InternetShortcutSanitize($sFile)
    If $sFile = "" Then Return SetError(1,@error,False)

    ; Get rid of whitespace at beginning & end
    $sFile = StringStripWS($sFile,3)

    Local $sFileOut, $nRet
    Local $sURL = "", $sFileContent = ""

    $sURL = IniRead($sFile, "InternetShortcut", "URL", "")
    If @error Or $sURL = "" Then Return SetError(-1,@error,False)

;~  ConsoleWrite("URL = "&$sURL&@CRLF)

    ; Standard URL format
    $sFileContent = "[InternetShortcut]"&@CRLF&"URL="&$sURL&@CRLF

    ; $sFileOut: If not .website, we keep it the same.
    ;  Otherwise, we transfer it to a .URL file
    If StringRight($sFile, 8) = ".website" Then
        $sFileOut = StringReplace($sFile, ".website", ".URL", -1)
    Else
        $sFileOut = $sFile
    EndIf

    ; Create/Overwrite the URL file
    $hFile = FileOpen($sFileOut, 2)
    If $hFile = -1 Then Return SetError(3, 0, False)

    $nRet = FileWrite($hFile, $sFileContent)

    FileClose($hFile)

    ; FileWrite error?
    If Not $nRet Then
;~      ConsoleWrite("File Write error"&@CRLF)
        Return SetError(4,0,False)
    EndIf

    ; .website -> .URL 'translation' performed?  Delete .website file
    If $sFile <> $sFileOut Then
        ; Make sure we actually created the .URL file before delete:
        If FileExists($sFileOut) Then FileDelete($sFile)
    EndIf

    Return True
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By singh54
      Hello All,

      I am new to auto It  and coding. Have only tried few automated logging for different websites.  The login pages of the websites which I have worked on were having form name with input type as text and it seems straight forward to automate their login using "_IEFormElementSetValue".
      I have got a url, it does not have any form in the source page. On further analyzing I found that It does call some login page separately as below.
      function showLogin(arg) {
        Global.pollingDialogDoc = null;
        var fresh = jQuery.isValidString(arg) && "fresh" == arg ? !0 : !1, appFrame = $("#appFrame");
        if ($("#modalFrame").show(), $("iframe").hide(), fresh || !appFrame.attr('src').match("html/login.html")) appFrame.attr('src', baseURL + 'html/login.html'), 
        appFrame.on('load', function() {
          setTimeout(function() {
            $("#modalFrame").hide(), appFrame.show();
          }, 1);
        }); else try {
          window.frames.appFrame.updatePageFromIndex();
        } catch (e) {}
      }
      I can simply use "send" and "mouse click" Method to automate the login but that doesn't seems very reliable. Is there any separate way to fill the user ID and password to the respective fields by having reference by frames or something. 
      Appreciate if any one can point me to correct document or help in any way...!
    • By HariKara
      I have a script that seems to launch perfectly fine with IECreate, however, I want to launch the Browser and a specific URL with the RunAs command. I fairly new to AutoIT and wanted to know if someone can point me in the right direction.
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = _IECreate($sURL)
      The above launches the website correctly with the correct URL, however, I have tried the below and this fails to load and browser?
      #include <AutoItConstants.au3>
      ;========================
      $oSleep = "200"
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = RunAs($args("username"), $args("domain"), $args("logonpassword"), "", "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://somewebsite.com/DODA/admin/job.aspx")
      _IELoadWait($oIE)
       
      I get the following error back?
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
    • By nacerbaaziz
      hello sirs
      please i want to use the WinHttp to get the google drive file title using the api
      i searched in the forom but i didn't found any Google drive api UDF
      for that i liked to ask you for that
      i had read the google drive api documentation but i couldn't do it
      please help me
      here is the api doc
      note i've got the apikey and i have the file id
      what i want is to get the title of the file (the file name)
      because i want to download the files from the google drive using the autoit
      please help me for that
      am sorry because i didn't gave you any example or what i tried but all what tried was  failed
      thanks in advance
    • By nacerbaaziz
      hello sirs
      i've some questions about StringRegExpReplace i hope you can help me
       
      i tried to make a function that give me the host of the url and other give me the url with out host
      for example i've this link
      https://www.example.com/vb/result.php
      i need the first give me the
      example.com
      and the other give me 
      /vb/result.php
      i find that
      $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page)  
      but i found some problems i need your help to correct it
      first: when i get the host if the url has www i want to remove it
      second: if the url with out host did not have other things 
      i need the result to be ""
      e.g
      https://www.example.com
      the first i want it
      example.com
      and the second i want it to be ""
      i hope that you can help me
      thanks in advance
×
×
  • Create New...