Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi how write version of a file in a text file, by a batch file?

What I have tried:

have a batch file that writes version of a specified file in a text file.
Posted
Updated 18-Apr-17 1:04am
v2
Comments
CHill60 18-Apr-17 7:02am    
Are you expecting the batch file to query the file for its' version? What kind of file is it and how is the version number stored?
Zon-cpp 18-Apr-17 7:20am    
It is a .dll file that was created by C# and it's version was defined in AssemblyInfo.cs

1 solution

This would be hard to answer for anybody that has not seen your previous question How do I know the DLL version, in compile time?[^]

An example using the sigcheck utility from the SysInternals suite:
@ECHO off
REM Specify source directory of your project here
SET outputdir=c:\projects\myproject\
REM Execute sigcheck to print only file version and redirect to a temp file
path-to-sigcheck\sigcheck -n -q path-to-dll >%outputdir%temp.txt
REM Get file content into a variable
SET /p FILEVER=<%outputdir%temp.txt
REM Create header file
ECHO #pragma once > %outputdir%dll_ver.h
ECHO #define MY_DLL_VERSION _T("%FILEVER%") >> %outputdir%dll_ver.h
REM Uncomment to show the created file
REM type %outputdir%dll_ver.h

[EDIT]
Added the _T() macro to the string printed to the header file.
[/EDIT]
 
Share this answer
 
v2
Comments
Zon-cpp 18-Apr-17 7:24am    
I want to get version of 'my file' in CustomBuildStep of my project and write it in a text file. then in about window show that text file as version of my file.
Jochen Arndt 18-Apr-17 7:30am    
At first you need an utilty to get the version from a file.
I have used sigcheck in my example.
The example writes the output to a text file (temp.txt in my example).

It then creates a header file dllver.h. I have done that because it can be included in your source file (#include "dll_ver.h"). There you can use the MY_DLL_VERSION string to create the string to be shown in the dialog box.

Save the example file using a .bat extension and execute it as custom build step.
Zon-cpp 18-Apr-17 7:46am    
Thank you, that is what i want.
But how do i get "sigcheck" utilty?
Jochen Arndt 18-Apr-17 7:49am    
From the link in my previous answer:
https://technet.microsoft.com/en-us/sysinternals/bb897441.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900