GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Need help with a button!

Is it possible to create a button that share the active folder...and another
one to delete this share?

Here's a button (see here for what to do with the XML):

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" textcol="none" type="three_button"> <label>Share</label> <icon1>#default:mapnetworkdrive</icon1> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Share</label> <tip>Share the current folder</tip> <icon1>#default:mapnetworkdrive</icon1> <function type="batch"> <instruction>@admin</instruction> <instruction>net share {sourcepath$|nopath}={sourcepath$|noterm}</instruction> <instruction>pause</instruction> </function> </button> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>UnShare</label> <tip>Un-share the current folder</tip> <icon1>#disconnectnetworkdrive</icon1> <function type="batch"> <instruction>@admin</instruction> <instruction>net share {sourcepath$|noterm} /DELETE</instruction> <instruction>pause</instruction> </function> </button> </button>

If you left-click the button then the current folder will be shared.

If you right-click it then the current folder will be un-shared.

It does this using the Windows "net share" command. It opens a DOS window so you can see if it was successful or not.

Note: Shares created using "net share" do not seem to update the folder icon overlay until Opus is restarted.

Thanks! That's exactly what I need!

It doesn't work in the root folder (

It uses the folder's name as the name of the share. In the root folder that means it will try to create a share called C:\ or similar, which isn't a valid share name.

That was actually a good thing since the "Un-Share" button deleted the share by path (not by share name) and might have deleting the C$ (etc.) administrative shares instead of the ones you'd created using the Share button.

Here's an alternative version of the button which asks you for the share name to create / delete, and deletes the shares by name instead of by path:

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" textcol="none" type="three_button"> <label>Share</label> <icon1>#default:mapnetworkdrive</icon1> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Share</label> <tip>Share the current folder</tip> <icon1>#default:mapnetworkdrive</icon1> <function type="batch"> <instruction>@admin</instruction> <instruction>net share &quot;{dlgstringS|Share name to create:|{sourcepath$|nopath}}&quot;={sourcepath$|noterm}</instruction> <instruction>pause</instruction> </function> </button> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>UnShare</label> <tip>Un-share the current folder</tip> <icon1>#disconnectnetworkdrive</icon1> <function type="batch"> <instruction>@admin</instruction> <instruction>net share &quot;{dlgstringS|Name of share to delete:|{sourcepath$|nopath}}&quot; /DELETE</instruction> <instruction>pause</instruction> </function> </button> </button>
It'll default to the same names as before but you can type over them.

Great! Thank You!!! Maybe the second button is even better! But I resolved the problem with the first one:
instead of using {sourcepath$|nopath} I used this:

for /F "delims=" %%I
in ("%CD%") do set mydir=%%~nI
if not defined MyDir set mydir=%cd:~0,1%
net share "%mydir%"={sourcepath$|noterm}
pause
.....works perfectly!
Anyway,thank you for help!