Jump to content


Photo

Crazy Scripting : SecretFolder 10L


  • Please log in to reply
30 replies to this topic

#1 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 19 November 2010 - 11:11 AM

Creates a hidden folder like C:\Documents and Settings\%A_UserName%\My Documents\...
which will be inaccesible from 'windows explorer' unless this script is run.

Thanks to Fin for Folder names with a trailing dot?
Thanks to Sean for DefineDosDevice()

Usage: Run the script and use the hotkey ^#x ( Ctrl+Win+X ) to access the secret folder.

[*:3jepp40q]Note1: If drive letter 'X' is unavailable in your filesystem, replace all the 'red-marked'
with any free drive letter.

[*:3jepp40q]Note2: Mapped drive 'X:' will be available only when this script is running and will be
unmapped when the script quits.
Loop %A_MyDocuments%,1                    ; [color=indigo]SecretFolder 10L - By SKAN / 19-Nov-2010[/color]
  MyDoc := A_LoopFileShortPath            ; www.autohotkey.com/forum/viewtopic.php?t=65131
If !FileExist( hiddenFolder := MyDoc "\7154~1" ) {
    FileCreateDir, \\?\%MyDoc%\...
    FileSetAttrib, +SH, \\?\%MyDoc%\...
} DllCall( "DefineDosDevice", UInt,0, Str,"[color=darkred]X[/color]:", Str,hiddenFolder )
OnExit, QuitScript 

^#[color=darkred]x[/color]::Run [color=darkred]X[/color]:\,,Max ;            // end of auto-execute section //

QuitScript:
 ExitApp, % DllCall( "DefineDosDevice", UInt,1|2, Str,"[color=darkred]X[/color]:", Int,0 )


#2 tomoe_uehara

tomoe_uehara
  • Members
  • 2073 posts

Posted 19 November 2010 - 06:09 PM

I'm sorry, but I can't see the 'red-marked' code :shock:

#3 fincs

fincs
  • Fellows
  • 1528 posts

Posted 19 November 2010 - 07:20 PM

;...
} DllCall( "DefineDosDevice", UInt,0, Str,"[color=red]X:[/color]", Str,hiddenFolder )
;...
 ExitApp, % DllCall( "DefineDosDevice", UInt,1|2, Str,"[color=red]X:[/color]", Int,0 )
Better now?

#4 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 20 November 2010 - 09:18 PM

Following is what I will settle for:

I call the following script from my Always-Running-Script with a hotkey:

#SingleInstance, Ignore
Menu, Tray, Icon, Shell32.dll, 4
DllCall( "DefineDosDevice", UInt,0, Str,"X:", Str,"[color=darkred]C:\DOCUME~1\SURESH\MYDOCU~1\7154~1[/color]" )
OnExit, QuitScript
RunWait, %A_WinDir%\Explorer.exe X:\
QuitScript:
 ExitApp,% DllCall( "DefineDosDevice", UInt,1|2, Str,"X:", Int,0 )

Closing the Explorer GUI quits the script and unmaps the drive.
Quitting the script ( from Tray-menu ) unmaps the drive which automatically closes the Explorer GUI. ( atleast for me in XP SP3 )

#5 tomoe_uehara

tomoe_uehara
  • Members
  • 2073 posts

Posted 21 November 2010 - 01:52 PM

Better now?

Thank you fincs :wink:

#6 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 23 November 2010 - 02:24 PM

RunWait, %A_WinDir%\Explorer.exe X:\

The above does not quit the script properly.
I now use a 'Copy of Explorer.exe' instead

RunWait, %A_WinDir%\Copy of explorer.exe X:\


#7 JoeSchmoe

JoeSchmoe
  • Members
  • 304 posts

Posted 23 November 2010 - 05:40 PM

Hi Skan,

Many thanks for posting this. It looks great. Any chance of providing a version with more comments? I'm not familiar (as I'm sure many others aren't) with the DLLs you call, and am unsure how "\7154~1" comes in, etc.

#8 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 23 November 2010 - 08:21 PM

Any chance of providing a version with more comments?


Let me try to explain instead.

SUBST.EXE is a console utility that allows us to substitute a drive letter for a given path

For example we can map drive "M:" for "My Documents" like:
SUBST M: "C:\Documents and Settings\Suresh\My Documents"
..and later.. to remove the mapping, we may do it like:
SUBST M: /D

Posted Image

I'm not familiar (as I'm sure many others aren't) with the DLLs you call


DefineDosDevice() is like the API form of SUBST.EXE console utility, and the equivalent DllCalls would be:

DllCall( "DefineDosDevice", UInt,0, Str,"M:", Str,[color=darkred]A_MyDocuments[/color] ) ; Map M: Drive
DllCall( "DefineDosDevice", UInt,[color=darkred]3[/color], Str,"M:", Str,"" )            ; Unmap M: Drive


The purpose of this script is to create a folder named ... in 'My Documents' which will be inaccessible from 'Windows Explorer'

Posted Image

Even using the ShortPath 'C:\DOCUME~1\SURESH\MYDOCU~1\7154~1' on Windows Explorer's address bar would not help, because it will try to retrieve and use the LongPath and fail. For eg: Environment variable TEMP contains a ShortPath like: C:\DOCUME~1\Suresh\LOCALS~1\Temp
But if you type %TEMP% and press Enter in Windows Explorer's address bar, you will see that it automatically de-references to LongPath.

am unsure how "\7154~1" comes in


7154~1 is the ShortPath for ...

To retrieve the ShortPath for any file/folder, do a DIR /X from the console window. The following screenshot should explain how the folder can be created/removed from a console window:

Posted Image

From above screenshot we see that creating or deleting the folder is easy... but to move files in and out - or to backup the content to .zip or an optical disk, we really need a proper path... and hence the drive mapping is required.

:)

#9 Wicked - Guest

Wicked - Guest
  • Guests

Posted 23 November 2010 - 08:41 PM

Genius... Simply genius. :). You've once again blown me away, SKAN.

#10 health901

health901
  • Members
  • 8 posts

Posted 27 November 2010 - 11:03 AM

FileSetAttrib, +SH, \\?\%MyDoc%\...


this command makes no result.

#11 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 27 November 2010 - 11:08 AM

What is your system's OS? Works for me in XP SP3.

#12 health901

health901
  • Members
  • 8 posts

Posted 27 November 2010 - 11:25 AM

XP SP3 too.

But it does not work. Either when I set this folder to hidden in explorer.

I had tried "attrib +s +h" in cmd ,nothing happend but an error: folder can't find

#13 fincs

fincs
  • Fellows
  • 1528 posts

Posted 27 November 2010 - 11:46 AM

Windows 7 here. The short name of "..." is A535~1 instead.
This script works perfectly after doing the aforementioned change. It doesn't even need admin privileges :)
BTW, the hidden folder does not show up on Explorer even after unchecking "Hide protected OS files".

#14 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 27 November 2010 - 11:05 PM

XP SP3 too..I had tried "attrib +s +h" in cmd ,nothing happend but an error: folder can't find


Try the following and let me know if you see SHD in Message Box.

Folder := A_MyDocuments "\[color=darkred]...Test...[/color]"
FileCreateDir, \\?\%Folder%
FileSetAttrib, +SH, \\?\%Folder%
MsgBox,% "Folder:`t" Folder "`nAttrib:`t" FileExist( "\\?" Folder )

Windows 7 here. The short name of "..." is A535~1 instead.


Many thanks for the useful feedback. :)

#15 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 27 November 2010 - 11:28 PM

It is problematic to retrieve path for unconventionally named file/folder with Loop, FilePattern.
In such cases, ShortPath() would help:

ShortPath( UnCon ) {    ; Derives ShortPath fm Unconventional Path | By SKAN / 28-Nov-2010
 Loop, Parse, UnCon, \/ ;           www.autohotkey.com/forum/viewtopic.php?p=402714#402714
  SP .= A_LoopField ? "\" A_LoopField :
 SP := "\\?" SP
 While FileExist( SP )
   Loop %SP%, 1
     Ix := A_Index, SP := A_LoopFileDir, FP := A_LoopFileShortName "\" FP
 StringTrimRight, FP, FP, 1
Return Ix ? SP "\" FP :
}

Typical usage example:

Loop %A_MyDocuments%\*.*, 2 ; Listing subfolders in 'My Documents'
 If A_LoopFileShortPath
    Folders .= A_LoopFileLongPath "`n"
 Else
    Folders .= [color=darkred]ShortPath( A_LoopFileDir "\" A_LoopFileShortName )[/color] "`n"

MsgBox, % Folders

Note:
FileCreateDir accepts any path and all it needs is the prefix" "\\?\"
But FileRemoveDir works only with a ShortPath.