Sign in to follow this  
Followers 0
pieeater

close script if usb is unplugged

15 posts in this topic

can you make it so that you run a script from a flashdrive and when the flashdrive is unplugged it automatically closes?


[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites



you would have to copy the script locally, because you can't run a script if the source is unplugged

Share this post


Link to post
Share on other sites

but if i have the script on the flashdrive and then start it, how would i check to see if it is unplugged and make it exit?


[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

There's code floating around the forum to check whether an USB drive as been connected or disconnected... but this should do it too :unsure:...

AdlibRegister("_Check_Script_Existence", 1000)

Func _Check_Script_Existence()
    if not FileExists(@ScriptFullPath) Then
        Exit
    endif
EndFunc

Share this post


Link to post
Share on other sites

thanks :unsure: thats exactly what i needed


[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

There's code floating around the forum to check whether an USB drive as been connected or disconnected... but this should do it too :unsure:...

AdlibRegister("_Check_Script_Existence", 1000)

Func _Check_Script_Existence()
    if not FileExists(@ScriptFullPath) Then
        Exit
    endif
EndFunc

Did you try it ?

Seems odd that a script can realize that it doesn't exists...Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

My thoughts exactly

Share this post


Link to post
Share on other sites

Seems logical to me. If the @ScriptFullPath is on a flash drive, then if it's unplugged, the full path no longer exists. However, I'm not sure if the script will be able to continue to run if the drive is unplugged as mentioned.

You may have to FileInstall a secondary script to a temp dir on the pc that checks the path or something.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Seems logical to me. If the @ScriptFullPath is on a flash drive, then if it's unplugged, the full path no longer exists. However, I'm not sure if the script will be able to continue to run if the drive is unplugged as mentioned.

You may have to FileInstall a secondary script to a temp dir on the pc that checks the path or something.

How can it be logical to you ?

If not plugged, it can't be executed and "know" if it exists...

A second script seems more reliable.

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

hmmm...sounds like the 2nd post in the thread makes some sense...:unsure:

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I was assuming the script was started while the drive was plugged in.

*edit*

I guess I also assumed that script was loaded into Memory before running, but maybe not. Wasn't sure as I always run all my scripts locally.

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Or what about using /AutoIt3ExecuteScript with @AutoItExe?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I just tested this scenario with one of my scripts, I ran SciTe from the hard drive, opened a script on a USB drive, and then ran it from SciTe. After it started running, I pulled the USB drive from the computer, it kept running without a problem. It appears to be running the script in memory.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

it works for me, the thing about this is it checks to see if the path exists, so where ever the script comes from(USB drive) if it is deleted(or unplugged) the script will no longer exist on the computer, and then you can make it exit using an if...then. however if the script is not on a flash drive, the only way to close the script(unless you have another closing option) is to delete the script.


[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

Have the script write a temporary file to the USB drive you're accessing, if that file doesn't exist then exit the script. This way it won't matter where the script is being run from, it only matters that the USB drive has a file you're looking for on it. Or just look for the drive letter itself if you don't have the script running from the USB drive.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0