Jump to content
Sign in to follow this  
stev379

Right click Menu - Pass clicked folder as input

Recommended Posts

stev379

I have a script that reads a mapped network drive path and returns the full UNC path. I know how to add it as an item on the right click menu, but I don't know how to pass the folder name and it's mapped drive letter to the script.

How can I right click a folder in Windows Explorer, and select my script from the right click menu while passing the clicked on folder's mapped drive letter and subpath to the folder to the script?

Example: X: is mapped to \\server1\sourcedir1\sourcedir2

I right click sourcedir4 located at X:\sourcedir3\sourcedir4

The expected return is \\server1\sourcedir1\sourcedir2\sourcedir3\sourcedir4

Registry entries to add script to the right click menu (script is stored in System32).

;Folders
RegWrite("HKCR\Folder\Shell\GetDrivePath", "GetPath", "REG_SZ", "GetDrivePath.exe")
;Files - Will complete and rename a secondary app (if needed) for just files once the folder piece is working
;RegWrite("HKCR\*\Shell\GetDrivePath", "GetPath", "REG_SZ", "GetDrivePath.exe")oÝ÷ Ù'+m¢·u©¦v¸¯zW­µêðØh¯­­²æߢW^®­)Üç^u«­¢+ØÀÌØíI%Y}U11AQ ô%¹ÁÕÑ  ½à ÅÕ½ÐíÐÉ¥ÙAÑ ÅÕ½Ðì°ÅÕ½Ðí¹ÑȵÁÁÉ¥Ù¹ÁÑ Ñ¼ÉÑÕɸѡձ°U9ÁÑ ÅÕ½Ðì¤((íAÉÍÑ¡ÀÌØíI%Y}U9
}AQ Ѽɽ¹±äÑ¡¥ÉÍÐÈ¡ÉѽÉÌÌ `è¤(ìQ¡¸Ñ¡Éµ½ÙÁÑ ¬½ÉÉÁ½ÉÑ¥¹ÉÍÕ±Ñ̸(ÀÌØíI%Y}1QQHôMÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíI%Y}U11AQ °MÑÉ¥¹1¸ ÀÌØíI%Y}U11AQ ¤´È¤(ÀÌØíAQ ôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíI%Y}U11AQ °È¤(ÀÌØíI%Y1QQI}U9
}AQ ôÉ¥Ù5ÁÐ ÀÌØíI%Y}1QQH¤(ÀÌØíI%Y}U9
}AQ ôÀÌØíI%Y1QQI}U9
}AQ µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØíAQ )5Í ½à À°ÌäìÌäì°ÀÌØíI%Y}U9
}AQ µÀì
I1µÀì
I1µÀì|($$$ÅÕ½ÐíAÑ Ý¥±°ÁÉ¥¹ÐѼѡÍɸÌͽ¹ÌÑÈå½Ô±¥¬=,¸ÅÕ½Ðì¤((íAÕÍÌͽ¹Ì¹ÁÉ¥¹ÐѼѡÍɸ´ÕÉͽȵÕÍнÕͽ¸¥Ñ±¥±¸)ͱÀ ÌÀÀÀ¤)M¹ ÀÌØíI%Y}U9
}AQ

Share this post


Link to post
Share on other sites
stev379

Anyone have any suggestions on how to right click a folder and return its path as input to a script?

Share this post


Link to post
Share on other sites
martin

I have a script that reads a mapped network drive path and returns the full UNC path. I know how to add it as an item on the right click menu, but I don't know how to pass the folder name and it's mapped drive letter to the script.

How can I right click a folder in Windows Explorer, and select my script from the right click menu while passing the clicked on folder's mapped drive letter and subpath to the folder to the script?

Example: X: is mapped to \\server1\sourcedir1\sourcedir2

I right click sourcedir4 located at X:\sourcedir3\sourcedir4

The expected return is \\server1\sourcedir1\sourcedir2\sourcedir3\sourcedir4

Registry entries to add script to the right click menu (script is stored in System32).

;Folders
RegWrite("HKCR\Folder\Shell\GetDrivePath", "GetPath", "REG_SZ", "GetDrivePath.exe")
;Files - Will complete and rename a secondary app (if needed) for just files once the folder piece is working
;RegWrite("HKCR\*\Shell\GetDrivePath", "GetPath", "REG_SZ", "GetDrivePath.exe")oÝ÷ Ù'+m¢·u©¦v¸¯zW­µêðØh¯­­²æߢW^®­)Üç^u«­¢+ØÀÌØíI%Y}U11AQ ô%¹ÁÕÑ  ½à ÅÕ½ÐíÐÉ¥ÙAÑ ÅÕ½Ðì°ÅÕ½Ðí¹ÑȵÁÁÉ¥Ù¹ÁÑ Ñ¼ÉÑÕɸѡձ°U9ÁÑ ÅÕ½Ðì¤((íAÉÍÑ¡ÀÌØíI%Y}U9
}AQ Ѽɽ¹±äÑ¡¥ÉÍÐÈ¡ÉѽÉÌÌ `è¤(ìQ¡¸Ñ¡Éµ½ÙÁÑ ¬½ÉÉÁ½ÉÑ¥¹ÉÍÕ±Ñ̸(ÀÌØíI%Y}1QQHôMÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØíI%Y}U11AQ °MÑÉ¥¹1¸ ÀÌØíI%Y}U11AQ ¤´È¤(ÀÌØíAQ ôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíI%Y}U11AQ °È¤(ÀÌØíI%Y1QQI}U9
}AQ ôÉ¥Ù5ÁÐ ÀÌØíI%Y}1QQH¤(ÀÌØíI%Y}U9
}AQ ôÀÌØíI%Y1QQI}U9
}AQ µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØíAQ )5Í ½à À°ÌäìÌäì°ÀÌØíI%Y}U9
}AQ µÀì
I1µÀì
I1µÀì|(ÅÕ½ÐíAÑ Ý¥±°ÁÉ¥¹ÐѼѡÍɸÌͽ¹ÌÑÈå½Ô±¥¬=,¸ÅÕ½Ðì¤((íAÕÍÌͽ¹Ì¹ÁÉ¥¹ÐѼѡÍɸ´ÕÉͽȵÕÍнÕͽ¸¥Ñ±¥±¸)ͱÀ ÌÀÀÀ¤)M¹ ÀÌØíI%Y}U9
}AQ
To add a new context menu item to explorer for a drive

In Regedit find HKET_CLASSES_ROOT\Folder\shell

(note \Folder not \.Folder)

Click on the shell folder, right click, choose new|key to add a new key to shell. Call it the item to be displayed in the menu.

click on the new key and, right click and choose new|key. This time call the key command.

click on the Default entry in the command folder, right click and choose modify. Type in the executable to be run (you might need to give the full path) and add a space then %1. The %1 means that the drive letter will be passed as a parameter to the exe.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
stev379

To add a new context menu item to explorer for a drive

In Regedit find HKET_CLASSES_ROOT\Folder\shell

(note \Folder not \.Folder)

Click on the shell folder, right click, choose new|key to add a new key to shell. Call it the item to be displayed in the menu.

click on the new key and, right click and choose new|key. This time call the key command.

click on the Default entry in the command folder, right click and choose modify. Type in the executable to be run (you might need to give the full path) and add a space then %1. The %1 means that the drive letter will be passed as a parameter to the exe.

Thanks for the tip! I've made the corrections in the regsitry.

How is that parameter passed to the scipt...how do I assign a variable to it?

Share this post


Link to post
Share on other sites
martin

Thanks for the tip! I've made the corrections in the regsitry.

How is that parameter passed to the scipt...how do I assign a variable to it?

If you mean how do you read that parameter in your script then look in the help for "running scripts". The first parameter is $CmdLIne[1] so you can use something like

$selectedDriveorFolder = $CmdLine[1]

$CmdLine is a global array created by AutoIt so you musn't declare it or try to define it.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
stev379

If you mean how do you read that parameter in your script then look in the help for "running scripts". The first parameter is $CmdLIne[1] so you can use something like

$selectedDriveorFolder = $CmdLine[1]

$CmdLine is a global array created by AutoIt so you musn't declare it or try to define it.

I spend a lot of time in the help file (note my minimal postings :D ) and recommend it to anyone using AutoIT. I could have read it and I'm not sure this issue would have clicked for me.

Thank you very much for the help. We now have an easy way for users (in XP) to get the full UNC path to send to the Help Desk techs. With mapped drives for different departments and users not fully understanding how to read a Windows Explorer window, it's difficult for the techs to get info they need sometimes.

$DRIVE_FULLPATH = $CmdLine[1]


;Parse the $DRIVE_UNC_PATH to read only the first 2 charactors as (  X:  ) 
; Then add the removed path back before reporting results.
$DRIVE_LETTER = StringTrimRight($DRIVE_FULLPATH, StringLen($DRIVE_FULLPATH)-2)
$PATH = StringTrimLeft($DRIVE_FULLPATH, 2)
$DRIVELETTER_UNC_PATH = DriveMapGet($DRIVE_LETTER)
$DRIVE_UNC_PATH = $DRIVELETTER_UNC_PATH & "\" & $PATH
MsgBox(0,'', $DRIVE_UNC_PATH & @CRLF & @CRLF & _
             "Path will print to the screen 3 seconds after you click OK.")

;Pause 5 seconds and print to the screen - cursor must be focused on a editable field.
;Users can use this time to open a new email window or Notepad or any editable field.
sleep(5000)
Send($DRIVE_UNC_PATH)

Share this post


Link to post
Share on other sites
stev379

If you mean how do you read that parameter in your script then look in the help for "running scripts". The first parameter is $CmdLIne[1] so you can use something like

$selectedDriveorFolder = $CmdLine[1]

$CmdLine is a global array created by AutoIt so you musn't declare it or try to define it.

Just extra info for reference should anyone read this in the future. (Time machine!)

I found a drawback to this method last night. It doesn't get the full path if there is a space in the path. I tried adjusting quotes and using FileGetShortName, but $CmdLine[1] is only getting the path up to the first space so using either method only applies to a partial path. I used $CmdLine[1] & " " & $CmdLine[2] ...[3] and so on, but this gets messy and doesn't help when we don't know how many spaces might be in any path.

I reviewed the "Running Scripts" section of the Help File some more and found that $CmdLineRaw will get the entire path regardless of the spaces.

Thanks again to Martin for the original tip!

Edited by stev379

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.