Icon of VSTO Add-In in Windows Setting - c#

I use the publish feature in Visual Studio to create a setup.exe for a VSTO Word Add-In.
In the Visual Studio application settings, an icon (Icon and manifest) is assigned to the project.
Unfortunately, this icon is not displayed in the Windows Apps and Features Settings. There appears only a default icon.
How can I change the Icon used in the Windows Apps and Features Settings?

An additional step for adding a windows registry key is required for ClickOnce installers. The DisplayIcon key should be added after installation, for example:
using System.Deployment.Application;
using Microsoft.Win32;
//Call this method as soon as possible
private static void SetAddRemoveProgramsIcon()
{
//Only execute on a first run after first install or after update
if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "example.ico");
if (!File.Exists(iconSourcePath))
{
MessageBox.Show("We could not find the application icon. Please notify your software vendor of this error.");
return;
}
RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Uninstall");
string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
for (int i = 0; i < mySubKeyNames.Length; i++)
{
RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
object myValue = myKey.GetValue("DisplayName");
Console.WriteLine(myValue.ToString());
// Set this to the display name of the application. If you are not sure, browse to the registry directory and check.
if (myValue != null && myValue.ToString() == "Example Application")
{
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
}
catch(Exception mye)
{
MessageBox.Show("We could not properly setup the application icons. Please notify your software vendor of this error.\r\n" + mye.ToString());
}
}
}
You may find the 'Add or Remove Programs' icon for a C# ClickOnce application page helpful.

Related

How to find and list all UWP apps / packages?

My goal is to find and launch a UWP app by name (e.g. Twitter). I'm currently using an elevated desktop extension, following a guide by Stefan Wick.
In my full-trust Win32 console process, I'm currently using the PackageManager to find and list all the UWP apps, and it works on my machine. However, when I send my finalized app package to another user, nothing appears on his screen, even after running elevated.
Here's my current code:
var PkgMgr = new PackageManager();
var currUserPkgs = PkgMgr.FindPackagesForUser(string.Empty);
foreach (Package pkg in currUserPkgs)
{
string pkgName = pkg.DisplayName;
if (pkgName == "")
{
continue;
}
if (pkgName.Contains(appName) || appName.Contains(pkgName) ||
percentSimilarity(appName, pkgName) >= 0.50)
{
// we found it
appPkgName = pkg.Id.FamilyName;
break;
}
}
Why does this not bring up any packages on another user's machine? There's no error message that's called.
Also, is there another solution that can locate all UWP packages? Thank you!

Webbrowser control ignores FEATURE_BROWSER_EMULATION reg entry

Im developing a custom browser solution with .net's Webbrowser control.
To disable the IE-Compatibilty View, I set the registry entry
Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION:
[Sreenshot regedit] http://zbirk.mirk.at/browserreg.png "Screenshot"
i tried to use the values: dword=8000,dword=8888,dword=9000, but the webbrowser control seems to ignore these reg entries.
Maybe someone had this problems too and may help me.
The WebBrowser control definately DOES respect these keys.
Remember that while taskman may show application.exe in the name column, if you are debugging the exe name is application.vshost.exe
So in my application sI just attempt to create the key every time the app runs. If it fails to create it (because it already exists) then I continue running, if it creates the key then I inform the user that they need to restart the application.
ensure that you are not running within vshost
the app name would be different ie appname.vshost.exe
Thx for your reply, now its working.
Her is my working peace of code:
public void setIEcomp()
{
String appname = Process.GetCurrentProcess().ProcessName+".exe";
RegistryKey RK8 = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION",RegistryKeyPermissionCheck.ReadWriteSubTree);
int value9 = 9999;
int value8 = 8888;
Version ver = webBrowser1.Version;
int value = value9;
try
{
string[] parts = ver.ToString().Split('.');
int vn = 0;
int.TryParse(parts[0], out vn);
if (vn != 0)
{
if (vn == 9)
value = value9;
else
value = value8;
}
}
catch
{
value = value9;
}
//Setting the key in LocalMachine
if (RK8 != null)
{
try
{
RK8.SetValue(appname, value, RegistryValueKind.DWord);
RK8.Close();
}
catch(Exception ex)
{
//MessageBox.Show(ex.Message);
}
}
}
I too could not see that FEATURE_BROWSER_EMULATION made any difference in my application.
I was testing the FEATURE_BROWSER_EMULATION functionality by manually editing the registry with regedit. Nothing I did made any difference. My hosted page was still failing on any new-ish JavaScript and could not load external libraries.
I found my mistake:
I was editing the 64-bit view of the registry with regedit. My app was running as a 32-bit app and looking at the 32-bit view of the registry. That's why my changes to the registry seemed to have no impact on my application. By the way, the WPF project template defaults to "Prefer 32-bit."
Manually editing with regedit within the Wow6432Node key worked:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION
Of course, setting the DWORD value programmatically within your application will also work, since your 32-bit application will edit within the Wow6432Node.
An older post and solution is no longer accurate.
Running procmon and watching for FEATURE_BROWSER_EMULATION shows the following registry variables actually checked. This was for WINWORD.exe but other than that - take your pick...
HKU\S-1-5-21-[my-sid-paws-off]\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WINWORD.EXE
HKU\S-1-5-21-[my-sid-paws-off]\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION*
HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION(Default)
HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WINWORD.EXE
HKLM\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\WINWORD.EXE
HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION*
HKLM\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION*

Visual Studio Setup Project and placing application in startup path

I've created a function that executes in the beginning of an installation to create a registry key in the SOFTWARE\Microsoft\Windows\CurrentVersion\Run path, so the app can start when the computer starts.
The function works in a XP / 2003 machine but not on Windows 7. The install application Elevates the privileges during installation automatically because it is installing a windows service program. So I'm wondering what am I doing wrong again?
Here is the function:
private void RegisterInStartup(bool isChecked)
{
try
{
string t_registeryPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
RegistryKey registryKey =
Registry.LocalMachine.OpenSubKey(t_registeryPath, true);
if (registryKey == null)
registryKey = Registry.LocalMachine.CreateSubKey(t_registeryPath);
if (isChecked)
{
string tgt_dir = Context.Parameters["targetPath"];
if (!Directory.Exists(tgt_dir))
return;
string t_exeName = Path.Combine(tgt_dir, "AppTaskbarNotificator.exe");
if (!File.Exists(t_exeName))
return;
registryKey.SetValue("AppTaskbar", t_exeName);
}
else
{
registryKey.DeleteValue("AppTaskbar");
}
}
catch (Exception)
{
return;
}
}
and it is placed in the Install function which is overridden in the Installer Class of the App in mind.
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
System.Diagnostics.Debugger.Break();
RegisterInStartup(true);
StartApp();
}
Thanks in advance.
HKEY_LOCAL_MACHINE is a per-machine location, so your custom action needs Administrator privileges to write in it. You can give it these privileges by making it deferred with no impersonation.
Visual Studio 2010 makes custom actions deferred with no impersonation by default, but older versions don't. So you may have to edit the MSI with Orca to set the appropriate flags.
Another solution is to write your registry entry in HKEY_CURRENT_USER.

Automatic update a Windows application

How do I develop my Windows application so it will auto update on the client machine, like Firefox, Skype, etc.?
Is there any simple approach or any open source library which help me to do it just following some steps or a few lines of code?
ClickOnce is what you're searching for.
You might also find these SO questions interesting (which offers some different solutions):
Auto update for WinForms application
How do I implement an auto update strategy for my in-house winform app
try microsoft clickonce technology
(in MSDN)
You can use wyUpdate or .NET Application Updater Component
There is also the Update Block in the Ent Lib by msft.
The most popular frameworks are:
Google Omaha - This is what Chrome uses. Very powerful.
Squirrel - This is used in Electron applications. Easy to use but can't update machine-wide installations. Also, no graphical update notifications.
WinSparkle - Gives you graphical update notifications. But less mature than Squirrel.
AutoUpdater.NET - Both graphical and silent updates. Similar to Squirrel and WinSparkle.
I've taken these links from this article. It goes into more details about the pros and cons of each of the frameworks.
Use MD5-Update it easy only need add 5 lines at your application, no configuration need in your app only add library and publish the files.
1. Your need a web server with PHP for publish your files please include updt.exe.
2. Add index.php for make list of update files. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.
<?php
$_dat = array();
$_dir=new RecursiveDirectoryIterator(".");
foreach (new RecursiveIteratorIterator($_dir) as $_itm) {
$_fil = str_replace(".".DIRECTORY_SEPARATOR, "", $_itm);
if(!is_dir($_fil) && $_fil != "index.php"){
$_dat[]=array('StrFil' => "$_fil", 'StrMd5' => strtoupper(md5_file($_fil)), 'lonSiz' => filesize($_fil));
}
}
echo json_encode($_dat, JSON_UNESCAPED_UNICODE);
?>
3. Add nuget repository at your proyect
PM> Install-Package MD5.Update
4. Call the library when your app stars, with your update folder url, update all files and download your new app on updt folder, for replace your app need updt.exe
string strUrl = "http://yourdomain.com/app/";
if (MD5Update.MD5Update.Check(strUrl, true))
{
Process.Start(AppDomain.CurrentDomain.BaseDirectory + #"updt.exe", AppDomain.CurrentDomain.FriendlyName + " " + Process.GetCurrentProcess().ProcessName);
Application.Exit();
}
5. updt.exe for replace the current app with the new app updt folder to app. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
List<string> lisArg = Environment.GetCommandLineArgs().ToList();
if (lisArg.Count < 2)
{
MessageBox.Show("Please provide App Excutable Name and Procees name");
Application.Exit();
return;
}
string strAppName = lisArg[1];
string strAppProcees = lisArg[2];
Process[] lisPro = Process.GetProcessesByName(strAppProcees);
foreach (Process Pro in lisPro)
{
if (Pro.Id != Process.GetCurrentProcess().Id)
{
Pro.Kill();
Thread.Sleep(1000);
}
}
string strAppMain = AppDomain.CurrentDomain.BaseDirectory + strAppName;
string strAppUpdate = AppDomain.CurrentDomain.BaseDirectory + #"updt\" + strAppName;
if (!File.Exists(strAppMain))
{
MessageBox.Show("App Excutable dosent exists");
Application.Exit();
return;
}
if (!File.Exists(strAppUpdate))
{
MessageBox.Show("App Excutable Updated dosent exists");
Application.Exit();
return;
}
File.Copy(strAppUpdate, strAppMain, true);
long fileSize = 0;
FileInfo currentFile = new FileInfo(strAppMain);
while (fileSize < currentFile.Length)
{
fileSize = currentFile.Length;
Thread.Sleep(1000);
currentFile.Refresh();
}
Process.Start(strAppMain);
}
catch (Exception Ex)
{
MessageBox.Show("An error ocurred");
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + #"updt_" + DateTime.Now.ToString("yyyyMMddTHHmmss") + " .txt", Ex.ToString());
Application.Exit();
}
How about System Center 2012 Configuration Manager?
I'd add another possible variation:
https://github.com/synhershko/NAppUpdate
https://github.com/cecon/autoupdatereasy
https://github.com/NetSparkleUpdater/NetSparkle
While ClickOnce is simple and it resurrected for .NET 5, it still has a lot of limitations, so I found out that nowadays better option exists: you could use included in Windows 10 mechanism for app delivery called AppInstaller by packaging your app in MSIX bundle or package.
I covered my findings related to the topic in this answer

How can I check that PowerPoint or point viewer is installed on the machine?

I need to play PowerPoint slides but first I want to check whether PowerPoint or viewer is installed on the machine or not. How can I do that using .NET?
It depends on whether you are trying to tell whether you can view a presentation (*.ppt, *.pptx, etc) or whether you can access the PowerPoint object model.
To check whether there is an associated handler for ppt files, you can do the following:
// using Microsoft.Win32;
private bool CheckPowerPointAssociation() {
var key = Registry.ClassesRoot.OpenSubKey(".ppt", false);
if (key != null) {
key.Close();
return true;
}
else {
return false;
}
}
if (CheckPowerPointAssociation()) {
Process.Start(pathToPPT);
}
To check whether the PowerPoint COM object model is available, you can check the following registry key.
// using Microsoft.Win32;
private bool CheckPowerPointAutomation() {
var key = Registry.ClassesRoot.OpenSubKey("PowerPoint.Application", false);
if (key != null) {
key.Close();
return true;
}
else {
return false;
}
}
if (CheckPowerPointAutomation()) {
var powerPointApp = new Microsoft.Office.Interop.PowerPoint.Application();
....
}
Note, however, that in both cases it will only give you a pretty good indication of the availability of PowerPoint. For example, an uninstallation may not have fully removed all traces. Also in my experience selling an Outlook addin for years I've seen certain antivirus programs that interfere with the COM object model in a screwup effort to protect against malicious scripts. So in any case, have robust error handling as well.
Hope this helps!
HKEY_CLASSES_ROOT\MSPowerPoint\protocol\StdFileEditing\server
This key is the same for all installs of PowerPoint and points to the install dir for the executable to run PowerPoint. Great to use when detecting if this product is installed and good for figuring out which folder Office products are installed in, when the install is not using the defaults.
I am not sure this is the right way to do this. But you can use this
try
{
//It will throw a WIN32 Exception if there is no associated
//application available to open the file.
Process p = Process.Start("C:\\Sample.pptx");
}
catch (Win32Exception ex)
{
MessageBox.Show("Powerpoint or Powerpoint viewer not installed\n");
}
What about checking if the EXE file for PowerPoint or PowerPoint viewer exists or not by using "Exists Method" from system.io namespace?
Check this.

Categories

Resources