Auto Increment version of setup project - c#

I need to increment version of an installer on every successful build. I have added a VBscript file and called it from a pre-build event. But am not able to get the actual result. my script is as under:
set a = wscript.arguments
if a.count = 0 then wscript.quit 1
'read and backup project file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(a(0))
s = f.ReadAll
f.Close
fbak = a(0) & ".bak"
if fso.fileexists(fbak) then fso.deletefile fbak
fso.movefile a(0), fbak
'find, increment and replace version number
set re = new regexp
re.global = true
re.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
set m = re.execute(s)
v = m(0).submatches(1)
v1 = split(v, ".")
v1(ubound(v1)) = v1(ubound(v1)) + 1
vnew = join(v1, ".")
'msgbox v & " --> " & vnew
s = re.replace(s, "$1" & vnew & """")
'replace ProductCode
re.pattern = "(""ProductCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'replace PackageCode
re.pattern = "(""PackageCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'write project file
fnew = a(0)
set f = fso.CreateTextfile(fnew, true)
f.write(s)
f.close
and my Pre-build Event is as C:\Projects\VersionProject\myscript.vbs "$(ProjectDir)VersionProject.Installer.vdproj" .Any help appreciated.

You'd need to go into the vdproj file and find the string of the form "ProductVersion" = "8:1.0.0"
and change the string from (say) 1.0.0 to 1.0.1.
However you're likely to get into trouble with updates if that's all you change. Note that when you increment the ProductVersion in the setup project it prompts to change ProductCode, and it will also change the PackageCode of the MSI file. So a safe change of the version involves all those things. For example, if you change only the version and attempt to reinstall the MSI it will fail with "Another version of this product is already installed". If you're unaware of these things, I suggest you familiarise yourself with how ProductCode, UpgradeCode, ProductVersion all interact, together with RemovePreviousVersions, and be aware that every new MSI created needs a new PackageCode.

Take a look at this. This Plugin allows you to set various options for the version number in your project.
And it does exactly what you need, auto increment the version number on each build . I've been using this for years and never had problems with it.
Update:
This Plugin only works if your project has an AssemblyInfo.cs

Related

Batch takes a part from the file name and create a folders with this part

I have files with names like this:
414_gtmlk_videos_Mas_147852_hty1147.xls
414_gtmlk_videos_Mas_P147852_hty1147.txt
I want to creat a job to check the filenames and take the part after Mas in the file name (147852-P147852)
and create a folders with this part name (the folder name should be: 147852-P147852).
And finally move each file to his folder.
Batch takes a part from the file name and create a folders with this part i have files with names like this:
414_gtmlk_videos_Mas_147852_hty1147.xls
414_gtmlk_videos_Mas_P147852_hty1147.txt (the folder name will be
here:147852-P147852)
Here's a way to do this with a Batch Script since you have this tagged as a batch-file in your question. Just set your source directory accordingly and the rest should just work based on the detail you provided and my understanding.
I used a simple batch FOR /F loop incorporating MD with IF conditions. I used the underbar characters as the delimiter and set the token to 5 to make this work.
#ECHO ON
SET Src=C:\Folder\Path
FOR /F "TOKENS=5 DELIMS=_" %%F IN ('DIR /B /A-D "%Src%\*.txt"') DO (
IF NOT EXIST "%Src%\%%~F-P%%~F" MD "%Src%\%%~F-P%%~F"
IF EXIST "%Src%\*%%~F*P%%~F*.txt" MOVE /Y "%Src%\*%%~F*P%%~F*.txt" "%Src%\%%~F-P%%~F"
)
GOTO EOF
Further Resources
FOR /F
IF
MD
FOR /?
delims=xxx - specifies a delimiter set. This replaces the
default delimiter set of space and tab.
tokens=x,y,m-n - specifies which tokens from each line are to
be passed to the for body for each iteration.
This will cause additional variable names to
be allocated. The m-n form is a range,
specifying the mth through the nth tokens. If
the last character in the tokens= string is an
asterisk, then an additional variable is
allocated and receives the remaining text on
the line after the last token parsed.
I have some C# code below. The first part does the following:
Gets paths
Get names of file
Modify full paths to get "147852" part, between __Mas_ and last _
string pathToGetFile = #"C:\\";
string[] filePaths = System.IO.Directory.GetFiles(pathToGetFile +#"\\", "*_Mas_*");
string[] fullName = new string[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
fullName[i] = filePaths[i].Substring(filePaths[i].LastIndexOf("\\") + 1);
filePaths[i] = filePaths[i].Substring(filePaths[i].LastIndexOf("_Mas_") + 5);
int l = filePaths[i].IndexOf("_");
filePaths[i] = filePaths[i].Substring(0, l);
Now you can create folders with yours names
filePaths is now like that: 147852, P147852
if (!Directory.Exists(#"C:\" + filePaths[i]))
System.IO.Directory.CreateDirectory(#"C:\" + filePaths[i]);
}
Now just move files to new directories
for (int i = 0; i < filePaths.Length; i++)
{
string sourceFile = System.IO.Path.Combine(pathToGetFile, fullName[i]);
string destFile = System.IO.Path.Combine(#"C:\" + filePaths[i], #"C:\" + filePaths[i] + "\\" + fullName[i]);
File.Copy(sourceFile,destFile,true);
}
Now, what happens
Files:
C:\414_gtmlk_videos_Mas_147852_hty1147.xls
C:\414_gtmlk_videos_Mas_P147852_hty1147.txt
They will be copied according to the:
C:\147852\
C:\P147852\

VBScript to Un-install windows application

I tried to uninstall the windows application exe which is already installed in my system using VBScript. But was not able to Uninstall the exe. Please help me on this. Thanks in advance.
I tried with following code:
Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."
'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{XXXXC6BA-0F96-4E3B-BB14-211E2805XXXX}"
'********************************
' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")
'**************************
UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
IF subkey = ProductCode Then
oShell.Run UninstallString, 1, True
End If
Next
Set oShell = Nothing
Set oReg = Nothing
MODIFIED CODE
Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."
'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{4AE9C6BA-0F96-4E3B-BB14-211E2805227E}"
'********************************
' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")
'**************************
UninstallString = """C:\Program Files\ASCO\DatabaseUpgradeUtility\ASCO Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
'UninstallString = "ASCO Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
InputBox(UninstallString)
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
'IF subkey = ProductCode Then
'.Run UninstallString, 1, True
'End If
IF subkey = ProductCode Then
oShell.Run "%COMSPEC% /k " & UninstallString, 1, True
End If
Next
Set oShell = Nothing
Set oReg = Nothing
tried the above and the path also trid with out double quotes also but both are not working. Please provide me if any thing that i have to change in the above script.
Your executable name has spaces in it, so you need to put double quotes around it, otherwise the shell object will try to run an executable Database, which cannot be found.
Change this line:
UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
into this:
UninstallString = """Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
Also, make sure that the path to Database Upgrade Utility.exe is in the PATH environment variable. If it isn't, you need to run the executable with its full path.
UninstallString = """C:\Program Files\ASCO\DatabaseUpgradeUtility\ASCO Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
If that doesn't work, check the following things:
Is the Run statement executed in the first place? Change the conditional like this to see if the code actually goes into the Then branch:
IF subkey = ProductCode Then
WScript.Echo "Subkey check OK."
oShell.Run UninstallString, 1, True
End If
Does the uninstall command return an error code?
IF subkey = ProductCode Then
rc = oShell.Run(UninstallString, 1, True)
If rc <> 0 Then WScript.Echo "Command returned with status code " & rc & "."
End If
Does the uninstall command produce output on the console?
IF subkey = ProductCode Then
oShell.Run "%COMSPEC% /k " & UninstallString, 1, True
End If

Copy specific folders to new location

Firs of, i am new here and hope you can help.
I am a systen engeneer and have to move (copy) 400 out of 500 folder's in a directory.
The folder names are uniek GUID {f199a57f-fbee-411b-a70e-32619f87e6aa} naming
Is there a VB or C# way to have the user input the 400 names of the folders that need to be copyd and let the scrip search them and copy the folders too a new location?
Thank you for your help...
Regards,
Wim
Wat i tried:
I tried this, but noting hapens :-(
Sub CopySomeFolder()
Dim FSO, sourceFolder, currentFile, filesInSourceFolder
Dim strSourceFolderPath
Dim strDestinationFolderPath
Dim strUserInput
Set FSO = CreateObject("Scripting.FileSystemObject")
' Figure out which folder to copy from where to where
strUserInput = InputBox("Please enter name of file to copy.")
strSourceFolderPath = "M:\"
strDestinationFolderPath = "M:\"
Set sourceFolder = FSO.GetFolder(strSourceFolderPath)
Set filesInSourceFolder = sourceFolder.Files
' Look at all folders in source folder. If name matches,
' copy to destination folder.
For Each currentFile In filesInSourceFolder
If currentFile.Name = strUserInput Then
currentFile.Copy (FSO.BuildPath(strDestinationFolderPath, _
currentFile.Name))
End If
Next
End Sub
Decide whether you need to copy folders or files
Don't be a sadist - asking a user to type 400 GUIDs into an InputBox!
Use dir to create the list of all 500 folder in a text file
Ask your asistent to delete the 100 not to be copied
Use a .bat or .vbs to copy the 400 remaining folders
This is simple to do. Example script that will read a text file and move them is as fallows;
Const ForReading = 1
Const list = "c:\list_of_folders.txt"
Const destination = "c:\temp\"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim folders : Set folders = fso.OpenTextFile(list, ForReading)
Dim folder
Do Until folders.AtEndOfStream
folder_loc = folders.ReadLine
If fso.FolderExists(folder_loc) Then
Set folder = fso.GetFolder(folder_loc)
folder.move(destination)
End If
Loop
Wscript.echo "Operation completed."
The list_of_folders.txt needs to have full paths.
First of, thank's for all your help...
We ended up using both answers. We got the DB admins to give us the GUIS's that have to be moved, slapt that in too 4 txt doc's, 1 for everyday of the migration. We used copy, not move for if something goes wrong.... here is the script i made...
Dim arrFileLines()
i = 0
set filesys = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserInput = InputBox ("Pathe to TXT file containing the folder names: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
strUserInputFrom = InputBox("Enter the directory path to the folders u want to copy: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
strUserInputTo = InputBox("Enter the destination folder: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
Set objFile = objFSO.OpenTextFile(strUserInput, 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Wscript.echo strUserInputFrom&"\"&arrFileLines(l) &" copy to " & strUserInputTo&"\"
filesys.CopyFolder strUserInputFrom&"\"&arrFileLines(l), strUserInputTo&"\"
Next
Please let me know if there is a better way, i like to learn :-)
Thanks

How to extract file paths from a text file

I am looking for a tool / code in C#, or C++ / C that can extract file paths from a file e.g.
File.txt:
Lorem Impusum
C:\Windows\System32\test.exe
C:\Users\Limited\Downloads.txt
testing 123
So it would output File.txt as follows:
C:\Windows\System32\test.exe
C:\Users\Limited\Downloads.txt
This should return what you're after, assuming you've loaded the contents of your file into a List<string> or string[]
var result = potentialPaths.Where(Path.IsPathRooted).ToList();
Also, this is C#.
Have a look at c# System.IO.Path.
Google is your friend.
You could use Regex, something like:
"([a-zA-Z]:)?(\\\\[a-zA-Z0-9_.-]+)+\\\\?"
http://www.regular-expressions.info/examples.html
There is an example how to do it in C++ here: http://www.gbresearch.com/axe/Reference.pdf
Here is an excerpt:
// windows path can start with a server name or letter
auto start_server = "\\\\" & +path_chars - '\\';
auto start_drive = r_alpha() & ':';
auto simple_path = (start_server | start_drive) & *('\\' & +path_chars);
auto quoted_path = '"' & (start_server | start_drive) &
*('\\' & +(space | path_chars)) & '"';
// path can be either simple or quoted
auto path = simple_path | quoted_path;
// rule to extract all paths
std::vector<std::wstring> paths;
size_t length = 0;
auto extract_paths = *(*(r_any() - (path >> e_push_back(paths) >> e_length(length)))
& r_advance(length));
You can customize the rules for your purposes. The rules will also work for unicode and binary files, no change necessary.

Outlook/Exchange - how to programmatically export users in distribution list?

How do I export all of the names and email addresses from a distribution list in Outlook using code? I have access to an Outlook 2000 or Outlook 2007 client. Ideally I would like the code to be in C#.
I realize you asked about c#, but the following script from http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips0524.mspx may be of some use.
Const olFolderContacts = 10
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items
intCount = colContacts.Count
For i = 1 To intCount
If TypeName(colContacts.Item(i)) = "DistListItem" Then
Set objDistList = colContacts.Item(i)
Wscript.Echo objDistList.DLName
For j = 1 To objDistList.MemberCount
Wscript.Echo objDistList.GetMember(j).Name & " -- " & _
objDistList.GetMember(j).Address
Next
Wscript.Echo
End If
Next
use outlook component model
http://www.dotnetjunkies.ddj.com/Tutorial/2E1EEEAF-C78A-4A38-A830-AC204B12DF83.dcik

Categories