AutoHotkey Community

It is currently May 26th, 2012, 6:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: February 21st, 2008, 1:49 pm 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
Hi,

is there a possibility to show a windows error dialog after run a inexistent command like it occurs when I type a wrong command in Win+R - instead of the ahk error like in my current code!?

Thx!

Code:
#c::
  Clipboard =
  Send ^c
  ClipWait
  Run, "%Clipboard%"
  Return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 21st, 2008, 8:06 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
M3CSL wrote:
is there a possibility to show a windows error dialog


You can simulate a similar Message Box.

Code:
#c::
  Clipboard =
  Send ^c
  ClipWait
  Run, "%Clipboard%",, UseErrorLevel
  If errorLevel
     MsgBox, 16, %clipboard%, % "Windows cannot find '" Clipboard "'."
     . "Make sure you typed the name correctly, and then try again. "
     . "To search for a file, click the Start button, and then click Search."
Return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 22nd, 2008, 3:19 pm 
Woot!...I did it...

Code:
;//AlwaysUseCurrentCB=1

#c::
cba:=ClipboardAll
Clipboard=
Send ^c
ClipWait, .319
if (errorlevel) {
   Gosub, RestoreCB
   if (!AlwaysUseCurrentCB) {
      StringLeft, ClipPart, Clipboard, 119
      msgbox, 36, ClipWait Failed - %A_ScriptName%,
      (LTrim
         Select some text 1st...or do you wanna use the current clipboard contents?...
   
         %clippart%
      )
      clippart=
      IfMsgBox, No
         return
   }
}

Run, cmd /c start "" "%Clipboard%", , hide

RestoreCB:
if (cba) {
   Clipboard:=cba
   cba=
}
returnp

...much more reliable...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2008, 7:48 pm 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
Thank you both, I modified your script and now I use this:

Code:
#c::
  cba := ClipboardAll
  Clipboard =
  Send ^c
  ClipWait, .319

  If (Errorlevel)
    Msgbox, 16, Run, No text selected, 5
  else
    Run, cmd /c Start "" "%Clipboard%", , Hide

  If (cba)
    Clipboard := cba
Return


Hey Guest, why the dot in .319? This means 319ms?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2008, 1:28 pm 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
I found another problem:

Code:
Run, "%Clipboard%",, Hide UseErrorLevel
Run, cmd /c start "" "%Clipboard%",, Hide UseErrorLevel


are unable to run these examples:

control.exe intl.cpl
control.exe input.dll

Code:
Run, cmd /c "%Clipboard%",, Hide UseErrorLevel


Runs everything, but sets no Errorlevel if wrong command was in clipboard.

Any idea what to improve?

THX

Code:
#c::
  cba := ClipboardAll
  Clipboard =
  Send ^c
  ClipWait, .319

  If (Errorlevel)
    Msgbox, 16, Run, No text selected, 5
  else {
    Run, cmd /c "%Clipboard%",, Hide UseErrorLevel
   
    msgbox Errorlevel: %Errorlevel% `nA_LastError: %A_LastError%
   
    If (A_LastError != 0)
      Msgbox, 16, Run, Windows cannot find '%Clipboard%'.
    }
   
  If (cba)
    Clipboard := cba
  Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 23rd, 2008, 1:36 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
I would recommend you to keep the Windows Run Dialog hidden and use it instead. :)

Read the following topic.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2008, 7:19 am 
M3CSL wrote:
...but sets no Errorlevel if wrong command was in clipboard.

...you wanted the Windows Run Error Dialog not an Errorlevel...I don't think you can get an Errorlevel (at least not easily), cuz Autohotkey is only testing whether or not the running of cmd worked...that always should...after I posted, I modified mine to not include the double quotes around "Run, cmd /c start %Clipboard%, , Hide"...which makes some stuff work & other stuff not work...for example you can't run exe's with spaces in the path, unless what you highlight has double quotes around it...but it does work for your control.exe examples...I'm working on the Errorlevel of the sub-process, but I don't think it'll be easy or pretty...

Code:
;//AlwaysUseCurrentCB=1

#c::
cba:=ClipboardAll
Clipboard=
Send ^c
ClipWait, .319
if (errorlevel) {
   Gosub, RestoreCB
   if (!AlwaysUseCurrentCB) {
      StringLeft, ClipPart, Clipboard, 119
      msgbox, 36, ClipWait Failed - %A_ScriptName%,
      (LTrim
         Select some text 1st...or do you wanna use the current clipboard contents?...
   
         %clippart%
      )
      clippart=
      IfMsgBox, No
         return
   }
}

Run, cmd /c start %Clipboard%, , hide
;//Run, %Clipboard%

RestoreCB:
if (cba) {
   Clipboard:=cba
   cba=
}
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2008, 10:31 am 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
SKAN wrote:
I would recommend you to keep the Windows Run Dialog hidden and use it instead. :)

Read the following topic.


Nice idea. I read this and the following topics, but I couldn't find out how to pass the parameter to your de-nested funktion and how to hide the run dialog.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2008, 10:33 am 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
Guest, I understand. But I need a function which runs everything that Win-Run does.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 10:53 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
M3CSL wrote:
but I couldn't find out how to pass the parameter to your de-nested funktion and how to hide the run dialog.


That function halts the thread! :( .. also it is not possible to start the run dialog hidden. :(

Anyways, here is some code:

Code:
SetBatchLines, -1
Process, Priority,, High

#c::
  ClipBoard=
  Send ^c
  ClipWait, 2
  IfNotEqual, Errorlevel, 0, Return
  Command=%Clipboard%
  Send #r
  Loop {
         If ( RunID := WinExist( "Run ahk_class #32770" ) )
             Break
         Sleep 10
         IfGreater, A_Index, 200, Return
       }
  ControlSetText, Edit1, %command%, ahk_id %RunID%
  ControlClick, Button2, ahk_id %RunID%
  WinClose, ahk_id %RunID%
Return


I tested it in this website: http://www.dx21.com/SCRIPTING/RUNDLL32/REFGUIDE.ASP

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2008, 11:50 am 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
SKAN wrote:
.. also it is not possible to start the run dialog hidden. :(


Didn't I understand your post where you wrote you can hide it?

SKAN wrote:
Anyways, here is some code:


Thank you, but I'm not a friend of flare-up windows. I will use this code instead:

Code:
#c::
  cba := ClipboardAll
  Clipboard =
  Send ^c
  ClipWait, .319

  If (Errorlevel)
    Msgbox, 16, Run, % "No text selected.                " , 5
  else {
    If (Clipboard = "cmd")
      Run, cmd
    else
      Run, cmd /c "%Clipboard%",, Hide
    }

  If (cba)
    Clipboard := cba
  Return



SKAN wrote:


I already knew this site, it's one of the best I've ever seen!

CU


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2008, 1:06 pm 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
My last code is useless , since it doesn't work for URLs. This one works for everything I tried:

Code:
www.google.de
http://google.de
mailto:
control
control.exe intl.cpl
control intl.cpl
intl.cpl
input.dll
control.exe input.dll
C:\Program Files\AutoHotkey\AU3_Spy.exe


Code:
#c::
  cba := ClipboardAll
  Clipboard =
  Send ^c
  ClipWait, .319

  If (Errorlevel)
    Msgbox, 16, Run, % "No text selected.                " , 5
  else {
    Run, %Clipboard%,, UseErrorLevel
    If (ErrorLevel = "ERROR")
      Run, %comspec% /c Start "" "%Clipboard%",, Hide
    }

  If (cba)
    Clipboard := cba
  Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2008, 1:30 pm 
Offline

Joined: February 9th, 2006, 8:36 pm
Posts: 338
there is a superduper winApi function which is IMO identical to the run dialog flexibility: ShellExec_RunDLL
Code:
dllCall("shell32\ShellExec_RunDLL","uint",0,"uint",0,"str",MyCommandString,"uint",10) ;10=SW_SHOWDEFAULT


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2008, 1:58 pm 
Offline

Joined: January 21st, 2008, 6:15 pm
Posts: 36
Location: Germany
Thx, really nice:

Code:
#c::
  cba := ClipboardAll
  Clipboard =
  Send ^c
  ClipWait, .319

  If (Errorlevel)
    Msgbox, 16, Run, % "No text selected.                " , 5
  else
    dllCall("shell32\ShellExec_RunDLL","uint",0,"uint",0,"str",Clipboard,"uint",10)

  If (cba)
    Clipboard := cba
  Return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: bobbysoon, Exabot [Bot], JSLover, kkkddd1, Tipsy3000, Yahoo [Bot] and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group