[wpkg-users] Accessing file path within .bat file

Rainer Meier r.meier at wpkg.org
Sat May 15 12:52:43 CEST 2010


Hi,

On 15.05.2010 12:01, simplesi wrote:
> 
> I'm trying to write a package to deploy some files and then run an
> install.bat files afterwards
> [code]
> 	<install 
> 		cmd='xcopy "%PACKAGES%\heliumfrognet\*.*" "c:\apps\Helium_Frog_Netbook" /c
> /e /f /i /y' />
> 	<install 
> 		cmd='%COMSPEC% /C "c:\apps\Helium_Frog_Netbook\install.bat"' />
> [/code]
> the install.bat file works fine when run directly from explorer as %CD%
> contains its path and it needs it path to function but when I run it from
> WPKG it doesn't seem to know where it is :(

I guess this is just about the working directory. Your script pretty likely
accesses files within the Helium_Frog_Netbook\ directory and if run from outside
this directory it cannot access these files. The solution is simple. Either
change the working directory to the Helium_Frog_Netbook\ directory or use
absolute paths.


> If there a way of passing a parameter to the install.bat file so tell it
> that it is?

Not sure if I understand this question correctly... let's just read on.


> I'm sure this is a newbie question but I;m not a great cmd .bat person
> :embarassed: 

Well, we can still try to help.


> The reason for all this is that I'm going to be publicly publishing the
> whole thing as a zip file to non-WPKG users and those users will just be
> un-zipping and then double-clicking on the install.bat
> 
> Just for ref here is the install.bat
> [code]
> rem V1.2 install dlls and shortcuts
> 
> rem copy a couple of dlls to system32 (vb6 video capture related)
> 
> copy fsfwrap.dll "%SYSTEMROOT%\system32" /y >NUL 2>&1
> copy capstill.dll "%SYSTEMROOT%\system32" /y >NUL 2>&1
> 
> regsvr32 /s "%SYSTEMROOT%\system32\fsfwrap.dll" >NUL 2>&1
> regsvr32 /s "%SYSTEMROOT%\system32\capstill.dll" >NUL 2>&1
> 
> rem create shortcut using a vbs file that needs path to main exe
> cscript.exe createshortcut2.vbs "%CD%" >NUL 2>&1
> 
> 
> [code]

OK, here I see a couple of problems. Your files "fswrap.dll" and "capstill.dll"
are likely to be within th ZIP file and to resist within the
Helium_Frog_Netbook\ directory. You're using relative paths. So if the execute
path is for example at c:\temp\ it will look for this files at "c:\temp\fswrap.dll".

To fix this use absolute paths:

e.g.
[code]
@echo off

:: V1.2 install dlls and shortcuts
:: copy a couple of dlls to system32 (vb6 video capture related)

copy "%~dp0fsfwrap.dll" "%SYSTEMROOT%\system32" /y >NUL 2>&1
copy "%~dp0capstill.dll" "%SYSTEMROOT%\system32" /y >NUL 2>&1

regsvr32 /s "%SYSTEMROOT%\system32\fsfwrap.dll" >NUL 2>&1
regsvr32 /s "%SYSTEMROOT%\system32\capstill.dll" >NUL 2>&1

:: create shortcut using a vbs file that needs path to main exe
cscript.exe "%~dp0createshortcut2.vbs" "%CD%" >NUL 2>&1

[code]

What I miss here is the variable "CD" - should it point to some exe binary? You
definitely need to define this variable first... eg.

[code]
@echo off

:: V1.2 install dlls and shortcuts
:: copy a couple of dlls to system32 (vb6 video capture related)

set CD=%ProgramFiles%\app\app.exe

copy "%~dp0fsfwrap.dll" "%SYSTEMROOT%\system32" /y >NUL 2>&1
copy "%~dp0capstill.dll" "%SYSTEMROOT%\system32" /y >NUL 2>&1

regsvr32 /s "%SYSTEMROOT%\system32\fsfwrap.dll" >NUL 2>&1
regsvr32 /s "%SYSTEMROOT%\system32\capstill.dll" >NUL 2>&1

:: create shortcut using a vbs file that needs path to main exe
cscript.exe "%~dp0createshortcut2.vbs" "%CD%" >NUL 2>&1

[code]


Please note that the "%~dp0" variable is used within command scripts to get the
drive (d) and path (p) to the shell script actually executed. For example if you
execute "c:\temp\whatever.cmd" this just resolves to "c:\temp\".

Please also note that you are not supposed to append another "\" to the "%~dp0"
variable.

br,
Rainer



More information about the wpkg-users mailing list