How do I generate a file based on user input in MSI created using WixSharp? - wixsharp

I created an installation MSI package using WixSharp. I have a custom dialog with language, server, etc. options. I want to generate an application config file based on these options and deploy it next to the .exe file as part of an installation process. If it is possible, how should I do that?

You can subscribe on AfterInstall event (when files has been coppied) and modify your config file there.
AfterInstall demostration
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
Installation directory you can find here:
private void OnAfterInstall(SetupEventArgs e)
{
var installationPath = e.Session["INSTALLDIR"];
// Change your config file here
// if you need to modify your file once time after installation
// just add this one condition if (e.IsInstalled) { ... }
}

Related

Razor pages not update until restart project

I add Volo.Account module with source code to my solution for update some functionality of Login/Register. When I update page (like Login.cshtml) changes not shown until restart project.
According to Microsoft doc, I instal Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package and line below to ConfigureServices of {PROJECT}AuthServerModule, but RuntimeCompilation not working.
context.Services.AddRazorPages()
.AddRazorRuntimeCompilation();
actually you don't need to use AddRazorRuntimeCompilation in your application. You can get the advantage of ABP's Virtual File System and configure the AbpVirtualFileSystemOptions in your application module class:
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
//other configurations...
if (hostingEnvironment.IsDevelopment())
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.ReplaceEmbeddedByPhysical<AbpAccountWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("<web-module-project-path>")));
});
}
}
You just need to use the ReplaceEmbeddedByPhysical method. Check the following links for more info:
https://docs.abp.io/en/abp/latest/Virtual-File-System#dealing-with-embedded-files-during-development
https://github.com/abpframework/abp/blob/dev/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs#L148

how to download exe files in vb.net (Visual Studio 2015)

I try make one program for download one .exe file and run for help in my job.
But idk how to make this, i'm new in VB.
I am using this code, as shown in the Visual Basic document reference:
My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/WineList.txt", _
"C:\Documents and Settings\All Users\Documents\WineList.txt")
But when I try to download an .exe file, the entire file doesn't complete and I the file is only 1 kb after download.
The webclient should be the way to go a comment above highlights that too.
This is an example from another question:
Either use sync method:
public void DownloadFile()
{
using(var client = new WebClient())
{
client.DownloadFile(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Or use new async-await approach:
public async Task DownloadFileAsync()
{
using(var client = new WebClient())
{
await client.DownloadFileTaskAsync(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Then call this method like this:
await DownloadFileAsync();
Open up the .exe file you are trying to download in a text editor like NotePad. Odds are what is being downloaded is an HTML page showing some kind of error message like 404 not found.
Another possibility might be that AntiVirus software is moving the original EXE into quarantine and replacing it with a Quarantine MetaData file.
If the file does actually contain binary content your connection could be getting interrupted but odds are if this happened an exception would be thrown.

Script or utility to change permissions on sub folder of the same name in Windows

I have a parent folder call Projects, under that I have over 400 folders with a separate folder name (eg. Project1, Project2, etc). Under each Project folder there is a standard folder called Management, that should have restricted access but they don't. I would like to change the permissions for this Management subfolder, within all the projects (same permissions). If anyone has an idea on how to do this it would really be appreciated, thanks.
Scott.
Here's a simple Java application that does about what you're asking. If I misinterpreted anything, you can probably fix it but I'm assuming your main task was to figure out how to modify permissions of only specific files.
My solution was to loop through the current directory's fplders (that being the directory that houses all the project files) and then through each project folder to find each management folder. Then, I used the icacls command to remove permission from a specific user.
public static void main(String[] args) {
File file = new File("directory path");
Runtime runtime = Runtime.getRuntime();
for(File pfolder : file.listFiles()) { // Loop through project folders
if(pfolder.isDirectory()) {
for(File mfolder : file.listFiles()) { // Find management folder
if(mfolder.getName().equals("Management")) {
try {
runtime.exec("icacls "+mfolder.getAbsolutePath()+" /deny USERNAME");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
}
}
Be sure to modify the initial directory value (make it an absolute path) and the username who's permissions you are removing. Hope this helps!

Launching .vsto file after installation. (InstallShield)

I have an msi installer, made via InstallShield, which moves some files to required location,
writes some info to registry and installes VSTO runtime. But I need to launch the .vsto file, that is installed with the application, after the installation is over. Can I do this with custom actions? If that file was an .exe file, that would be rather easy, but how could I launch a .vsto file?
[upd]
Well, may be there is an easier solution:
Can I just call the function:
public override void Install(IDictionary stateSaver)
from InstallShield? Something like that:
Custom Action->Call a function in a Windows Installer dynamic link library->stored in binary table=>
AssemblyFile = \InclusionListCustomActions.dll
MethodSignature = InclusionListCustomActions.TrustInstaller.Install(but what parameter goes here?)
You shouldn't launch the VSTO file because this will only install it per-user. What you should do is add it to the AddIns registry key for the office application you need and use the |vstolocal attribute to tell it to not deploy to the click once cache.
you can follow steps described in http://msdn.microsoft.com/en-us/library/cc563937%28v=office.12%29.aspx, you can copy same steps in Installshield, After file is copied and registry value set as specified, on starting office app it will automatically pick up vsto file
To add information to inclusion list you will have to write a console application and then call console app from installshield. Below code will help
string RSA_PublicKey = #"<RSAKeyValue><Modulus></Modulus></RSAKeyValue>";
//get this key from .vsto file
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
Console.WriteLine(
"You have insufficient privileges to " +
"register a trust relationship. Start Excel " +
"and confirm the trust dialog to run the addin.");
Console.ReadLine();
}
Uri deploymentManifestLocation = null;
var excelPath = YourAPPPath;
if (Uri.TryCreate(excelPath,
UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false)
{
Console.WriteLine(
"The location of the deployment manifest is missing or invalid.");
Console.ReadLine();
}
if (!File.Exists(excelPath))
{
UserInclusionList.Remove(deploymentManifestLocation);
Console.WriteLine(deploymentManifestLocation.ToString() + "removed from inclusion list");
}
else
{
AddInSecurityEntry entry = new AddInSecurityEntry(
deploymentManifestLocation, RSA_PublicKey);
UserInclusionList.Add(entry);
Console.WriteLine(deploymentManifestLocation.ToString() + "Added to inclusion list");
}

Self updating .net CF application

I need to make my CF app self-updating through the web service.
I found one article on MSDN from 2003 that explains it quite well. However, I would like to talk practice here. Anyone really done it before or does everyone rely on third party solutions?
I have been specifically asked to do it this way, so if you know of any tips/caveats, any info is appreciated.
Thanks!
This is relatively easy to do. Basically, your application calls a web service to compare its version with the version available on the server. If the server version is newer, your application downloads the new EXE as a byte[] array.
Next, because you can't delete or overwrite a running EXE file, your application renames its original EXE file to something like "MyApplication.old" (the OS allows this, fortunately). Your app then saves the downloaded byte[] array in the same folder as the original EXE file, and with the same original name (e.g. "MyApplication.exe"). You then display a message to the user (e.g. "new version detected, please restart") and close.
When the user restarts the app, it will be the new version they're starting. The new version deletes the old file ("MyApplication.old") and the update is complete.
Having an application update itself without requiring the user to restart is a huge pain in the butt (you have to kick off a separate process to do the updating, which means a separate updater application that cannot itself be auto-updated) and I've never been able to make it work 100% reliably. I've never had a customer complain about the required restart.
I asked this same question a while back:
How to Auto-Update Windows Mobile application
Basically you need two applications.
App1: Launches the actual application, but also checks for a CAB file (installer). If the cab file is there, it executes the CAB file.
App2: Actual application. It will call a web service, passing a version number to the service and retrieve a URL back if a new version exists (). Once downloaded, you can optionally install the cab file and shut down.
One potiencial issue: if you have files that one install puts on the file system, but can't overwrite (database file, log, etc), you will need two separate installs.
To install a cab: look up wceload.exe http://msdn.microsoft.com/en-us/library/bb158700.aspx
private static bool LaunchInstaller(string cabFile)
{
// Info on WceLoad.exe
//http://msdn.microsoft.com/en-us/library/bb158700.aspx
const string installerExe = "\\windows\\wceload.exe";
const string processOptions = "";
try
{
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = installerExe;
processInfo.Arguments = processOptions + " \"" + cabFile + "\"";
var process = Process.Start(processInfo);
if (process != null)
{
process.WaitForExit();
}
return InstallationSuccessCheck(cabFile);
}
catch (Exception e)
{
MessageBox.Show("Sorry, for some reason this installation failed.\n" + e.Message);
Console.WriteLine(e);
throw;
}
}
private static bool InstallationSuccessCheck(string cabFile)
{
if (File.Exists(cabFile))
{
MessageBox.Show("Something in the install went wrong. Please contact support.");
return false;
}
return true;
}
To get the version number: Assembly.GetExecutingAssembly().GetName().Version.ToString()
To download a cab:
public void DownloadUpdatedVersion(string updateUrl)
{
var request = WebRequest.Create(updateUrl);
request.Credentials = CredentialCache.DefaultCredentials;
var response = request.GetResponse();
try
{
var dataStream = response.GetResponseStream();
string fileName = GetFileName();
var fileStream = new FileStream(fileName, FileMode.CreateNew);
ReadWriteStream(dataStream, fileStream);
}
finally
{
response.Close();
}
}
What exactly do you mean by "self-updating"? If you're referring to configuration or data, then webservices should work great. If you're talking about automatically downloading and installing a new version of itself, that's a different story.
Found this downloadable sample from Microsoft- looks like it should help.
If you want to use a third-party component, have a look at AppToDate developed by the guys at MoDaCo.