Jump to content

How can I use CmdLine?


Recommended Posts

I'm trying get the name of a file that was associate with my autoit exe.

When I click on a file "a.cpt" in my desktop my exe file open but I can't get the name of file ("a.cpt") in CmdLine Parameters...

What I need put in my script to get the name of file ('a.cpt')?

Thanks for help...

Link to comment
Share on other sites

Show us the code you used to associate .cpt files with your application. It seems that if double-clicking on the .cpt file does the hard part and opens your application correctly, it should also pass the name or fullpath of the file clicked on. You must have made a mistake in the code that created the association. Usually, you just use " %1" at the end of the registry data entry that specifies the path to your application.

That accomplished, $CmdLine[1] should contain the filepath.

Das Häschen benutzt Radar

Link to comment
Share on other sites

Show us the code you used to associate .cpt files with your application. It seems that if double-clicking on the .cpt file does the hard part and opens your application correctly, it should also pass the name or fullpath of the file clicked on. You must have made a mistake in the code that created the association. Usually, you just use " %1" at the end of the registry data entry that specifies the path to your application.

That accomplished, $CmdLine[1] should contain the filepath.

I use this

FileRegister("cpt",@ScriptDir & "\cpt.exe","Open with cpt.exe",1,@ScriptDir & "\cpt.ico","cpt file")




;==============================================================================================
;
; Description:      FileRegister($ext, $cmd, $verb[, $def[, $icon = ""[, $desc = ""]]])
;                   Registers a file type in Explorer
; Parameter(s):     $ext -  File Extension without period eg. "zip"
;                   $cmd -  Program path with arguments eg. '"C:\test\testprog.exe" "%1"'
;                           (%1 is 1st argument, %2 is 2nd, etc.)
;                   $verb - Name of action to perform on file
;                           eg. "Open with ProgramName" or "Extract Files"
;                   $def -  Action is the default action for this filetype
;                           (1 for true 0 for false)
;                           If the file is not already associated, this will be the default.
;                   $icon - Default icon for filetype including resource # if needed
;                           eg. "C:\test\testprog.exe,0" or "C:\test\filetype.ico"
;                   $desc - File Description eg. "Zip File" or "ProgramName Document"
;
;===============================================================================================
Func FileRegister($ext, $cmd, $verb, $def = 0, $icon = "", $desc = "")
    Local $loc, $curicon, $oldicon, $oldverb, $olddesc, $oldcmd, $curdesc, $curverb, $curcmd
    
    $loc = RegRead("HKCR\." & $ext, "")
    If @error Then
        RegWrite("HKCR\." & $ext, "", "REG_SZ", $ext & "file")
        $loc = $ext & "file"
    EndIf
    $curdesc = RegRead("HKCR\" & $loc, "")
    If @error Then
        If $desc <> "" Then
            RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)
        EndIf
    Else
        If $desc <> "" And $curdesc <> $desc Then
            RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)
            RegWrite("HKCR\" & $loc, "olddesc", "REG_SZ", $curdesc)
        EndIf
        If $curdesc = "" And $desc <> "" Then
            RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)
        EndIf
    EndIf
    $curverb = RegRead("HKCR\" & $loc & "\shell", "")
    If @error Then
        If $def = 1 Then
            RegWrite("HKCR\" & $loc & "\shell", "", "REG_SZ", $verb)
        EndIf
    Else
        If $def = 1 Then
            RegWrite("HKCR\" & $loc & "\shell", "", "REG_SZ", $verb)
            RegWrite("HKCR\" & $loc & "\shell", "oldverb", "REG_SZ", $curverb)
        EndIf
    EndIf
    $curcmd = RegRead("HKCR\" & $loc & "\shell\" & $verb & "\command", "")
    If Not @error Then
        RegRead("HKCR\" & $loc & "\shell\" & $verb & "\command", "oldcmd")
        If @error Then
            RegWrite("HKCR\" & $loc & "\shell\" & $verb & "\command", "oldcmd", "REG_SZ", $curcmd)
        EndIf
    EndIf
    RegWrite("HKCR\" & $loc & "\shell\" & $verb & "\command", "", "REG_SZ", $cmd)
    If $icon <> "" Then
        $curicon = RegRead("HKCR\" & $loc & "\DefaultIcon", "")
        If @error Then
            RegWrite("HKCR\" & $loc & "\DefaultIcon", "", "REG_SZ", $icon)
        Else
            RegWrite("HKCR\" & $loc & "\DefaultIcon", "", "REG_SZ", $icon)
            RegWrite("HKCR\" & $loc & "\DefaultIcon", "oldicon", "REG_SZ", $curicon)
        EndIf
    EndIf
EndFunc

thanks for help

Link to comment
Share on other sites

That script had a few problems with it. Try this (triple-left-click the code to select it) -

FileRegister('cpt', '"' & @ScriptDir & '\cpt.exe" "%1"', "Catapult It", 1, _
    '"' & @ScriptDir & '\cpt.ico"', "Catapult File")

;==============================================================================================
; Name:         FileRegister
; Description:  Registers a file type in Explorer
; Syntax:
;               FileRegister($ext, $cmd, $verb [, $def [, $icon = "" [, $desc = "" ]]] )
; Parameter(s):
;               $ext -  File Extension without period eg. "zip"
;               $cmd -  Program path with arguments (%1 is 1st argument, %2 is 2nd, etc.)
;                           Enclose the path in double-quotes if it has any spaces in it and
;                           enclose the whole thing in single-quotes.
;                           examples:
;                               'C:\test\testprog.exe "%1"'
;                               '"C:\Program Files\Windows Media Player\wmplayer.exe" /Play "%L"'
;               $verb - Name of action to perform on file
;                           examples:
;                               'Open with ProgramName'
;                               'Extract Files'
;                               'open'
;                               'edit'
;               $def -  Action is the default action for this filetype (1 for true 0 for false)
;                           If the file is not already associated, this will be the default.
;               $icon - Default icon for filetype including resource # if needed
;                           Enclose the path in double-quotes if it has any spaces in it.
;                           examples:,
;                               '"C:\Program Files\NetMeeting\conf.exe",1'
;                               'C:\test\testprog.exe,0'
;                               'C:\test\filetype.ico'
;               $desc - File Description eg. "Zip File" or "ProgramName Document"
; Returns:
;               None.
; Authors:      Squirrely1 & ?
;===============================================================================================
Func FileRegister($ext, $cmd, $verb, $def = 0, $icon = "", $desc = "")
    Local $loc, $curicon, $oldicon, $oldverb, $olddesc, $oldcmd
    Local $curdesc, $curverb, $curcmd, $curDefaultVerb
    
    ; Write a new root entry if needed ...
    $loc = RegRead("HKCR\." & $ext, "")
    If @error Then
        RegWrite("HKCR\." & $ext, "", "REG_SZ", $ext & "file")
        $loc = $ext & "file"
    EndIf
    $curdesc = RegRead("HKCR\" & $loc, "")
    If @error Then
        RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)
    Else
        If $desc <> "" And $curdesc <> $desc Then
            RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)
            RegWrite("HKCR\" & $loc, "olddesc", "REG_SZ", $curdesc)
        EndIf
        If $curdesc = "" And $desc <> "" Then
            RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)
        EndIf
    EndIf
    
    ; Set the default verb conditionally ...
    $curDefaultVerb = RegRead("HKCR\" & $loc & "\shell", "")
    If @error Then
        If $def = 1 Then
            RegWrite("HKCR\" & $loc & "\shell", "", "REG_SZ", $verb)
        EndIf
    Else
        If $def = 1 Then
            RegWrite("HKCR\" & $loc & "\shell", "", "REG_SZ", $verb)
            RegWrite("HKCR\" & $loc & "\shell", "oldverb", "REG_SZ", $curDefaultVerb)
        EndIf
    EndIf
    
    ; Create or re-write the passed verb ...
    $curverb = RegRead("HKCR\" & $loc & "\shell\" & $verb, "")
    If @error Then
        If $def = 1 Then
            RegWrite("HKCR\" & $loc & "\shell\" & $verb, "", "REG_SZ", $verb)
        EndIf
    Else
        If $def = 1 Then
            RegWrite("HKCR\" & $loc & "\shell\" & $verb, "", "REG_SZ", $verb)
            RegWrite("HKCR\" & $loc & "\shell\" & $verb, "oldverb", "REG_SZ", $curverb)
        EndIf
    EndIf
    
    ; Write the complete, new commandline for this verb ...
    $curcmd = RegRead("HKCR\" & $loc & "\shell\" & $verb & "\command", "")
    If Not @error Then
        RegRead("HKCR\" & $loc & "\shell\" & $verb & "\command", "oldcmd")
        If @error Then
            RegWrite("HKCR\" & $loc & "\shell\" & $verb & "\command", "oldcmd", "REG_SZ", $curcmd)
        EndIf
    EndIf
    RegWrite("HKCR\" & $loc & "\shell\" & $verb & "\command", "", "REG_SZ", $cmd)
    
    ; Write the icon to use ...
    If $icon <> "" Then
        $curicon = RegRead("HKCR\" & $loc & "\DefaultIcon", "")
        If @error Then
            RegWrite("HKCR\" & $loc & "\DefaultIcon", "", "REG_SZ", $icon)
        Else
            RegWrite("HKCR\" & $loc & "\DefaultIcon", "", "REG_SZ", $icon)
            RegWrite("HKCR\" & $loc & "\DefaultIcon", "oldicon", "REG_SZ", $curicon)
        EndIf
    EndIf
EndFunc   ;==>FileRegister

Not tested !

Edit 1: If you wrote that first version of the script, then if I were you, I wouldn't clutter up my registry with those backup strings - instead, just export the relevant keys.

Edit 2: Code updated.

Edit 3: Post text updated.

Edit 4: Code and its documentation updated.

Edit 5: Everything updated.

Edit 6: Documentation and code updated.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

That script had a few problems with it. Try this (triple-left-click the code to select it) -

CODE
Global $contextMenuEntry = "Catapult"

Global $formalDescription = "A Fabulous .CPT file"; enter your own description.

Global $EXE = @ScriptDir & "\cpt.exe"

Global $myICO = @ScriptDir & "\cpt.ico"

If StringInStr($EXE, " ") Then

; Put a set of double-quotes around the filepath - best for backward compatibility I think.

; Also, you forget to read the documentation - %1 is needed ...

$EXE = '"' & $EXE & '"' & ' "%1"'

Else

; Just add the %1 to the string ...

$EXE &= ' "%1"'

EndIf

FileRegister("cpt", $EXE, $contextMenuEntry, 1, $myICO, $formalDescription)

;==============================================================================================

; Name: FileRegister

; Description: Registers a file type in Explorer

; Syntax: FileRegister($ext, $cmd, $verb[, $def[, $icon = ""[, $desc = ""]]])

; Parameter(s):

; $ext - File Extension without period eg. "zip"

; $cmd - Program path with arguments eg. '"C:\test\testprog.exe" "%1"'

; (%1 is 1st argument, %2 is 2nd, etc.)

; $verb - Name of action to perform on file

; eg. "Open with ProgramName" or "Extract Files"

; ; this string should probably have no spaces in it

; like "open" or "Execute".

; $def - Action is the default action for this filetype

; (1 for true 0 for false)

; If the file is not already associated, this will be the default.

; $icon - Default icon for filetype including resource # if needed

; e.g., "C:\test\testprog.exe,0" or "C:\test\filetype.ico"

; $desc - File Description eg. "Zip File" or "ProgramName Document"

; Returns:

; None.

; Authors: Squirrely1 & ?

;===============================================================================================

Func FileRegister($ext, $cmd, $verb, $def = 0, $icon = "", $desc = "")

Local $loc, $curicon, $oldicon, $oldverb, $olddesc, $oldcmd

Local $curdesc, $curverb, $curcmd, $curDefaultVerb

Local $ext2 = StringLower($ext)

$loc = RegRead("HKCR\." & $ext2, "")

If @error Then

RegWrite("HKCR\." & $ext2, "", "REG_SZ", $ext2 & "file")

$loc = $ext2 & "file"

EndIf

; Write a new root entry ...

$loc = $ext2 & "file"

$curdesc = RegRead("HKCR\" & $loc, "")

If @error Then

RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)

Else

If $desc <> "" And $curdesc <> $desc Then

RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)

RegWrite("HKCR\" & $loc, "olddesc", "REG_SZ", $curdesc)

EndIf

If $curdesc = "" And $desc <> "" Then

RegWrite("HKCR\" & $loc, "", "REG_SZ", $desc)

EndIf

EndIf

; Set the default verb conditionally ...

$curDefaultVerb = RegRead("HKCR\" & $loc & "\shell", "")

If @error Then

If $def = 1 Then

RegWrite("HKCR\" & $loc & "\shell", "", "REG_SZ", $verb)

EndIf

Else

If $def = 1 Then

RegWrite("HKCR\" & $loc & "\shell", "", "REG_SZ", $verb)

RegWrite("HKCR\" & $loc & "\shell", "oldverb", "REG_SZ", $curDefaultVerb)

EndIf

EndIf

; Create or re-write the passed verb ...

$curverb = RegRead("HKCR\" & $loc & "\shell\" & $verb, "")

If @error Then

If $def = 1 Then

RegWrite("HKCR\" & $loc & "\shell\" & $verb, "", "REG_SZ", $verb)

EndIf

Else

If $def = 1 Then

RegWrite("HKCR\" & $loc & "\shell\" & $verb, "", "REG_SZ", $verb)

RegWrite("HKCR\" & $loc & "\shell\" & $verb, "oldverb", "REG_SZ", $curverb)

EndIf

EndIf

; Write the complete, new commandline for this verb ...

$curcmd = RegRead("HKCR\" & $loc & "\shell\" & $verb & "\command", "")

If Not @error Then

RegRead("HKCR\" & $loc & "\shell\" & $verb & "\command", "oldcmd")

If @error Then

RegWrite("HKCR\" & $loc & "\shell\" & $verb & "\command", "oldcmd", "REG_SZ", $curcmd)

EndIf

EndIf

RegWrite("HKCR\" & $loc & "\shell\" & $verb & "\command", "", "REG_SZ", $cmd)

; Write the icon to use ...

If $icon <> "" Then

$curicon = RegRead("HKCR\" & $loc & "\DefaultIcon", "")

If @error Then

RegWrite("HKCR\" & $loc & "\DefaultIcon", "", "REG_SZ", $icon)

Else

RegWrite("HKCR\" & $loc & "\DefaultIcon", "", "REG_SZ", $icon)

RegWrite("HKCR\" & $loc & "\DefaultIcon", "oldicon", "REG_SZ", $curicon)

EndIf

EndIf

EndFunc ;==>FileRegister

Not tested !

Edit 1: If you wrote that first version of the script, then if I were you, I wouldn't clutter up my registry with those backup strings - instead, just export the relevant keys.

Edit 2: Code updated.

Edit 3: Post text updated.

Edit 4: Code and its documentation updated.

Edit 5: Everything updated.

Works.. thanks a lot for your help...

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...