| 1. |
Solve : Vista copy command failure? |
|
Answer» Vista Home edition: The SYSTEM cannot find the path specified.That indicates to me that when the batch is "Run as Administrator" it somehow LOSES it's ability to see the current drive (the USB drive), it then is unable to find the path. Is there any way to avoid this when running a batch file "as Administrator"? Or is there a way to use an environment variable that would specify the correct drive letter of the USB drive for me?I think "Run as administrator" changes the current directory. If you put the line... echo %cd% ... at the start of your batch you will see what it reports when run as ordinary user and as administrator. However there is a way around this - every batch file knows its own drive letter, path and name and some more stuff besides. The variable %0 holds the information and you can use the standard d,n,p,x, etc variable modifiers to extract it. You put a tilde (~) and a letter after the percent sign. For example %~d0 holds the drive letter and colon. You can use upper or lower case letters but the convention is to use lower case. So you could put Code: [Select]copy "%~d0\MiscDLLs\*.*" "C:\MyProgram\" Note that the directory, path, etc obtained this way refer to the actual drive that the batch is stored on and do not change, and are independent from the current directory that the batch is being run from, so I expect that this will be suitable for your purposes. This is IDme.bat. It is on a pendrive which has the letter G, in the root directory... Code: [Select]echo off echo Drive letter %~d0 echo Folder %~p0 echo Name %~n0 echo Extension %~x0 echo Drive\path\name %~dpnx0 echo fully qualified path %~f0 echo File date %~t0 echo File size in bytes %~z0 pause I double click on it in Explorer and I see this in the command window that opens... Code: [Select]Drive letter G: Folder \ Name IDme Extension .bat Drive\path\name G:\IDme.bat fully qualified path G:\IDme.bat File date 18/10/2010 06:25 PM File size in bytes 291 Press any key to continue . . . The variable modifiers also work on parameters %1 to %9 passed from the command line, as well as the FOR variables %%a - %%z and %%A - %%Z, and you can see a list in the FOR documentation obtained by tyoing FOR /? at the prompt. The date is shown according to your local settings. I'm sure that will work. It's exactly what I was looking for! Thanks! This is definately a keeper. I've already thought of a few other applications for the information you provided. Thanks again! |
|