Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

privacy: batch-killing (editing) hidden content of URL(!) files in win2K

98 views
Skip to first unread message

Acamas

unread,
May 3, 2013, 2:01:46 PM5/3/13
to
Hello,



It's been a while -- actually: a few decades -- since I've been using batch files last time for more than just simple operations like moving or deleting files. Now I'm faced with a problem that appears to be a bit more difficult - at least for me. So I hope someone can help me out with a few good hints.



I have to edit thousands of links, both *.URL and *.LNK files, on a W2K machine with NTFS.



First trouble comes up when you try to simply "open" a URL or LNK file from a GUI shell (NOT using the console):

(A) Opening a LNK in fact opens the target file, not the LNK file itself.

(B) Opening a URL with a GUI editor causes a crash of the editor.



Quite different, when you open it using the console ("edit FILENAME.URL"):



(A) Opening a LNK file in deed "opens" the file itself (not the target).

However, the "content" of a LNK file, i.e.
- path to the target,
- path to an alternative active directory (optional),
- keyboard shortcut (optional),
- window size (normal, maximized, minimized),
- comment (optional),
is in a non-text format I have no idea how to edit with a plain text editor only. Maybe, some of you know a batchable (scriptable) 3rd-party tool or any tricky work-around for that task. (?)



Anyway, the more important problem is this:



(B) Opening a URL file with "edit" command will also open the file itself, and it shows all the information in plain text format, e.g.:



========== *.URL ==========



[InternetShortcut]

URL=file:///C:/data/targetfile.jpg (or simply "http://." or whatever)

Modified=000000000000000000h

IconIndex=0

IconFile=C:\WINNT\system32\url.dll



[AdditionalParagraphs]

- with nasty but harmless doubleclick.net links and such stuff

- or even less harmless links to external spyware or something



========== E O F ==========



Now, my job is to write a batch file to automatically remove all these additional entries in all relevant URL files in a LAN, beginning with a W2K machine/system, and I guess I'm not the first one with this task. Therefore, I ended up here, looking for help. ;-)



Btw.: I also try to automatically (batch-aided) change some Icon files, or read out URLs and time stamps for better organizing the files in databases. However, that seems to be the same thing, at the end.



Thanks in advance for some feedback!


Acamas

Auric__

unread,
May 3, 2013, 10:25:46 PM5/3/13
to
Acamas wrote:

> It's been a while -- actually: a few decades -- since I've been using
> batch files last time for more than just simple operations like moving
> or deleting files. Now I'm faced with a problem that appears to be a bit
> more difficult - at least for me. So I hope someone can help me out with
> a few good hints.
>
>
>
> I have to edit thousands of links, both *.URL and *.LNK files, on a W2K
> machine with NTFS.
>
>
>
> First trouble comes up when you try to simply "open" a URL or LNK file
> from a GUI shell (NOT using the console):
>
> (A) Opening a LNK in fact opens the target file, not the LNK file
> itself.
>
> (B) Opening a URL with a GUI editor causes a crash of the editor.

'notepad filename.lnk' works as expected for me. I end up with binary
gibberish in the editor, but no crash.

> Quite different, when you open it using the console ("edit
> FILENAME.URL"):
>
>
>
> (A) Opening a LNK file in deed "opens" the file itself (not the target).
>
> However, the "content" of a LNK file, i.e.
> - path to the target,
> - path to an alternative active directory (optional),
> - keyboard shortcut (optional),
> - window size (normal, maximized, minimized),
> - comment (optional),
> is in a non-text format I have no idea how to edit with a plain text
> editor only. Maybe, some of you know a batchable (scriptable) 3rd-party
> tool or any tricky work-around for that task. (?)

You can edit it via the Windows API, but I don't know what is needed.
Personally, I would ask in comp.os.ms-windows.programmer.win32. (You'll
probably need something besides batches to do this, but who knows.)

> Anyway, the more important problem is this:
>
>
>
> (B) Opening a URL file with "edit" command will also open the file
> itself, and it shows all the information in plain text format, e.g.:

[snip]

> Now, my job is to write a batch file to automatically remove all these
> additional entries in all relevant URL files in a LAN, beginning with a
> W2K machine/system, and I guess I'm not the first one with this task.
> Therefore, I ended up here, looking for help. ;-)

Does it *have* to be a batch file? This one *can* be done in batches, but
it really strikes me as something more suited to a non-scripting language.
I would do this job in, say, Qbasic, or a modern compiled language.

> Btw.: I also try to automatically (batch-aided) change some Icon files,
> or read out URLs and time stamps for better organizing the files in
> databases. However, that seems to be the same thing, at the end.

Time stamps can be edited with something like 'touch' (a utility from the
*nix world, which should be available in MinGW, GNUwin32, and other *nix-
on-Windows systems), and that is easily scriptable. Changing the icons...
that, I don't know. It depends on how that is stored, something I know
nothng about.

--
- You don't sleep, do you?
- Does lying still count?

foxidrive

unread,
May 3, 2013, 10:38:46 PM5/3/13
to
On 4/05/2013 04:01, Acamas wrote:

> I have to edit thousands of links, both *.URL and *.LNK files, on a W2K machine with NTFS.

> (A) Opening a LNK in fact opens the target file, not the LNK file itself.

Open the .LNK files in an editor, or a program designed to modify them.

> (B) Opening a URL with a GUI editor causes a crash of the editor.

Use a different editor. They are just text files.

> (B) Opening a URL file with "edit" command will also open the file itself, and it shows all the
> information in plain text format, e.g.:
>
> [AdditionalParagraphs]
>
> - with nasty but harmless doubleclick.net links and such stuff
>
> - or even less harmless links to external spyware or something
>
>
> Now, my job is to write a batch file to automatically remove all these additional entries in all
> relevant URL files

For some suggestions, show us some sample URL files and describe what you need removed.


It's also unclear what you want to change in the .LNK files but there are .LNK editors around for the
command line.


--
foxi

Todd Vargo

unread,
May 4, 2013, 12:51:04 AM5/4/13
to
On 5/3/2013 2:01 PM, Acamas wrote:
> Hello,
>
>
>
> It's been a while -- actually: a few decades -- since I've been using batch files last time for more than just simple operations like moving or deleting files. Now I'm faced with a problem that appears to be a bit more difficult - at least for me. So I hope someone can help me out with a few good hints.
>
>
>
> I have to edit thousands of links, both *.URL and *.LNK files, on a W2K machine with NTFS.
>
>
>
> First trouble comes up when you try to simply "open" a URL or LNK file from a GUI shell (NOT using the console):
>
> (A) Opening a LNK in fact opens the target file, not the LNK file itself.
>
> (B) Opening a URL with a GUI editor causes a crash of the editor.
>
>
>
> Quite different, when you open it using the console ("edit FILENAME.URL"):
>
>
>
> (A) Opening a LNK file in deed "opens" the file itself (not the target).
>
> However, the "content" of a LNK file, i.e.
> - path to the target,
> - path to an alternative active directory (optional),
> - keyboard shortcut (optional),
> - window size (normal, maximized, minimized),
> - comment (optional),
> is in a non-text format I have no idea how to edit with a plain text editor only. Maybe, some of you know a batchable (scriptable) 3rd-party tool or any tricky work-around for that task. (?)

That is correct, .lnk files are in a non-text format. You can extract
information from them using vbscript's CreateShortcut method.
Unfortunatly, you did not state what you are doing with the data to
offer any further information.



> Anyway, the more important problem is this:
>
>
>
> (B) Opening a URL file with "edit" command will also open the file itself, and it shows all the information in plain text format, e.g.:
>
>
>
> ========== *.URL ==========
>
>
>
> [InternetShortcut]
>
> URL=file:///C:/data/targetfile.jpg (or simply "http://." or whatever)
>
> Modified=000000000000000000h
>
> IconIndex=0
>
> IconFile=C:\WINNT\system32\url.dll
>
>
>
> [AdditionalParagraphs]
>
> - with nasty but harmless doubleclick.net links and such stuff
>
> - or even less harmless links to external spyware or something
>
>
>
> ========== E O F ==========
>
>
>
> Now, my job is to write a batch file to automatically remove all these additional entries in all relevant URL files in a LAN, beginning with a W2K machine/system, and I guess I'm not the first one with this task. Therefore, I ended up here, looking for help. ;-)

Actually, the only line in the file that needs to be retained is the
"url=" line. All other lines are just useless frill.


>
>
>
> Btw.: I also try to automatically (batch-aided) change some Icon files, or read out URLs and time stamps for better organizing the files in databases. However, that seems to be the same thing, at the end.

Sorry, this item is too vague to even comment on.


--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Todd Vargo

unread,
May 4, 2013, 1:15:45 AM5/4/13
to
On 5/4/2013 12:51 AM, Todd Vargo wrote:
> On 5/3/2013 2:01 PM, Acamas wrote:
<snip>
>> Now, my job is to write a batch file to automatically remove all these
>> additional entries in all relevant URL files in a LAN, beginning with
>> a W2K machine/system, and I guess I'm not the first one with this
>> task. Therefore, I ended up here, looking for help. ;-)
>
> Actually, the only line in the file that needs to be retained is the
> "url=" line. All other lines are just useless frill.

If you are interested in pruning to just the "url=" lines, try the
following batch on a test folder with some sample files.

@echo off
for %%A in (*.url) do (
for /f "delims=" %%B in ('find /i "url=" ^<"%%A"') do (
echo %%B > %%A
)
)

Acamas

unread,
May 4, 2013, 12:46:14 PM5/4/13
to
"Auric__" <not.m...@email.address> wrote...



__________
|
| > (A) Opening a LNK in fact opens the target file, not the LNK file.
| > (B) Opening a URL with a GUI editor causes a crash of the editor.
|
| 'notepad filename.lnk' works as expected for me. I end up with binary gibberish in the editor, but no crash.
|
¯¯¯¯¯¯¯¯¯¯

(A) ' Notepad filename. L N K ' doesn't crash.
(B) ' Notepad filename. U R L ' causes the trouble.

However, you're right: 'notepad filename. L N K' -- via CONSOLE, or via START->RUN -- opens the file itself, and not the target.

What I tried so far was:
(1) open the notepad;
(2) open the file from INSIDE the notepad --> And THIS opens the target instead of the LNK file.

Whereas:
(1) open the console or START>RUN;
(2) open an editor and the LNK file TOGETHER with ONE single command --> opens the LNK file, not the target. 'EDIT %1' or 'NOTEPAD %1' doesn't matter.

I just forgot that from windows command line I can open native windows files too, so I can use 'notepad' in the same way as the 'edit' command.

To my excuse: last time I used DOS was about two or more decades ago. Native MS-DOS 3.x, or 5.x or so. No way to run a windows exe file from a DOS prompt, back then.



__________
|
| You can edit it via the Windows API, but I don't know what is needed. Personally, I would ask in comp.os.ms-windows.programmer.win32. (You'll probably need something besides batches to do this, but who knows.) […]
|
| > (B) Opening a URL file […]
|
| Does it *have* to be a batch file? This one *can* be done in batches, but it really strikes me as something more suited to a non-scripting language. I would do this job in, say, Qbasic, or a modern compiled language.
|
¯¯¯¯¯¯¯¯¯¯

No, it doesn't HAVE to be a batch file. That's just something I've already dealt with (decades ago). :-/



__________
|
| Time stamps can be edited with something like 'touch' (a utility from the *nix world, which should be available in MinGW, GNUwin32, and other *nix-on-Windows systems), and that is easily scriptable.
|
¯¯¯¯¯¯¯¯¯¯

Roger that. Thanks for the hint!



__________
|
| Changing the icons... that, I don't know. It depends on how that is stored, something I know nothng about.
|
¯¯¯¯¯¯¯¯¯¯

Changing the icons in URL files shouldn't be a particular problem as long as I can edit the URL file in general.

In URL files, icons are stored as plain text (see lines 4 and 5):



> ========== *.URL ==========
> Line 1: [InternetShortcut]
> Line 2: URL=file:///c:/targetfile.*
> Line 3: Modified=000000000000000000h
> Line 4: IconFile=c:\iconfile.dll
> Line 5: IconIndex=0
> ========== E O F ==========


OK, I'll have a look at the other answers, now.

Standby, plz!

Acamas

unread,
May 4, 2013, 1:56:21 PM5/4/13
to
"foxidrive" <n...@this.address.invalid> wrote...



__________
| Open the .LNK files in an editor, or a program designed to modify them.
¯¯¯¯¯¯¯¯¯¯

Wilco. I'll have a look for such tools.



__________
| > (B) Opening a URL with a GUI editor causes a crash of the editor.
|
| Use a different editor. They are just text files.
¯¯¯¯¯¯¯¯¯¯

I did. I tried different GUI editors, e.g. Don Ho's notepad-plus-plus which handles nearly everything. Nevertheless, opening a URL file directly from notepad++ also gives back an 'invalid file format' error.

However, meanwhile I've got it: It's not the editor, which causes trouble. It's just about the way you open an URL file.
- Windows --> open --> editor --> open --> URL file --> error.
- Console --> open --> editor --> open --> URL file --> correctly opens the URL file.
- Console --> open --> editor, AND URL file as a variable --> also correctly opens the URL file.
- Windows --> RUN! --> editor, AND URL file as a variable --> also correctly opens the URL file.
- Windows --> open --> LNK file that points to a URL file --> opens the target file -- which IS the URL file.



__________
| It's also unclear what you want to change in the .LNK files but there are .LNK editors around for the command line.
¯¯¯¯¯¯¯¯¯¯

I guess, that'll be exactly what I need for the LNK files. It's to maintain them, e.g.
- checking the target URLs, and changing them if necessary,
- changing the path to special icon files for thousands of links, and
- adding or editing comments as quick info for users.



__________
| For some suggestions, show us some sample URL files and describe what you need removed.
¯¯¯¯¯¯¯¯¯¯


Here you are:

========== *.URL ==========

[DEFAULT]

BASEURL=http://domain.tld/

[InternetShortcut]

URL=http:// domain.tld/?x=a&y=b .

IconFile=C:\icon.ico

IconIndex=0

Modified=E044D72C3B0DCE013E

[{000214A0-0000-0000-C000-000000000046}]

Prop3=19,2

[DOC#178]

BASEURL=http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-[.]&dt=[.]&lmt=[.]&alt_color=FFF8DC&format=120x600_as&output=html&correlator=[.]&channel=[.]&url=http%3A%2F%2Fdomain.tld%2F&color_bg=FFF8DC&color_text=000000&color_link=CC0000&color_url=008000&color_border=FFF8DC&ad_type=text&cc=1450&ga_vid=[.].[.]&ga_sid=[.]&ga_hid=[.]&flash=9&u_h=900&u_w=1440&u_ah=866&u_aw=1440&u_cd=32&u_tz=60&u_java=true

ORIGURL=http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub- . and so on.

[DOC#180]

[.]

[DOC_google_ads_frame1]

BASEURL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub- . and so on.

ORIGURL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub- . and so on.

[DOC_iframe]

BASEURL=about:blank

ORIGURL=about:blank

[DOC#620]

BASEURL=http://domain.tld/

ORIGURL=

[DOC#609]

BASEURL=http://domain.tld/

ORIGURL=

[DOC#301]

BASEURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

ORIGURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

[DOC#300]

BASEURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

ORIGURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

[DOC#302]

BASEURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

ORIGURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

========== E O F ==========


My job is to clean up ALL URL files in the LAN from ALL unnecessary and unwanted mess, especially since there could be hidden links to privacy-breaking or even law-breaking target sites.

The only part to keep is this:



========== *.URL ==========

[InternetShortcut]

URL=http:// domain.tld/?x=a&y=b .

IconFile=C:\icon.ico

IconIndex=0

Modified=E044D72C3B0DCE013E

========== E O F ==========



Anyway, you don't have to do my job, though help is highly appreciated, of course. I just have to revitalize some rusted areas in my brain -- step by step. Therefore, all your hints do help me a lot, already! So thanks, again, so far!

I'll go on reading the other answers to the thread tomorrow.

So standby, if you want to.

foxidrive

unread,
May 4, 2013, 10:19:20 PM5/4/13
to
On 5/05/2013 03:56, Acamas wrote:
> My job is to clean up ALL URL files in the LAN from ALL unnecessary and unwanted mess, especially since there could be hidden links to privacy-breaking or even law-breaking target sites.
>
> The only part to keep is this:
>
>
>
> ========== *.URL ==========
>
> [InternetShortcut]
>
> URL=http:// domain.tld/?x=a&y=b .
>
> IconFile=C:\icon.ico
>
> IconIndex=0
>
> Modified=E044D72C3B0DCE013E
>
> ========== E O F ==========


This seems to work here - place the computer IP address or names in computerlist.txt in the format
"\\computer123\share" without the quotes, one per line, and ensure you have permissions to access them.

Test it on a sample of your URL files to see if it does what you need.

@echo off
for /f "delims=" %%a in (computerlist.txt) do (
pushd "%%a"
for /f "delims=" %%b in ('dir *.url /b /s /a-d') do (
findstr /i /l "[InternetShortcut] URL= IconFile= IconIndex= Modified=" <"%%b" >"%%~nb.tmp"
move /y "%%~nb.tmp" "%%b" >nul
)
popd
)



If you use this portion of the above batch file then it will process only the URL files in the current
directory and below.

@echo off
for /f "delims=" %%b in ('dir *.url /b /s /a-d') do (
findstr /i /l "[InternetShortcut] URL= IconFile= IconIndex= Modified=" <"%%b" >"%%~nb.tmp"
move /y "%%~nb.tmp" "%%b" >nul
)




--
foxi

Todd Vargo

unread,
May 4, 2013, 11:48:21 PM5/4/13
to
On 5/4/2013 1:56 PM, Acamas wrote:

> I did. I tried different GUI editors, e.g. Don Ho's notepad-plus-plus which handles nearly everything. Nevertheless, opening a URL file directly from notepad++ also gives back an 'invalid file format' error.
>
> However, meanwhile I've got it: It's not the editor, which causes trouble. It's just about the way you open an URL file.
> - Windows --> open --> editor --> open --> URL file --> error.
> - Console --> open --> editor --> open --> URL file --> correctly opens the URL file.
> - Console --> open --> editor, AND URL file as a variable --> also correctly opens the URL file.
> - Windows --> RUN! --> editor, AND URL file as a variable --> also correctly opens the URL file.
> - Windows --> open --> LNK file that points to a URL file --> opens the target file -- which IS the URL file.

Open notepad and just drop a file on it. It works.

Acamas

unread,
May 5, 2013, 11:55:42 AM5/5/13
to
Just a SHORT reply. (More to come later.)



"foxidrive" <n...@this.address.invalid> wrote...



__________
| This seems to work here - place the computer IP address or names in computerlist.txt in the format "\\computer123\share" without the quotes, one per line, and ensure you have permissions to access them.
|
| Test it on a sample of your URL files to see if it does what you need.
|
| ========== FOX1.BAT ==========
| @echo off
| for /f "delims=" %%a in (computerlist.txt) do (
| pushd "%%a"
| for /f "delims=" %%b in ('dir *.url /b /s /a-d') do (
| findstr /i /l "[InternetShortcut] URL= IconFile= IconIndex= Modified=" <"%%b" >"%%~nb.tmp"
| move /y "%%~nb.tmp" "%%b" >nul
| )
| popd
| )
| ========== E O F ==========



The 1st part ("fox1.bat") I haven't yet tested.



__________
| If you use this portion of the above batch file then it will process only the URL files in the current directory and below.
|
| ========== FOX2.BAT ==========
| @echo off
| for /f "delims=" %%b in ('dir *.url /b /s /a-d') do (
| findstr /i /l "[InternetShortcut] URL= IconFile= IconIndex= Modified=" <"%%b" >"%%~nb.tmp"
| move /y "%%~nb.tmp" "%%b" >nul
| )
| ========== E O F ==========



The 2nd part ("FOX2.BAT") I HAVE tested:

- It affects all *.URL files in the current directory, incl. sub-directories.
- It keeps the lines that shell be kept.

- It cuts out next O_N_E text line following the lines to keep.
- It does NOT cut off ALL the rest but ONE line only.



Before:

========== TEST.URL ==========
[PartToKeep]
Line1=a
Line2=b

[PartToCut]
Line01=AA
Line02=BB
========== E O F ==========



After:

========== TEST.URL ==========
[PartToKeep]
Line1=a
Line2=b
Line01=AA
Line02=BB
========== E O F ==========



Thanks so far, and Standby.

Acamas

unread,
May 5, 2013, 12:06:00 PM5/5/13
to
"Todd Vargo" <tlv...@sbcglobal.netz> wrote.



__________
| Open notepad and just drop a file on it. It works.
¯¯¯¯¯¯¯¯¯¯

Really works!

Hence we have yet another way to open a URL or LNK file.

GREAT! Thanks!

foxidrive

unread,
May 5, 2013, 12:09:38 PM5/5/13
to
> The 2nd part ("FOX2.BAT") I HAVE tested:
>
> - It affects all *.URL files in the current directory, incl. sub-directories.
> - It keeps the lines that shell be kept.
>
> - It cuts out next O_N_E text line following the lines to keep.
> - It does NOT cut off ALL the rest but ONE line only.
>
>
>
> Before:
>
> ========== TEST.URL ==========
> [PartToKeep]
> Line1=a
> Line2=b
>
> [PartToCut]
> Line01=AA
> Line02=BB
> ========== E O F ==========
>
>
>
> After:
>
> ========== TEST.URL ==========
> [PartToKeep]
> Line1=a
> Line2=b
> Line01=AA
> Line02=BB
> ========== E O F ==========
>
>
>
> Thanks so far, and Standby.

Show me a real file, before and after. What you have shown above bears no resemblance to any URL file
that you have mentioned.

foxidrive

unread,
May 5, 2013, 12:16:12 PM5/5/13
to
On 6/05/2013 01:55, Acamas wrote:
> Just a SHORT reply. (More to come later.)
>
> __________
> | If you use this portion of the above batch file then it will process only the URL files in the current directory and below.
> |


@echo off
for /f "delims=" %%b in ('dir *.url /b /s /a-d') do (
findstr /i /r "^\[InternetShortcut\] ^URL= ^IconFile= ^IconIndex= ^Modified=" <"%%b" >"%%~nb.tmp"
move /y "%%~nb.tmp" "%%b" >nul
)


> The 2nd part ("FOX2.BAT") I HAVE tested:
>
> - It affects all *.URL files in the current directory, incl. sub-directories.
> - It keeps the lines that shell be kept.
>
> - It cuts out next O_N_E text line following the lines to keep.
> - It does NOT cut off ALL the rest but ONE line only.


Try the code above. The line starting with findstr has changed.



--
foxi

Acamas

unread,
May 5, 2013, 12:29:12 PM5/5/13
to
"Todd Vargo" <tlv...@sbcglobal.netz> wrote.

__________
| On 5/3/2013 2:01 PM, Acamas wrote:
| > [.] the "content" of a LNK file, i.e.
| > - path to the target,
| > - path to an alternative active directory (optional),
| > - keyboard shortcut (optional),
| > - window size (normal, maximized, minimized),
| > - comment (optional),
| > [.]
|
| That is correct, .lnk files are in a non-text format. You can extract
| information from them using vbscript's CreateShortcut method.
¯¯¯¯¯¯¯¯¯¯

To be honest, I have no idea of vbscript. I can put the World Formula into an EXCEL sheet, but don't ask me about vb!



__________
| Unfortunatly, you did not state what you are doing with the data [.]
¯¯¯¯¯¯¯¯¯¯

Actually, my job refers to the URL files I mentioned.

Regarding the LNK files, I have to.
- check the target URLs, and change them if necessary,
- change the path to special icon files for thousands of links, and
- add or edit comments as a quick info or help text for users.
That's it.

Acamas

unread,
May 5, 2013, 1:29:57 PM5/5/13
to
"foxidrive" <n...@this.address.invalid> wrote...



__________
| Show me a real file, before and after. What you have shown above bears no resemblance to any URL file that you have mentioned.
¯¯¯¯¯¯¯¯¯¯



First, here you have a "real" TEST-File:

Before:

========== TEST.URL ==========
[InternetShortcut]
IconIndex=0
IconFile=C:\WINNT\system32\url.dll
URL=http://duckduckgo.com/
Modified=003B929AA149CE0120
[DOC_iframe]
BASEURL=about:blank
ORIGURL=about:blank
========== E O F ==========

After:

========== TEST.URL ==========
[InternetShortcut]
IconIndex=0
IconFile=C:\WINNT\system32\url.dll
URL=http://duckduckgo.com/
Modified=003B929AA149CE0120
BASEURL=about:blank
ORIGURL=about:blank
========== E O F ==========




And now about a "real real" file...

But, plz, keep in mind: the URL files I have to clean up are all quite different.
- Some have a unnecessary [Default] section at the beginning. Others have no such section.
- They ALL have an [InternetShortcut] section to be kept.
- Most of them have the 4 Lines as mentioned above, some have only the URL line.
- Sometimes the order of these 4 lines differs.
- Some have no additional content at all. Others have loads of rubbish.
The "real real file" below is just ONE example out of thousands.

My job is to make sure that ALL possible content -- except only the [InternetShortcut] section -- will be removed.

Actually, this means to...
- read out and safe the [InternetShortcut] section,
- delete the complete file,
- create a new (empty) file with the same (old) name, and
- restore and safe the content of the old [InternetShortcut] section into the "new" file.

So this is a "real real file"...
- In the lines with a leading triple "asterisk" (***) I "anonymized the value of the variable, e.g. "certainname.com" to a general "domain.tld".
- In the lines with a leading triple "degree" (°°°) I cut out certain numbers that could be identified.
- Lines with NO leading triple *** or °°° I didn't modify at all.

Before:

========== TEST.URL ==========
[DEFAULT]
***BASEURL=http://domain.tld/
[InternetShortcut]
***URL=http:// domain.tld/?x=a&y=b .
***IconFile=C:\icon.ico
IconIndex=0
Modified=E044D72C3B0DCE013E
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[DOC#178]
°°°BASEURL=http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-[...]&dt=[...]&lmt=[...]&alt_color=FFF8DC&format=120x600_as&output=html&correlator=[...]&channel=[...]&url=http%3A%2F%2Fdomain.tld%2F&color_bg=FFF8DC&color_text=000000&color_link=CC0000&color_url=008000&color_border=FFF8DC&ad_type=text&cc=1450&ga_vid=[...].[...]&ga_sid=[...]&ga_hid=[...]&flash=9&u_h=900&u_w=1440&u_ah=866&u_aw=1440&u_cd=32&u_tz=60&u_java=true
°°°ORIGURL=http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-[...]
[DOC#180]
°°°[...]
[DOC_google_ads_frame1]
°°°BASEURL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-[...]
°°°ORIGURL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-[...]
[DOC_iframe]
BASEURL=about:blank
ORIGURL=about:blank
[DOC#620]
***BASEURL=http://domain.tld/
ORIGURL=
[DOC#609]
***BASEURL=http://domain.tld/
========== E O F ==========

After:

Note:
- It's tested with FOX2.BAT -- not yet your newer lines!
- All the section headers except [InternetShortcut] have gone -- the headers only!

========== TEST.URL ==========
BASEURL=http://domain.tld/
[InternetShortcut]
URL=http:// domain.tld/?x=a&y=b
IconFile=C:\icon.ico
IconIndex=0
Modified=E044D72C3B0DCE013E
BASEURL=http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub
{...}&dt={...}&lmt={...}&alt_color=FFF8DC&format=120x600_as&output=html&correlator={...}&channel={...}&url=http%3A%2F%2Fdomain.tld%2F&color_bg=FFF8DC&color_text=000000&color_link=CC0000&color_url=008000&color_border=FFF8DC&ad_type=text&cc=1450&ga_vid={...}.{...}&ga_sid={...}&ga_hid={...}&flash=9&u_h=900&u_w=1440&u_ah=866&u_aw=1440&u_cd=32&u_tz=60&u_java=true
ORIGURL=http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-{...}
BASEURL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-{...}
ORIGURL=http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-{...}
BASEURL=about:blank
ORIGURL=about:blank
BASEURL=http://domain.tld/
ORIGURL=
BASEURL=http://domain.tld/
ORIGURL=
BASEURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html
ORIGURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html
BASEURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html
ORIGURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html
BASEURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html
ORIGURL=http://pagead2.googlesyndication.com/pagead/s/iframes_api_loader.html

Acamas

unread,
May 5, 2013, 1:42:13 PM5/5/13
to
"foxidrive" <n...@this.address.invalid> wrote...


| ========== FOX3.BAT ==========
| @echo off

| for /f "delims=" %%b in ('dir *.url /b /s /a-d') do (

| findstr /i /r "^\[InternetShortcut\] ^URL= ^IconFile= ^IconIndex= ^Modified=" <"%%b" >"%%~nb.tmp"

| move /y "%%~nb.tmp" "%%b" >nul

| )

| ========== E O F ==========
|

| Try the code above. The line starting with findstr has changed.

¯¯¯¯¯¯¯¯¯¯



Y E A H ! That's it! G R E A T !

THANK YOU VERY MUCH!

I'm out now for a while, family is waiting...

But I'll come back later at night or tomorrow.

I'll have a look at Todd's lines too. I have to learn all that stuff step by step.

Thanks again -- to all of you!

Todd Vargo

unread,
May 5, 2013, 5:17:08 PM5/5/13
to
On 5/4/2013 1:15 AM, Todd Vargo wrote:
> On 5/4/2013 12:51 AM, Todd Vargo wrote:
>> On 5/3/2013 2:01 PM, Acamas wrote:
> <snip>
>>> Now, my job is to write a batch file to automatically remove all these
>>> additional entries in all relevant URL files in a LAN, beginning with
>>> a W2K machine/system, and I guess I'm not the first one with this
>>> task. Therefore, I ended up here, looking for help. ;-)
>>
>> Actually, the only line in the file that needs to be retained is the
>> "url=" line. All other lines are just useless frill.
>
> If you are interested in pruning to just the "url=" lines, try the
> following batch on a test folder with some sample files.
>
> @echo off
> for %%A in (*.url) do (
> for /f "delims=" %%B in ('find /i "url=" ^<"%%A"') do (
> echo %%B > %%A
> )
> )

After seeing the real files, the ORIGURL= and BASEURL= lines would be
included using the code above. The following mod will remove them.

@echo off
for %%A in (*.url) do (
for /f "delims=" %%B in ('findstr/b/i "url="^<"%%A"') do (
echo %%B > %%A
)
)2>nul

Todd Vargo

unread,
May 5, 2013, 6:27:09 PM5/5/13
to
Doing more testing with this batch on a larger set of files, I
discovered that findstr freezes on certain files. On examination of the
files that it freezes on, they seem to have a trailing null character at
the end of the file. It is impossible to recall which version of IE
created these since I have used every version since IE 3.0.

I suppose this is a known feature of finstr, but its new to me. :(

billious

unread,
May 5, 2013, 9:22:06 PM5/5/13
to
tried

'type "%%A"^|findstr /b /i "url="'

?

Todd Vargo

unread,
May 5, 2013, 11:32:59 PM5/5/13
to
On 5/5/2013 9:22 PM, billious wrote:

> tried
>
> 'type "%%A"^|findstr /b /i "url="'
>
> ?
>

That solves the problem.

foxidrive

unread,
May 6, 2013, 1:23:09 AM5/6/13
to
On 6/05/2013 08:27, Todd Vargo wrote:

> Doing more testing with this batch on a larger set of files, I
> discovered that findstr freezes on certain files. On examination of the
> files that it freezes on, they seem to have a trailing null character at
> the end of the file. It is impossible to recall which version of IE
> created these since I have used every version since IE 3.0.
>
> I suppose this is a known feature of finstr, but its new to me. :(

findstr hangs in various modes when the last line has no trailing CR/LF



Google for this at Stack Overflow

"What are the undocumented features and limitations of the Windows FINDSTR command"

It's a good resource - findstr is a cow.



--
foxi

foxidrive

unread,
May 6, 2013, 1:14:50 AM5/6/13
to
On 6/05/2013 08:27, Todd Vargo wrote:

> Doing more testing with this batch on a larger set of files, I
> discovered that findstr freezes on certain files. On examination of the
> files that it freezes on, they seem to have a trailing null character at
> the end of the file. It is impossible to recall which version of IE
> created these since I have used every version since IE 3.0.
>
> I suppose this is a known feature of finstr, but its new to me. :(

0 new messages