![]() |
|
24 Nov 2009 | #31 |
|
No rush, thanks for checking this.
|
My System Specs![]() |
. |
|
28 Nov 2009 | #32 |
|
Fakeasdf, I'm wondering if you've had you a chance to check the Autorunner.exe program with an external hard drive. Thanks.
|
My System Specs![]() |
30 Nov 2009 | #33 |
|
Sorry, the holidays came and I was busy entertaining guests... I'll check it sometime tonight and let ya know..
|
My System Specs![]() |
. |
|
30 Nov 2009 | #34 |
|
Yeah, it turns out that the removable usb drives show up as fixed devices and not removable drives. I'll have it just check any attached drive that isn't a cd rom... Since someone might not want that, I'll leave the other exe... Code:
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.IO; using Microsoft.Win32; namespace Autorunner { public class RegKeysAndDrives { public RegistryKey basekey; public String subkey; public String driveLetter; public RegKeysAndDrives(RegistryKey _basekey, String _subkey, String _driveLetter) { basekey = _basekey; subkey = _subkey; driveLetter = _driveLetter; } } static class Program { /// <summary> /// The main entry point for the application. /// </summary> /// public static List<RegKeysAndDrives> toDelete; [STAThread] static void Main() { //keep track of drives we've already ran, Must compare strings, DriveInfo only compares using the Object List<String> haveRun = new List<String>(); toDelete = new List<RegKeysAndDrives>(); while (true) { //let's check every 2 seconds... We don't want to slow down the machine! System.Threading.Thread.Sleep(2000); try { //Get current drives DriveInfo[] drives = DriveInfo.GetDrives(); List<DriveInfo> curDrives = new List<DriveInfo>(drives); //remove any drives from haverun that don't exist anymore for (int i = 0; i < haveRun.Count; i++) { if (DriveInfoContains(curDrives, haveRun[i]) == false) { for (int j = 0; j < toDelete.Count; j++) { if (toDelete[j].driveLetter == haveRun[i]) { try { toDelete[j].basekey.DeleteSubKeyTree(toDelete[j].subkey); } catch (Exception ex) { //subkey doesn't exist anymore :P } toDelete.RemoveAt(j); j--; } } haveRun.RemoveAt(i); i--; } } //let's remove our haveRuns from drives, no point in checking them again... for (int i = 0; i < curDrives.Count; i++) { if (haveRun.Contains(curDrives[i].RootDirectory.Name) == true) { curDrives.RemoveAt(i); i--; } } //Check any new Removable type drives, and run them... foreach (DriveInfo drive in curDrives) { if (drive.DriveType != DriveType.CDRom) { if (drive.IsReady) { try { AutoRunDrive(drive); } catch (Exception ex) { //I don't care if it crashes trying to launch it, let's just let it go... } haveRun.Add(drive.RootDirectory.Name); } } } } catch (Exception ex) { //Let's not crash if something gets unplugged while we're accessing it... } } } private static bool DriveInfoContains(List<DriveInfo> curDrives, string haveRunDriveName) { foreach (DriveInfo di in curDrives) { if (di.RootDirectory.Name == haveRunDriveName) return true; } return false; } private static void AutoRunDrive(DriveInfo drive) { bool doAutoRun = false; String root = drive.RootDirectory.Name; String autorun = root + "autorun.inf"; if (File.Exists(autorun)) { StreamReader sr = new StreamReader(autorun); while (!sr.EndOfStream) { String line = sr.ReadLine(); if (line.ToLower().StartsWith("open")) { int idxEquals = line.IndexOf('='); String toRun = root + line.Substring(idxEquals + 1); //This isn't a good guess of where the args should be, but I don't care int spaceArgs = toRun.IndexOf(' '); String args = toRun.Substring(spaceArgs + 1); args = FixArgs(args, root, toRun.ToLower().Contains("truecrypt")); toRun = toRun.Substring(0, spaceArgs); if (MessageBox.Show("Would you like to Autorun '" + toRun + " " + args + "'?", "Autorunner", MessageBoxButtons.YesNo) == DialogResult.Yes) { System.Diagnostics.Process.Start(toRun, args); doAutoRun = true; } } else if (doAutoRun && line.ToLower().StartsWith("shell")) { int equalidx = line.IndexOf("="); String keyName; String subkey; String value; if (equalidx == -1) continue; keyName = line.Substring(5, equalidx - 5); value = line.Substring(equalidx + 1); if (keyName.Contains("command")) { value = root + value; } RegistryKey baseKey = Registry.CurrentUser; subkey = "Software\\Classes\\Drive\\shell" + keyName; RegistryKey key = baseKey.CreateSubKey(subkey); key.SetValue("", value); toDelete.Add(new RegKeysAndDrives(baseKey, subkey, root)); } } sr.Close(); } } private static string FixArgs(string args, string root, bool isTrueCrypt) { if (isTrueCrypt) { int idxv = args.IndexOf("/v"); int idxfile = args.IndexOf("\"", idxv); return args.Substring(0, idxfile + 1) + root + args.Substring(idxfile + 1); } return args; } } } |
My System Specs![]() |
01 Dec 2009 | #35 |
|
Works great! Thanks so much.
|
My System Specs![]() |
06 Mar 2012 | #36 |
|
Dismount
Hi,
There is any way to autodismount the volume previous to remove the USB, because it says the volume is in use. Thanks, Ariel |
My System Specs![]() |
![]() |
Thread Tools | |
Similar help and support threads | ||||
Thread | Forum | |||
Allow autorun on SDCards & USB Drives? Hello, i created an autorun.inf file on my SDCard to launch something when i plug it in. However it seems that feature was disabled for removable drives. Is there a tweak or something to allow it? Found an app called "SamLogic USB AutoRun Creator" it worked once and then not anymore. Not something... |
Hardware & Devices | |||
USB autorun when my USB is plunged or is opened in the file explorer i want a bat file run how would i do this |
General Discussion | |||
DVD/CD won't autorun I'm pretty sure I have set all the options so that the disks _ought_ to autorun but they won't. I have to go into Powerdesk (File Manager) and select a vob file. I' installed a codec package but that made no difference. I have had problems with this drive, Samsung TSST CDDVDW 288BB, in fact... |
Hardware & Devices | |||
How to Autorun USB on Win 7 Hi, I want to make a USB flash drive auto run a website link in Windows 7. I know the auto run function has been removed in Win 7, but can I at least make a pop up window appear whenever a USB flash drive is inserted in the PC and have the user the option to click and open the link??? ... |
Software | |||
Autorun.dll Is missing or corrupted.. anyone have this prob..? I have dl'd and burned the iso 2x and have the same prob. let me say that in order to burn iso..i have just renamed the longnamed file to (the longname).iso i have been dl'ing it with ff and it is adding a ,dlm to the file and i have just been... |
Installation & Setup |
Our Sites |
Site Links |
About Us |
Find Us |
Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd All times are GMT -5. The time now is 17:25. |
![]() ![]() |