Jump to content

_CMD()


w0uter
 Share

Recommended Posts

i hate having to type the full path when i need to run a commandline app

this way you can just browse to the app and hit #c

and you have a dos prompt with the correct dir.

(that is atleast if you have full path names in your titles)

hope it is use to someone:

ty gafrost

#NoTrayIcon

HotKeySet('#c', '_CMD')

While 1
    Sleep(1000)
WEnd

Func _CMD()
    $path = ControlGetText(Wingettitle(''),"","Edit1")
    Run(@comspec & ' /k ' & StringLeft($path, 2) & ' & cd "' & $path & '" & cls', @SystemDir)
EndFunc
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

might try this, had a problem using #c, so changed it alt-c, had the command incorrect also, was \k fixed /k

HotKeySet('!c', '_CMD')

While 1
    Sleep(1000)
WEnd

Func _CMD()
    $path = ControlGetText(Wingettitle(''),"","Edit1")
    Run(@comspec & ' /k cls & cd "' & $path)
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

its been done.

#include <Process.au3>

_RunDOS( $sCommand )

and btw, the window stays open if you use /k, using /c closes it after the command is executed so you don't need cls.

Think you missed the point of what w0uter is attempting to do, he needs to go to the dos prompt

Keeps the program running so that he can do that when he needs to _RunDOS would be a little bulky for that, why run a @ComSpec & " /C " & $sCommand (command would be equal to: (@comspec & ' /k cls & cd "' & $path) so now you have

@ComSpec & " /C " & (@comspec & ' /k cls & cd "' & $path

Now if _RunDOS had a parameter for keep open or close then that would be usefull.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Doesn't work with UNC paths, of course. What might make it work is to replace the 'cd' command with 'pushd'. Doing that, though, may make it work on only certain versions of Windows.

I never knew about the "pushd" command. Thnks for that. =)

Here's it with that command. I can't take any credit of course, I didn't really do anything...

Func _nCMD()
    $path = ControlGetText(Wingettitle(''),"","Edit1")
    Run(@comspec & ' /k cls &  pushd "' & $path & '"')
EndFunc

The fun part is now trying to do a "if" or "case" so you can do it under one hot key. B)

Link to comment
Share on other sites

kept forgetting if i had the program running or not, so added to it a lil bit

#NoTrayIcon
$G_SZVERSION = "_CMD Center ver 1.2" & @LF & @LF & "Made with AutoIt ver " & @AutoItVersion
If WinExists($G_SZVERSION) Then Exit; It's already running
AutoItWinSetTitle($G_SZVERSION)

opt("TrayOnEventMode", 1)
opt("TrayMenuMode", 1)
AdlibEnable("_ReduceMemory")
HotKeySet("!e", "_Exit")
HotKeySet('!c', '_CMD')

$cmditem = TrayCreateItem("Open CMD Window")
TrayItemSetOnEvent(-1, "_CMD")

$aboutitem = TrayCreateItem("About")
TrayItemSetOnEvent(-1, "About")

$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "ExitScript")

$dll = DllOpen("psapi.dll")
TraySetIcon(@SystemDir & "\cmd.exe", 0)

TraySetState()

$Current_Window = ""
While 1
   If WinGetTitle('') <> $G_SZVERSION Then $Current_Window = ControlGetText(WinGetTitle(''), "", "Edit1")
   _ReduceMemory($dll)
   Sleep(50)
WEnd
DllClose($dll)

Func OnAutoItExit()
   DllClose($dll)
EndFunc  ;==>OnAutoItExit

Func ExitScript()
   Exit
EndFunc  ;==>ExitScript

Func _CMD()
   Run(@ComSpec & ' /k pushd "' & $Current_Window & '"')
EndFunc  ;==>_CMD

Func About()
   MsgBox(64, "About:", $G_SZVERSION)
EndFunc  ;==>About

Func _Exit()
   Exit
EndFunc  ;==>_Exit

Func _ReduceMemory($dll = "psapi.dll")
   Local $ai_Return = DllCall($dll, 'int', 'EmptyWorkingSet', 'long', -1)
   Return $ai_Return[0]
EndFunc  ;==>_ReduceMemory
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

@wOuter

On Windows 2000 and above you can use a '/d' with the CMD instead of the old way of 'D:' followed by 'cd D:\foo\bar'.

Run(@comspec & ' /k cd /d "' & $path & '" & cls', @SystemDir)

@Klaatu

Pushd doesn't allow for authentication, but is a very handy way of cd'ing to a UNC. Also, for those who didn't know, pushd and popd use a stack, so you can use multiple pushd's (it will create one drive letter for each call, going down from Z: or the last available letter), and popd to climb back up the chain. You should use a popd after you're done because on some OS's (XP I think, but not Windows 2000), the drive letter will stay mapped after you exit the command line window. You could have your program watch for drive letters create while CMD windows are open and unmap them when no CMD windows exist. Just a thought.

If you need authentication, you can use something like this first, which will get you access to all shares on the remote machine to which you have access...

Run(@comspec & ' /c net use \\remotemachine\IPC$ ' & $password & ' /user:' & $domain & "\" & $username & ' /persistent:no')

and close the connection if you want with a...

Run(@comspec & ' /c net use \\remotemachine\IPC$ /del /y')

Of course, you'd have to check for a '\\' in the $path to know it's a UNC, then split the remote machine name from that UNC for the net use command. Also, the '/y' only works on Windows 2000 and above.

Edited by c0deWorm

My UDFs: ExitCodes

Link to comment
Share on other sites

You should use a popd after you're done because on some OS's (XP I think, but not Windows 2000), the drive letter will stay mapped after you exit the command line window.

XP Pro SP2 un-maps drive when closing command window

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Good idea! A CMD hotkey should be mandatory! AutoIt hotkeys can interfere with other programs so I just use start menu hotkeys. This script puts a hotkey onto the default shortcut for these apps. It only runs once with no need to leave an AutoIt app running.

;
; Hot keys on shortcuts
;
dim $a_Lnks[5][2]
; DOS Ctrl+Alt+D
$a_Lnks[0][0] = @StartMenuDir & "\Programs\Accessories\Command Prompt.lnk"
$a_Lnks[0][1] = "^!d"

; Notepad Ctrl+Alt+N
$a_Lnks[1][0] =  @StartMenuDir & "\Programs\Accessories\Notepad.lnk"
$a_Lnks[1][1] = "^!n"

; Wordpad Ctrl+Alt+W
$a_Lnks[2][0] = @StartMenuCommonDir & "\Programs\Accessories\WordPad.lnk"
$a_Lnks[2][1] = "^!w"

; Calulator Ctrl+Alt+Shift+3
$a_Lnks[3][0] = @StartMenuCommonDir & "\Programs\Accessories\Calculator.lnk"
$a_Lnks[3][1] = "^!+3"

; Paint Ctrl+Alt+P
$a_Lnks[4][0] = @StartMenuCommonDir & "\Programs\Accessories\Paint.lnk"
$a_Lnks[4][1] = "^!p"

For $i = 0 to ubound($a_Lnks, 1) - 1
    If FileExists($a_Lnks[$i][0]) == 1 then
        $det = FileGetShortcut($a_Lnks[$i][0])
        If StringInStr($det[3],"-HK") == 0 then; Skip shortcuts that have already been modified
            FIleCopy($a_Lnks[$i][0], $a_Lnks[$i][0] & ".bak", 0)
            FileSetAttrib($a_Lnks[$i][0] & ".bak", "+H")
            FileCreateShortcut($det[0],$a_Lnks[$i][0], $det[1], $det[2], $det[3] & "-HK", $det[4], $a_Lnks[$i][1], $det[5], $det[6])
        EndIf
    EndIf
Next

I also have a context menu for folders. This will open a DOS prompt, even to UNC paths using pushd.

; Open a Command Prompt to current folder
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\cmd", "", "REG_SZ", "Open CMD Here")
; This will open the command prompt on UNC shares
RegWrite("HKEY_CLASSES_ROOT\Directory\shell\cmd\command", "", "REG_SZ", 'cmd.exe /k "pushd %L"')
Link to comment
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
 Share

  • Recently Browsing   0 members

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