Jump to content

How to warn the user to remove memory stick


Recommended Posts

Please get me started on this one. I need to write a script that checks whether there are any USB memory sticks plugged in when the user does Start | Shut Down. If there are any, it should warn the user and not shut down.

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

In my examples script listing, in my signature there is a .au3 file called: DoSomethingAtShutdown.au3 download that, thats how you can do something at shutdown. Now, to check if theres a memory stick inserted you would need to use DriveGetType or something simalir, or check if like you have a certain hidden file like: E:\hiddenfile.dat then you could use the: DoSomethingAtShutdown.au3, and then:

If FileExists("E:\hiddenfile.dat") Then MsgBox(0, "Warning!", "Remove your memory stick now! then press OK!")

Hope this helps! Let me know if you need any more help!

Link to comment
Share on other sites

use it to detect and check USB

$DISK = DriveGetDrive("REMOVABLE")
For $I = 1 To $DISK[0]
    $STATS = DriveStatus($DISK[$I])
    If $STATS = "READY" Then
    MsgBox(0, "Warning!", "Remove your memory stick now! then press OK!")
    Else
Next
[font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php
$Life = "Happy"
If @Error Then
$Life = "Risk"
Link to comment
Share on other sites

Many thanks to both of you.

I would be nice to have a way of aborting the shut down if there is a memory stick inserted. Any ideas?

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Try this.

$DISK = DriveGetDrive("REMOVABLE")
For $I = 1 To $DISK[0]
    $STATS = DriveStatus($DISK[$I])
    If $STATS = "READY" Then
    Run(@ComSpec & "shutdown -a")
    MsgBox(0, "Warning!", "Remove your memory stick now! then press OK!")
    Else
Next

Not tested yet (I don't normally use @ComSpec so if I used it improperly someone please post the correct usage) but you should get the idea.

Edited by dbzfanatic
Link to comment
Share on other sites

c.haslam

Try this:

Global Const $WM_QUERYENDSESSION = 0x0011
Global $Msg = False

GUICreate("Dummy", 1, 1)

GUIRegisterMsg($WM_QUERYENDSESSION, "WM_QUERYENDSESSION")

While 1
    If $Msg Then
        $Msg = False
        MsgBox(0, "Warning!", "Remove your memory stick!")
    EndIf
    Sleep(100)
WEnd

Func WM_QUERYENDSESSION($hWndGUI, $MsgID, $WParam, $LParam)
    Local $DISK, $STATS, $i
    
    $DISK = DriveGetDrive("REMOVABLE")
    If @error Then Return True
    
    For $i = 1 To $DISK[0]
        $STATS = DriveStatus($DISK[$i])
        If $STATS = "READY" Then
            $Msg = True
            Return 0
        EndIf
    Next
    
    Return True
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...