Jump to content











Photo
* * * - - 1 votes

[.cmd] find drive, set path, execute w/ params


  • Please log in to reply
31 replies to this topic

#26 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 20 February 2008 - 03:50 PM

This is interesting from MS KB:

The Create Shortcut command truncates the source path folder names to eight characters

Thanks for the link. That confirmes (now correct) my experience!

... and a strange work-around for .vbs using 'Subst j: c:\' to make a non-existent drive 'j:\' exist temporarily.

I also use this workaround. But there is a time bomb: What happens, if your local system already has the (sample) drive j: with different contents? I couldn't find a solution right now.

Regards :)


Answer see inside your post.

Peter

#27 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 23 February 2008 - 06:40 AM

Hi,

I'm still muddling along here.

The .cmd (named 'extdrive.cmd') now looks like this ... if it posts OK:

[codebox] @ECHO OFF :: This .cmd must be invoked with a parameter pointing to a :: executable file, including RELATIVE path, such as: :: \Tools\image.exe :: BEFORE any parameter the executable might need. :: Input PARAMETERS: :: (0. ExtDrive.cmd) :: 1. Path without Drive letter :: 2. Arguments - eg 'doc.txt' as in 'notepad.exe doc.txt' :: 3. Description :: 4. Hotkey :: 5. WindowStyle - 1. Restore/Normal 3. Min. 7. Max. :: 6. Working Directory :: 7. Not Yet Implemented..IconLocation - Path :: 8. Not Yet Implemented..IconLocation - Icon Index :: 9. Not Yet Implemented.. :: Shortcut Location - Special Folder - 'Programs', :: 'Desktop','AllUsersPrograms', 'AllUsersDesktop' SET target=%1 SET params=%* FOR %%A in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ( IF EXIST %%A:%target% SET drive_letter=%%A&GOTO :File_Found ) ECHO %target% not found!&PAUSE GOTO :EOF :File_found ECho Found %drive_letter%:%1 SET name=%~n1 ECHO Filename: %name% CALL :Make_Shortcut %drive_letter% %name% GOTO :EOF :Make_shortcut :: Output PARAMETERS: :: 0. Drive Letter :: 1. Filename :: 2. Path without Drive Letter :: 3. Arguments - eg 'doc.txt' as in 'notepad.exe doc.txt' :: 4. Description :: 5. Hotkey :: 6. WindowStyle - 1. Restore/Normal 3. Min. 7. Max. :: 7. Working Directory :: 8. Not Yet Implemented..IconLocation - Path :: 9. Not Yet Implemented..IconLocation - Icon Index :: 10. Not Yet Implemented.. :: Shortcut Location - Special Folder - 'Programs', :: 'Desktop','AllUsersPrograms', 'AllUsersDesktop' ECHO %params% PAUSE CScript x:\windows\system32\Make_shortcut.vbs %1 %2 %params% GOTO :EOF [/codebox] ... now running the whole lot at boot time. The startnet.cmd in the Windows PE Startup folder works OK, but it only runs the first 'extdrive.cmd' line - it only creates the first Shortcut. How do I get the next lines in 'startnet.cmd' to run? What am I missing? Probably something very basic!? Here's a pic of the 'startnet.cmd' and 'make_shortcut.cmd' in Windows PE:

[attachment=4453:extdrive.png]

... a bit difficult to copy and paste from there ATM.

Help is much appreciated. Thanks :)

#28 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7100 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 23 February 2008 - 09:27 AM

OK, I'm lost. :)

One little thing, before I start understanding the logic of the program.

This:
SET target=%1

SET params=%*
and this:
CALL :Make_Shortcut %drive_letter% %name%
makes this:
:: Input PARAMETERS:
:: (0. ExtDrive.cmd)
:: 1. Path without Drive letter
:: 2. Arguments - eg 'doc.txt' as in 'notepad.exe doc.txt'
:: 3. Description
:: 4. Hotkey
:: 5. WindowStyle - 1. Restore/Normal 3. Min. 7. Max.
:: 6. Working Directory
:: 7. Not Yet Implemented..IconLocation - Path
:: 8. Not Yet Implemented..IconLocation - Icon Index
BECOMES this:
:: Output PARAMETERS:
:: 0. Drive Letter
:: 1. Filename
:: 2. Path without Drive Letter
:: 3. Arguments - eg 'doc.txt' as in 'notepad.exe doc.txt'
:: 4. Description
:: 5. Hotkey
:: 6. WindowStyle - 1. Restore/Normal 3. Min. 7. Max.
:: 7. Working Directory
:: 8. Not Yet Implemented..IconLocation - Path
:: 9. Not Yet Implemented..IconLocation - Icon Index

Effectively shifting parameters by one.
Is this intentional?

In the .vbs there is no need for output parameter 1. (or are you going to change the "test.lnk")? :(

jaclaz

#29 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 23 February 2008 - 09:30 AM

.... Found the answer... Needed 'Call ExtDrive.cmd ...' in the 'startnet.cmd'. Calling a batch from a batch 'without stopping the parent batch program.'

:)

#30 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 23 February 2008 - 10:10 AM

OK, I'm lost. :(


Well, I'm just starting to find my way, I hope. And our posts crossed in cyber-space again. Thanks for the reply.

...
Effectively shifting parameters by one.
Is this intentional?

In the .vbs there is no need for output parameter 1. (or are you going to change the "test.lnk")?


I have discovered that 'Shift has no affect on the %* batch parameter.' The %* always retains the original parameters.

I'm adding two new parameters - 'drive_letter' and 'name' rather than shifting the originals.

So having to keep all the original input parameters including 'Path without Drive Letter' parameter, it is not really necessary to pass a 'Full Path' as an output parameter to the .vbs - only require the new 'Drive Letter' parameter, and add it to the 'Path without Drive Letter' parameter in the .vbs script separated by ':'.

You are spot on with the 'name' parameter, eventually it will name the .lnk.

... it all makes sense to me. :cheers:

... trying to understand someone elses code could be a nightmare. If I can get the overall picture to you, I would greatly value your help. Your code looked so much more polished than mine. I do not want to mess it up.

Also, 'PUSHD' worked when finding the drive letter for programs that are actually on the System Drive. (I'm using the Script for all Programs - not only those on External Drives.) But didn't seem to work with programs on External Drives... I'm not actually sure what it does, but everything worked with your batch when simply looking for something in x:\programs\ for example. Then seemed to fail when the program was shifted to the external media. ?

Thanks again. :)

#31 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7100 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 23 February 2008 - 12:44 PM

allanf, just for the fun of it, I don't want to be a teacher, mind you, this is how I would write your batch:
[codebox] ::< This .cmd must be invoked with a parameter pointing to a ::< executable file, including absolute path, such as: ::< C:\Tools\image.exe (don&#39;t worry, the batch will fix to the RIGHT ::< drive letter... ::< BEFORE any parameter the executable might need. ::< Input PARAMETERS: ::< (0. ExtDrive.cmd) ::< 1. Filename with full path ::< 2. Arguments - eg &#39;doc.txt&#39; as in &#39;notepad.exe doc.txt&#39; ::< 3. Description ::< 4. Hotkey ::< 5. WindowStyle - 1. Restore/Normal 3. Min. 7. Max. ::< 6. Working Directory ::< 7. Not Yet Implemented..IconLocation - Path ::< 8. Not Yet Implemented..IconLocation - Icon Index ::< 9. Not Yet Implemented.. ::< 10. Not Yet Implemented.. ::< Shortcut Location - Special Folder - &#39;Programs&#39;, ::< &#39;Desktop&#39;,&#39;AllUsersPrograms&#39;, &#39;AllUsersDesktop&#39; ::> Output PARAMETERS: ::> 0. Filename (i.e. name of link) ::> 1. Filename with full path ::> 2. Arguments - eg &#39;doc.txt&#39; as in &#39;notepad.exe doc.txt&#39; ::> 3. Description ::> 4. Hotkey ::> 5. WindowStyle - 1. Restore/Normal 3. Min. 7. Max. ::> 6. Working Directory ::> 7. Not Yet Implemented..IconLocation - Path ::> 8. Not Yet Implemented..IconLocation - Icon Index ::> 9. Not Yet Implemented.. ::> 10. Not Yet Implemented.. ::> Shortcut Location - Special Folder - &#39;Programs&#39;, ::> &#39;Desktop&#39;,&#39;AllUsersPrograms&#39;, &#39;AllUsersDesktop&#39; @ECHO OFF SETLOCAL ENABLEEXTENSIONS SETLOCAL ENABLEDELAYEDEXPANSION SET /A NumParams=0 SET /A TotParams=6 FOR %%A IN ( %*) DO ( SET /A NumParams=!NumParams!+1 SET VAR!NumParams!=%%A ) IF %Numparams% LEQ %Totparams% GOTO :MissingParams PAUSE ECHO %~d1 ECHO %~pnx1 PAUSE SET VAR1=%~pnx1 FOR %%A in (Z Y X W V U T S R Q P O N M L K J I H G F E D C) DO ( IF EXIST %%A:%VAR1% SET VAR1=%%A:%VAR1% &GOTO :File_Found ) CLS&ECHO Problem!&ECHO %VAR1% not found!&PAUSE GOTO :EOF :File_found ECho Found %VAR1% ECHO Filename: %~n1 SET params=%~n1 %VAR1% %VAR2% %VAR3% %VAR4% %VAR5% %VAR6% %VAR7% %VAR8% %VAR9% PAUSE CALL :Make_Shortcut %params% GOTO :EOF :Make_shortcut ECHO %params% PAUSE ECHO CScript x:\windows\system32\Make_shortcut.vbs %params% GOTO :EOF :MissingParams CLS ECHO ERROR! A required parameter is missing, or wrong FOR /F "tokens=*" %%A IN (&#39;TYPE %~dpnx0 ^| FIND "::<" ^| FIND /V "FIND /V"&#39;) DO ECHO %%A [/codebox] and no, it is NOT better than yours, only a bit complicated, but it has a few minor advantages :): a. path and filename are supplied as usual (absolute) b. it "keeps" variables with same number in output and output c. it checks for missing parameters and displays howto
and of course uses some other commands/syntax....

jaclaz

#32 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 23 February 2008 - 04:04 PM

Hi jaclaz,

Don't take this personally, but I think there is a 'PAUSE' missing from the very end of your Script! ... :)

What more can I say? Thank you!

Some things I have noted:

I have implemented the .vbs 'IconLocation' argument as a single input/output parameter #7, like so - "Path, Index". The initial setting 'SET /A TotParams=6' works with (requires?) parameters up to #7 (i. e. eight input parameters including #0, the batch-file name).

... setting the Path to an Icon file with an unknown drive letter? Oh!

And now that things are working, I have discovered that Filename might not have been such a good idea for the name of the .lnk. This became very evident with the two shortcuts, 'wpeutil.exe shutdown' and 'wpeutil.exe reboot' - one over-writing the other. I'll think about whether those two should be set aside for special treatment, or universally use the 'Description' argument.

:(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users