AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is there a way to stop auto-run/auto-play from auto-running?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
elchapin



Joined: 06 Mar 2007
Posts: 62
Location: Columbus, OH, USA

PostPosted: Fri May 11, 2007 4:29 pm    Post subject: Is there a way to stop auto-run/auto-play from auto-running? Reply with quote

I know you can just do this with windows settings, but is there a way to stop auto-run and auto-play from auto-running with autohotkey?

For instance, I want to run a script on another person's computer before I put in a CD. Windows Explorer is set to automatically open to the CD drive. I don't want that to happen.

No idea where to start on this one... any help would be appreciated.
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Fri May 11, 2007 5:49 pm    Post subject: Reply with quote

do you have control over what's on the CD? you can create an autorun.inf in the root of it, and configure it to not do anything.
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
elchapin



Joined: 06 Mar 2007
Posts: 62
Location: Columbus, OH, USA

PostPosted: Fri May 11, 2007 6:05 pm    Post subject: Reply with quote

No, unfortunately there is no control of the CD content, otherwise that would be a great way to do it...
Back to top
View user's profile Send private message Visit poster's website
Micahs



Joined: 01 Dec 2006
Posts: 413

PostPosted: Sat May 12, 2007 12:02 pm    Post subject: Reply with quote

Give this a try. It stops the autorun by pressing "Shift" for ten seconds when it detects the CD insertion. Based on the code here. There is probably a better way, but this works.
Code:
#Persistent
OnMessage(0x219, "notify_change")
Return

notify_change(wParam, lParam, msg, hwnd)
{
   ;MsgBox, %wParam% %lParam% %msg% %hwnd%
   if wParam = 32768
   {   ;msgbox, Disc Inserted
      Send,{Shift down}
      SetTimer,tipper,100
      SetTimer,killshift,10000
   }
}

tipper:
   ToolTip,Preventing Autorun
Return

killshift:
   SetTimer,tipper,Off
   SetTimer,killshift,Off
   Send,{Shift up}
   ToolTip
Return

_________________
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 62
Location: Columbus, OH, USA

PostPosted: Sat May 12, 2007 5:35 pm    Post subject: Reply with quote

@Micahs - That was brilliant! I remember reading that "shift" key trick when inserting a CD, but of course, I never would have remembered it when I needed it!

It would be still be nice to know if there is a "proper" way of doing this, but Micahs saved the day, thanks!
Back to top
View user's profile Send private message Visit poster's website
Micahs



Joined: 01 Dec 2006
Posts: 413

PostPosted: Sun May 13, 2007 2:56 am    Post subject: Reply with quote

I did some checking and there is a better way to do this - using the "QueryCancelAutoPlay" message, but it requires your script to have the focus for it to work. If your script is running in the background it won't work.
_________________
Back to top
View user's profile Send private message
Travley



Joined: 13 May 2007
Posts: 47

PostPosted: Sun May 13, 2007 8:44 pm    Post subject: Reply with quote

Regedit HKEY_LOCAL_MACHINE> SYSTEM> CurrentControlSet>Services> Cdrom and change the AutoRun value from 1 to 0.



This probably isnt whatcha need, but figured Id post it up none the less.

Cheers
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 7159

PostPosted: Mon May 14, 2007 1:03 pm    Post subject: Reply with quote

Code:
#Persistent
Gui +AlwaysOnTop
SetFormat, Integer, Hex

lpStr  := "QueryCancelAutoPlay"
MsgNo  := DllCall( "RegisterWindowMessage", UInt, &lpStr )
; MsgNo will be a message identifier in the range 0xC000 through 0xFFFF

OnMessage( MsgNo, "QCAP" )

Gui, Add, Text, w150 h25 +0x201 +Border     , Awaiting : %MsgNo%
Gui, Add, Text, w150 h25 +0x201 +Border vMsg

Gui, Show, , Auto-Play Cancellation
Return

QCAP( wParam, lParam, msg, hwnd ) {
  GuiControl,, Msg, Received : %Msg%
  Return True
}
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 62
Location: Columbus, OH, USA

PostPosted: Mon May 14, 2007 6:06 pm    Post subject: Reply with quote

@Skan-
Thanks, I knew you would be around with the answer! That is great stuff.

--

I am trying to make sense of it all still, and I think most of it I understand... However, it appears when I get rid of the GUI, it now longer stops auto-run, and the Explorer window opens.

Is there a way to do this without the GUI? I must be missing something...
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 7159

PostPosted: Mon May 14, 2007 8:12 pm    Post subject: Reply with quote

elchapin wrote:
Is there a way to do this without the GUI? I must be missing something...


No! Not with QueryCancelAutoPlay! Maybe Micahs method or we have to meddle with the registry, AFAIK.

Why not use a GUI ? You can make it so small that it will never be noticed.

Code:
#Persistent
Gui -Caption +AlwaysOnTop

lpStr  := "QueryCancelAutoPlay"
MsgNo  := DllCall( "RegisterWindowMessage", UInt, &lpStr )
OnMessage( MsgNo, "QCAP" )
OnMessage(0x219, "Notify_Change")

Return

Notify_Change(wParam, lParam, msg, hwnd) {
IfEqual, wParam, 32768, Gui, Show, x0 y0 w1 h1
}

QCAP( wParam, lParam, msg, hwnd ) {
  Gui, Hide
  Return True
}


In that code, I would use an appropriate icon to fully fit into the GUI.

Smile
Back to top
View user's profile Send private message
elchapin



Joined: 06 Mar 2007
Posts: 62
Location: Columbus, OH, USA

PostPosted: Mon May 14, 2007 9:06 pm    Post subject: thanks, skan! Reply with quote

@Skan- That's a good tip to just make the GUI small, or just let the GUI stay visible... I did like that little layout of yours anyway. Cool.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group