/* Date: 03/14/2003 Programmer: Rich@AutoTraker.com www.autotraker.com Description: This program will produce a directory (C:\Drives) which you can add to your DeskTop toolbar to give you explorer shortcuts to all the drives on your machine. Usage: compile program using command line: compile DriveIcons.prg build EXE using command line: build DriveIcons.pro to DriveIcons Then Run this Exe. Right click on Desktp toolbar and select "Toolbars" then "New Toolbar.." Find our new toolbar directory (C:\Drives) and select it. Now you have a new toolbar on your Desktop Toolbar that will give you shortcuts to all the drives on your machine. Dependencies: Windows Scripting Host Download latest version 5.6 at: http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/733/msdncompositedoc.xml */ clear #define DRIVE_FOLDER_PATH "C:\Drives" // build an Assoc array of drives and some other information a = new array() x = new OleAutoClient("Scripting.FileSystemObject") xx = x.drives for i = 0 to xx.count -1 b = new AssocArray() b["driveLetter"] = xx[i].driveLetter b["path"] = xx[i].path b["driveType"] = getDriveType(xx[i].driveType) a.add(b) endfor release object x x = NULL // delete the folder if it exists, so we can rebuild it x = new OleAutoClient("Scripting.FileSystemObject") if x.FolderExists(DRIVE_FOLDER_PATH) x.DeleteFolder(DRIVE_FOLDER_PATH) endif release object x x = NULL // make a new folder x = new OleAutoClient("Scripting.FileSystemObject") if not x.FolderExists(DRIVE_FOLDER_PATH) x.CreateFolder(DRIVE_FOLDER_PATH) endif release object x x = NULL // find all the persistant network drives that are not // connected at this time and add them to our drive array aDead = findDeadNetDrives() for i = 1 to aDead.size // ? aDead[i] b = new AssocArray() b["driveLetter"] = left(aDead[i],1) b["path"] = aDead[i]+"\" b["driveType"] = "Disconnected Network" a.add(b) endfor // get windows folder so we know where explorer is x = new OleAutoClient("Scripting.FileSystemObject") WinFolder = x.GetSpecialFolder(0).path release object x x = NULL // sort our array putting our drives in proper order a.sort() // flip though drives and build shortcuts for i = 1 to a.size WshShell = new OleAutoClient("Wscript.shell") // get information array from array of drives b = a[i] // create the shortcut ShortcutName = DRIVE_FOLDER_PATH+"\"+left(b["driveLetter"],1)+" Drive" oShortcut = WshShell.CreateShortcut(ShortcutName+".lnk") // set the path to explorer oShortcut.TargetPath = WinFolder+"\explorer.exe" // add the arguments to open explrer in the right view and drive oShortcut.Arguments = "/n,/e," + iif(right(b["path"],1)="\",b["path"],b["path"]+"\") // add the icon for type of drive if b["driveType"] = "Removable" and (left(b["path"],1)="A" or left(b["path"],1)="B") cIcon = 5 // 5.25 floppy drive cIcon = 6 // 3.5 floppy drive elseif b["driveType"] = "Removable" cIcon = 7 elseif b["driveType"] = "Fixed" cIcon = 8 elseif b["driveType"] = "Network" cIcon = 9 elseif b["driveType"] = "Disconnected Network" cIcon = 10 elseif b["driveType"] = "CD-ROM" cIcon = 11 elseif b["driveType"] = "RAM-disk" cIcon = 12 else cIcon = 4 endif oShortcut.IconLocation = WinFolder+"\system32\SHELL32.dll,"+cIcon // set other shortcut properties oShortcut.WindowStyle = 4 // Normal oShortCut.WorkingDirectory = b["path"] + "\" oShortcut.Description = ShortcutName //oShortCut.Hotkey = "" // save our new shortcut oShortCut.Save() release object oShortCut release object WshShell endfor // build an Icon for this program to undate our icons WshShell = new OleAutoClient("Wscript.shell") oShortcut = WshShell.CreateShortcut(DRIVE_FOLDER_PATH+"\Rebuild Drive Icons.lnk") oShortcut.TargetPath = set("directory")+"\DriveIcons.exe" oShortcut.IconLocation = WinFolder+"\system32\SHELL32.dll,13" oShortcut.WindowStyle = 4 // Normal oShortCut.WorkingDirectory = set("directory")+"\" oShortcut.Description = "Rebuild Drive Icons" oShortCut.Save() return function getDriveType // returns the drive type parameters lnDriveType do case case lnDriveType=0 lcDriveType = [Unknown] case lnDriveType=1 lcDriveType = [Removable] case lnDriveType=2 lcDriveType = [Fixed] case lnDriveType=3 lcDriveType = [Network] case lnDriveType=4 lcDriveType = [CD-ROM] case lnDriveType=5 lcDriveType = [RAM-disk] otherwise lcDriveType = [Unknown] endcase return lcDriveType function findDeadNetDrives // get's a array of all the currently connected network drives // and compares it to an array of all persistant network drives // eliminating all those currently connected. These are the drives // that are mapped, but not in use. Such as mapped drives to machines // that are turned off. aDead = new array() aDrives = EnumerateNetDrives() aWSHDrives = WSHgetAllNetworkDrives() cDrive = aDrives.firstKey for nElements = 1 to aDrives.count( ) // ? cDrive // drive found = false for i = 1 to aWSHDrives.size if left(aWSHDrives[i],2) = cDrive found = true endif endfor if not found aDead.add(cDrive) endif // ? aDrives[ cDrive ] // Share cDrive := aDrives.nextKey( cDrive ) endfor return aDead function WSHgetAllNetworkDrives // returns an array of all current network drives local a,x,oDrives,i a = new array() x = new OleAutoClient("WScript.Network") //? "*** Network Drives ***" oDrives = x.EnumNetworkDrives() for i = 0 to oDrives.count() -1 step 2 //? oDrives.Item(i) + "=" + oDrives.Item(i+1) a.add(oDrives.Item(i))// + "=" + oDrives.Item(i+1)) next release object x x = NULL return a function EnumerateNetDrives /* returns an assoc array of all persistant network drives Their drive letter and the share. Example: aDrives = EnumerateNetDrives() */ aDrives = new assocArray() for i = 67 to 90 cDrive = chr(i)+":" cResult = GetNetMapping(cDrive) if not isBlank(cResult) aDrives[cDrive] = cResult endif endfor return aDrives ************************************************************************ function GetNetMapping(cDrive) ************************************************************************ // returns the share name for a drive if TYPE( 'WNetGetConnection' ) # 'FP' extern culong WNetGetConnection( cString, cString, CPTR CULONG ) MPR.DLL ; FROM "WNetGetConnectionA" endif cBuff = space( 255 ) if not WNetGetConnection( cDrive,cBuff,len(cBuff)) == 0 endif return trim(cBuff)