This is a script for a Button or Menu to safety remove a drive.
To use this three external programs are required.
In DOpus program folder (which can be changed) create a folder named "Portable". This is the place where I put all portable programs I use a lot in DOpus.
Copy and Past the script into a Button or Menu, navigate into a ejectable drive and press the newly created button to safety remove this drive.
Parts of this script are based on another script which can be found here (unfortunately I don't find it just right now, but someone will find out the url...)
Requirements (Sources are available on the their pages):
EjectMedia.exe and RemoveDrive.exe http://www.uwe-sieber.de
NotifU.exe (Bubble notifier) http://www.paralint.com/projects/notifu/
NOTE: Please use 32Bit versions if you can. Every 32Bit Program runs also on 64Bit System, but not vice versa!
@script JScript
// This example below (the four line only) are working well
// @set driveletter = {sourcepath$|\}
// Go /mycomputer
// /home\Portable\RemoveDrive.exe "{$driveletter}" -h -e -b -a
// /home/Portable\ShowBalloonTip.exe 1 6 "Ejected drive "+{$driveletter } "Ejected drive "+{$driveletter }
function removeDrive(driveletter, command) {
var wsh = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.DriveExists(driveletter + ":")) {
//var dopusdatapath = DOpus.aliases("dopusdata").path;
var dopushome = DOpus.aliases("home").path;
if (fso.getDrive(driveletter + ":").DriveType == 4) {
// cdrom
var result = wsh.Run("\"" + dopushome + "\\Portable\\EjectMedia.exe\" " + driveletter + ":", 0, true);
if (result == 0) {
command.RunCommand("\"/home\\Portable\\notifu.exe\" /p \"Media Eject Success (" + driveletter + ":)\" /m \"The media in drive " + driveletter + ": was successfully ejected.\"");
} else {
command.RunCommand("\"/home\\Portable\\notifu.exe\" /p \"Media Eject Error (" + driveletter + ":)\" /m \"The media in drive " + driveletter + ": could not be ejected (device probably in use by another application).\"");
}
} else {
// other
var result = wsh.Run("\"" + dopushome + "\\Portable\\RemoveDrive.exe\" " + driveletter + ":", 0, true);
if (result == 0) {
command.RunCommand("\"/home\\Portable\\notifu.exe\" /p \"Hardware Removal Success (" + driveletter + ":)\" /m \"The device that was connected to drive " + driveletter + ": was successfully dismounted.\"");
} else {
command.RunCommand("\"/home\\Portable\\notifu.exe\" /p \"Hardware Removal Error (" + driveletter + ":)\" /m \"The device that is connected to drive " + driveletter + ": could not be dismounted (device probably in use by another application).\"");
}
}
} else {
command.RunCommand("\"/home\\Portable\\notifu.exe\" /p \"Drive Access Error (" + driveletter + ":)\" /m \"The specified drive " + driveletter + ": can not be accessed or does not exist.\"");
}
}
// removeDrive("D", clickData.func.command);
function OnClick(clickData) {
found=false;
for (var eListers = new Enumerator(DOpus.listers); !eListers.atEnd(); eListers.moveNext())
{
for (var eTabs = new Enumerator(eListers.item().tabs); !eTabs.atEnd(); eTabs.moveNext())
{
//A foreground lister is the active Lister Window
// The source tab is the currently selected tab
if (eListers.item().foreground==true && eTabs.item().source==true) {
var sourcepath = eTabs.item().path;
// The Drive number 1=A 2=B 3=C ...
var drivenum = String(eTabs.item().path.drive);
// ASCII 65=@. Thus for example Drive C is drivenum 3+64= ASCII 'C'
var drive = String.fromCharCode(64+eTabs.item().path.drive);
if (drivenum>0) {
//clickData.func.command.RunCommand("\"/home\\Portable\\notifu.exe\" /t info /p \"Drive\" /m \"Drive: " + drive + "\"");
clickData.func.command.RunCommand("Go /mycomputer");
removeDrive( drive, clickData.func.command) ;
found=true;
}
}
}
}
if (found==false) {
clickData.func.command.RunCommand("\"/home\\Portable\\notifu.exe\" /t warn /p \"Drive not found\" /m \"Drive not ejected. Perhaps it is missing a drive letter, UNC Share or FTP-Connection. \"");
}
}
SafetyRemove.zip (464 KB)