0

i'm using vbscript to automated build of an app, and during the script before the building i need to update version number in a rc file, i got an .rc file with a PRODUCTVERSION and FILEVERSION that i want to incremented by one both of this values, the values are shown - 0.0.0.0, stil can't find a way to do it, build language is C#, i'm building it in VS2005 and VS2012

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Hebrew resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_HEB)
#ifdef _WIN32
LANGUAGE LANG_HEBREW, SUBLANG_DEFAULT
#pragma code_page(1255)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 3,0,27,0
 PRODUCTVERSION 3,0,27,0
 FILEFLAGSMASK 0x17L
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040004b0"
        BEGIN
            VALUE "FileDescription", "SHSAppli Dynamic Link Library"
            VALUE "FileVersion", "3, 0, 27, 0"
            VALUE "InternalName", "SHSAppli"
            VALUE "LegalCopyright", "Copyright (C) 2011"
            VALUE "OriginalFilename", "SHSAppli.dll"
            VALUE "ProductName", "SHSAppli Dynamic Link Library"
            VALUE "ProductVersion", "3, 0, 27, 0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x400, 1200
    END
END

#endif    // Hebrew resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED
Newton
  • 41
  • 1
  • 8

1 Answers1

1

Try with a reglar expression:

rcfile = "C:\path\to\your.rc"
major = 3
minor = 0
maint = 27
build = 0
version = major & "," & minor & "," & maint & "," & build

Set fso = CreateObject("Scripting.FileSystemObject")
Set re  = New RegExp
re.Global = True

rctext = fso.OpenTextFile(rcfile).ReadAll

re.Pattern = "(PRODUCTVERSION|FILEVERSION) \d+,\d+,\d+,\d+"
rctext = re.Replace(rctext, "$1 " & version)

re.Pattern = "(""(ProductVersion|FileVersion)"",) ""\d+, \d+, \d+, \d+"""
rctext = re.Replace(rctext, "$1 """ & Replace(version, ",", ", ") & """")

fso.OpenTextFile(rcfile, 2).Write rctext

If product and file version are not identical you need separate regular expressions for each.

Edit: For incrementing just the maintenance number I'd recommend using a replacement function:

rcfile = "C:\path\to\your.rc"

Set fso = CreateObject("Scripting.FileSystemObject")
Set re  = New RegExp
re.Global = True

Function IncMaint(m, g1, g2, g3, pos, src)
  IncMaint = g1 & (CInt(g2)+1) & g3
End Function

rctext = fso.OpenTextFile(rcfile).ReadAll

re.Pattern = "((?:PRODUCTVERSION|FILEVERSION) \d+,\d+,)(\d+)(,\d+)"
rctext = re.Replace(rctext, GetRef("IncMaint"))

re.Pattern = "(""(?:ProductVersion|FileVersion)"", ""\d+, \d+, )(\d+)(, \d+"")"
rctext = re.Replace(rctext, GetRef("IncMaint"))

fso.OpenTextFile(rcfile, 2).Write rctext
Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Tried this script, but it changes onlt the file version, how can make them auto incremented by one ? – Newton Nov 11 '13 at 13:02
  • I had something different in mind when I started writing the answer, and forgot to add `re.Global = True` when I changed my mind. Fixed. As for auto-incrementing: which number exactly do you want to increment? – Ansgar Wiechers Nov 11 '13 at 13:28
  • i need the product version and the file version up by 1 everytime i run this script – Newton Nov 11 '13 at 22:12
  • *\*sigh\** Perhaps you haven't noticed, but both the product and the file version consist of 4 numbers. So, which of these 4 numbers do you want to increment? – Ansgar Wiechers Nov 11 '13 at 22:19
  • oh, sorry, the "maint" :) – Newton Nov 11 '13 at 22:24
  • I ran both of the above listed scripts in .vbs files but I am getting the following error:Error: Invalid procedure call or argument Code: 800A0005 Source: Microsoft VBScript runtime error What could potentially be causing this error? – AhiyaHiya Jan 27 '14 at 21:45
  • @AhiyaHiya Please post a new question including the code you're using and indicate which line is raising the error. – Ansgar Wiechers Jan 27 '14 at 23:29
  • Question posted to http://stackoverflow.com/questions/21396199/vbs-script-attempting-to-write-to-rc-file-returns-error – AhiyaHiya Jan 28 '14 at 03:21