External Harddrive Autorun

hey guy's, new day, new program and new problems...

I've created this autorun for my external hard drive, everything works perfectly, but i want some extras...

i want know if someone can supply some coding for me for when i insert the hard drive via usb and the autorun starts that the usb hard drive will be removed in my computer.

i think you going to need some .dll files for it, but i don't know how to work with .dll files yet.

can some maybe help and thanks to all the guys who is always helping

Comments

  • ok, i finally figured it out to get n system tray icon for the autorun of hard drive and to hide you program...

    but theres is n problem somewhere, plus i still need to get some code to hide the external hard drive connected via USB...

    now this is my code for the system tray icon.

    //----------------------------------------------------
    with TrayIconData do
    begin
    cbSize := SizeOf(TrayIconData);
    Wnd := Handle;
    uID := 0;
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
    uCallbackMessage := [color=Red]WM_ICONTRAY;[/color]
    hIcon := Application.Icon.Handle;
    StrPCopy(szTip, Application.Title);
    end;

    Shell_NotifyIcon(NIM_ADD, @TrayIconData);

    //----------------------------------------------------

    but it gives me an error at the red...
    Undeclared identifier: 'WM_ICONTRAY'

    can someone help please
  • found the problem..

    forgot to declare the const...

    const
    WM_ICONTRAY = WM_USER + 1;

  • partly solved...

    you need to add Registry to your uses clause just after interface

    //--------------------------------
    Procedure DriveControl;
    Const
    UserKeyHideDrive = 'HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    SystemKeyHideDrive = 'HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';

    UserKeyPreventAcces = 'HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    SystemKeyPreventAcces = 'HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    Begin
    With TRegistry.Create Do
    Try
    If OpenKey(UserKeyHideDrive, True) Then
    WriteInteger('NoDrives', X);
    If OpenKey(SystemKeyHideDrive, True) Then
    WriteInteger('NoDrives', X);

    If OpenKey(UserKeyPreventAcces, True) Then
    WriteInteger('NoDrives', X);
    If OpenKey(SystemKeyPreventAcces, True) Then
    WriteInteger('NoDrives', X);

    CloseKey;
    Finally
    Free;
    End;
    End;

    //--------------------------------------------------

    Now... Where the x stands in WriteInteger('NoDrives', X) you have to enter in the Decimal code of the drive letter... example

    A: 1, B: 2, C: 4, D: 8, E: 16, F: 32, G: 64, H: 128, I: 256, J: 512, K: 1024, L: 2048, M: 4096, N: 8192, O: 16384, P: 32768, Q: 65536, R: 131072, S: 262144, T: 524288, U: 1048576, V: 2097152, W: 4194304, X: 8388608, Y: 16777216, Z: 33554432, ALL: 67108863

    but there is still some work...
    if plug in my external hard drive, the autorun program starts showing the system tray icon and menus to control the drive... but the drives is still shown in my computer, u have to first log of or restart the computer before it hides the drives and the contents as i wanted...

    is there some way to update or refresh the the explorer so that i don't need to restart or log of... o' and when i restart my anti virus program is always asking if i want windows registry to be accessed and if i say no the drive will be hidden, but when i say yes the registry will be restored and the drives is no longer hidden
  • sorry, previous code doesn't work...

    Here we go...

    you need to add Registry and windows to your uses clause just after interface if your using a unit

    Procedure DriveControl;
    Const
    UserKeyHideDrive = 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    LocalKeyHideDrive = 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';

    UserKeyNoViewOnDrive = 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    LocalKeyNoViewOnDrive = 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    Begin
    With TRegistry.Create Do
    Try
    RootKey := HKEY_CURRENT_USER;
    If OpenKey(UserKeyHideDrive, True) Then
    WriteInteger('NoDrives', 4);
    If OpenKey(UserKeyNoViewOnDrive, True) Then
    WriteInteger('NoViewOnDrive', 4);
    CloseKey;
    Finally
    Free;
    End;

    With TRegistry.Create Do
    Try
    RootKey := HKEY_LOCAL_MACHINE;
    If OpenKey(LocalKeyHideDrive, True) Then
    WriteInteger('NoDrives', 4);
    If OpenKey(LocalKeyNoViewOnDrive, True) Then
    WriteInteger('NoViewOnDrive', 4);
    CloseKey;
    Finally
    Free;
    End;
    End;
  • : sorry, previous code doesn't work...
    :
    : Here we go...
    :
    : you need to add Registry and windows to your uses clause just after
    : interface if your using a unit
    :
    [code]
    : Procedure DriveControl;
    : Const
    : UserKeyHideDrive =
    : 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    : LocalKeyHideDrive =
    : 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    :
    : UserKeyNoViewOnDrive =
    : 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    : LocalKeyNoViewOnDrive =
    : 'SoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer';
    : Begin
    : With TRegistry.Create Do
    : Try
    : RootKey := HKEY_CURRENT_USER;
    : If OpenKey(UserKeyHideDrive, True) Then
    : WriteInteger('NoDrives', 4);
    : If OpenKey(UserKeyNoViewOnDrive, True) Then
    : WriteInteger('NoViewOnDrive', 4);
    : CloseKey;
    : Finally
    : Free;
    : End;
    :
    : With TRegistry.Create Do
    : Try
    : RootKey := HKEY_LOCAL_MACHINE;
    : If OpenKey(LocalKeyHideDrive, True) Then
    : WriteInteger('NoDrives', 4);
    : If OpenKey(LocalKeyNoViewOnDrive, True) Then
    : WriteInteger('NoViewOnDrive', 4);
    : CloseKey;
    : Finally
    : Free;
    : End;
    : End;
    :
    [/code]

    Please use the code tags next time you post code. See below the entry box for new posts for instructions.
  • Hello. I have read in an article that Autorun in Windows 7 has been blocked. Is there still a way on making Autorun work in Windows 7? If so, what are the codes? Thank you so much! This is for our thesis project. This will really be a big help.

    We would like to have our C# application that's been saved in an external hard drive to run automatically after we plugged in the external device. What are the codes that could make this work?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories