Walkthrough – Automatic Update Process for Outlook Add-in Solutions

Introduction
This article answers the question often asked about Outlook Add-In plug-in: Once an Outlook Add-In solution is deployed on the client computer, how can any future revisions to the solution automatically be made available to the client computer seamlessly? This article attempts to provide end-to-end steps on how the Update Process for Outlook Add-Ins Solutions needs to be handled once the application is deployed on the end-user machine.

Scenario
Normally an application is deployed on the client computer in two ways: One is using the “setup” (using either Microsoft’s or third party setup projects) or using the “publish” or more popularly known as “Click-once”.

As you can see, there are definite reasons why you need to choose one over the other. Click-once is appealing as this method can be used to publish the application and the updates can be made automatically at the end user. But using this method, an application that requires registry entries cannot be deployed. The traditional method can be used to make registry entries but the automatic updates are difficult unless the auto-updater component is custom developed.

The method explained here uses a combination of both the methods to achieve registry updates during the installation and also to push the updates seamlessly to the end user.

Prerequisites
Before we begin, Visual Studio 2005 Tools for Office (VSTO) needs to be installed to create custom add-ins for Outlook in Visual Studio 2005. This article does not address the pre-requisites to develop the Outlook Add-In.

Using the code
Step 1: Create a simple Outlook Add-In project using VS2005.
In Microsoft Visual Studio .NET 2005, open the New Project dialog box, open Visual C#, select Office and click Outlook Add-in.

  • Rename the project as TestOutlookAddin and click OK. As you would expect, Visual Studio creates a project called TestOutlookAddin and it also
    automatically creates a setup project (TestOutlookAddinSetup). This setup project helps in installing the add-in on the client’s computer.
  • Under Outlook folder in Solution Explorer, open ThisApplication.cs and add logic to create a Top Menu Item under ThisApplication_Startup event procedure. Refer to the attached sample application for details.
  •  // Get the Outlook menu bar.
        _menuBar = this.ActiveExplorer().CommandBars.ActiveMenuBar;

     // Get the index of the Help menu on the Outlook menu bar.
       _helpMenuIndex = _menuBar.Controls[_MENU_BEFORE].Index;

     // Add the top-level menu right before the Help menu.
       _topMenu =
         (Office.CommandBarPopup)_menuBar.Controls.Add(
                   Office.MsoControlType.msoontrolPopup,
                   Type.Missing,
                   Type.Missing,
                   _helpMenuIndex,
                   true);

    // Set the Caption from App.Config
       _topMenu.Caption =
         System.Configuration.ConfigurationManager.AppSettings
                           ["TopMenuCaption"];

    // Make the new Menu Item visible
      _topMenu.Visible = true;
  • Add an application configuration file to the Outlook-Addin project TestOutlookAddin. In this article, we would drive the caption name and position for the new Menu item from the App.Config file.
  • key="MenuBeforeLocation" value="Help" />
    key="TopMenuCaption" value="Demo" />
  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Add Reference on the shortcut menu. Select System.Configuration under the .NET tab and click OK.
  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Rebuild on the shortcut menu to rebuild the project.
  • Step 2: Publish the Outlook Add-in project Solution files – TestOutlookAddin
    Use the Publish Wizard under Properties to deploy the solution files to a location on a Server that would enable automatic updates to the application on the client computer. This follows the manifest approach that gives more flexibility in maintaining and updating the application without touching the registry again.

  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Properties on the shortcut menu.
  • Select Publish on the left pane. Make sure the Checkbox ‘Automatically increments revision with each release’ is checked.
  • Use either of the two methods to Publish the solution. This would copy the revised assemblies, application manifest and configuration manifest to the published location.
  • Method 1

  • After selecting Publish on the left Pane as illustrated above, choose Publishing Location (Web site or file path) that would allow automatic updates to the application on the client computer.
  • You may choose either File System, Local IIS or Remote Site . If you choose Remote Site option, the FrontPage Server Extensions need to be enabled on the Server.
  • Click on the Publish Now button.
  • Method 2 – Using the Publish Wizard

  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Publish on the shortcut menu.
  • Specify the centralized location to publish this application. Click on the Browse button to choose either File System, Local IIS or Remote Site . If you choose Remote Site option, the FrontPage Server Extensions need to be enabled on the Server.
  • Click on Next button. Click on Finish to publish your application.
  • You may have noticed that when the Add-in project TestOutlookAddin was created in VS2005, the automatically created setup project TestOutlookAddinSetup contains the Primary output from TestOutlookAddin. Thus the necessary published information like location and version number are available when you rebuild TestOutlookAddinSetup and subsequently in the Windows Installer (.msi) file that will be distributed to your Clients.

    Step 3: Add Prerequisites to the Setup Project – TestOutlookAddinSetup
    Once your Outlook Add-In application is published onto a centralized location, it is time to build the Setup project and distribute it to your Clients as a Windows Installer (.MSI) file. You will now modify the Setup project to check for basic prerequisites.

  • In Solution Explorer, right-click the TestOutlookAddinSetup project node and click on Properties on the shortcut menu.
  • Click on the prerequisites button and make sure the Create setup program to install prerequisite components is checked.
  • Check the .NET Framework 2.0 prerequisite from the list.
  • Specify the install location for prerequisites accordingly. In the sample application, the ‘Download prerequisites from the same location as my application’ is checked.
  • Click OK twice to exit the Properties Page.
  • Step 4: Add Launch Conditions to the Windows Installer (.msi) file

    In this article, we check only two basic prerequisites namely, Visual Studio 2005 Tools for Office Runtime and the Office primary interop assemblies.

  • In Solution Explorer, right-click the TestOutlookAddinSetup project node, point to View on the shortcut menu and click Launch Conditions.
  • To add a launch condition for the Visual Studio 2005 Tools for Office Runtime

  • In the Launch Conditions editor, right-click Requirements on Target Machine, and then click Add Windows Installer Launch Condition.
  • Select the newly added search condition, Search for Component1 and rename to VSTO Runtime.
  • Right click on the above search condition and select the Properties Window. In the Properties window, type {D2AC2FF1-6F93-40D1-8C0F-0E135956A2DA} into the ComponentId property and change the value of Property to CHECK_VSTO_RUNTIME.
  • Select the newly added launch condition, (Condition1) and rename it to Display VSTO Runtime Message.
  • In the Properties window, change the value of the Condition property to CHECK_VSTO_RUNTIME and leave the InstallURL property blank.
  • Change the value of the Message property to ‘The Visual Studio 2005 Tools for Office Runtime is not installed on this Computer’.
  • To add a launch condition for the Outlook 2003 Primary Interop Assembly

  • In the Launch Conditions editor, right-click Requirements on Target Machine, and then click Add Windows Installer Launch Condition.
  • Select the newly added search condition, Search for Component1 and rename the search condition to Outlook 2003 Primary Interop Assemblies.
  • Right click on the above search condition and select Properties Window. In the Properties window, type {14D3E42A-A318-4D77-9895-A7EE585EFC3B} into the ComponentId property and change the value of Property to CHECK_OUTLOOK2003_PIA.
  • Select the newly added launch condition, (Condition1) and rename it to Display PIA message.
  • In the Properties window, change the value of the Condition property to CHECK_OUTLOOK2003_PIA and leave the InstallURL property blank.
  • Change the value of the Message property to ‘The Office 2003 Primary Interop Assemblies have not been installed on this Computer’.
  • Step 5: Installing the Add-in Solution

  • In Solution Explorer, right-click the TestOutlookAddinSetup project node and click on Rebuild on the shortcut menu to rebuild your solution. This would create the Windows Installer file TestOutlookAddinSetup.msi.
  • To install the solution on your development machine using VS2005, in Solution Explorer, right-click the TestOutlookAddinSetup project node and click Install on the shortcut menu.
  • To install the solution on the Client computer, distribute the Windows Installer file TestOutlookAddinSetup.msi to your client and install the same.
  • The installation creates the necessary registry entry for the application Add-In on the Client Computer when all prerequisites are met.
  • Note: It is important to note that the Add-In project TestOutlookAddin was published to some location prior to the installation of the Add-In solution on the client computer.
  • Step 6: Look for the impact of the Add-in in Outlook
    The attached sample application adds a new menu item to Outlook just before the HELP menu. If the installation was successful, the next time Outlook is opened, you should see the new Menu item Demo on the top.

    Step 7: Test the automatic Update Process
    Now that your application has been deployed on your client computer, changes that you make to your solution on the development server should be automatically made available on the Client computer. VSTO uses a concept similar to the ClickOnce to achieve this. In the attached sample application we shall change the caption of the Menu item in the app.config.

  • In the attached sample application TestOutlookAddin, change the Value of the field TopMenuCaption in App.config to DemoRevision.
  • In Solution Explorer, right-click the TestOutlookAddin project node and click on Publish on the shortcut menu.
  • Important: Do not change the location of the Publish at this stage. The local application manifest file on the Client computer contains the published Location and version information that would enable the automatic updating process. If the location needs to be changed for some reason, you will have to distribute the Windows Installer file to your clients for re-installation.

    Step 8: Looking for the desired changes in Outlook
    Close and re-open the Outlook application on the client computer to see the impact of the new changes to the Add-In application. The new Menu item on the top would have the revised text DemoRevision instead of Demo.

    Note: You did not rebuild or re-install your setup application TestOutlookAddinSetup this time.

    The following events take place when Outlook is re-opened:

  • The VSTO Runtime uses the information in the application manifest on the client computer to locate the deployment manifest.
  • The version of the deployment manifest is checked against the version of the application manifest on the client computer. If the version of the deployment manifest on the server is newer than the application manifest on the client computer, the new assemblies and the new application manifest are downloaded automatically.
  • The local copy of the application manifest is overwritten with the latest version.
  • When the user starts Outlook the next time, the new assemblies are executed on the client computer and the changes are reflected in the Outlook application.
  • Summary
    This article demonstrates that once the Outlook Add-In project is deployed on the client computer using the Microsoft Installer (.msi) file created in the setup project of VS2005, further updates to the application can be automatically made available on the Client Computer by using the Publish option of the Add-In project in VS2005. As long as the path to the local application manifest is the same, no further changes in the registry entries are needed for this Add-in. The Publish option will accommodate all updates from here.

    VBA调用javascript(一)

    函数接口

    Function execJSFunc(filePath, funcName)
        Dim code
        Open filePath For Input As #1
        Do While Not EOF(1)
            Line Input #1, tmpCode
            code = code & tmpCode & Chr(13)
        Loop
        Close #1
     
        Set JS = CreateObject("ScriptControl")
        JS.Language = "JScript"
        JS.AddCode code
        Dim result
        result = JS.run(funcName, ThisWorkbook)
        execJSFunc = result
    End Function

    调用封装

    Sub run(funcName)
        Dim path, fileName, pos, result
        path = ThisWorkbook.path
        pos = InStr(4, ThisWorkbook.Name, ".", 1)
        pos = Len(ThisWorkbook.Name) - 4
        fileName = Mid(ThisWorkbook.Name, 1, pos - 1)
        path = path + "" + fileName + ".js"
        result = execJSFunc(path, funcName)
        Debug.Print result
    End Sub

    调用示例

    Sub 按钮1_Click()
        run("hello")
    End Sub

    test.js源码

    function hello(workbook) {
        var sheets = workbook.sheets;
        sheets("Sheet1").range("a3").value = 55555;
        return workbook.sheets.count;
    }

    在x64 OFFICE中使用ScriptControl控件的方法

    Sub Test()  
        Dim oSC As Object  
        Set oSC = CreateObjectx86("MSScriptControl.ScriptControl") ' create ActiveX via x86 mshta host  
        Debug.Print TypeName(oSC) ' ScriptControl  
        With oSC  
            '操作oSC  
        End With  
        CreateObjectx86 , True ' close mshta host window at the end  
    End Sub
    Function CreateObjectx86(Optional sProgID, Optional bClose = False)  
        Static oWnd As Object  
        Dim bRunning As Boolean  
        #If Win64 Then  
            bRunning = InStr(TypeName(oWnd), "HTMLWindow") > 0  
            If bClose Then  
                If bRunning Then oWnd.Close  
                Exit Function  
            End If  
            If Not bRunning Then  
                Set oWnd = CreateWindow()  
                oWnd.execScript "Function CreateObjectx86(sProgID): Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"  
            End If  
            Set CreateObjectx86 = oWnd.CreateObjectx86(sProgID)  
        #Else  
            Set CreateObjectx86 = CreateObject("MSScriptControl.ScriptControl")  
        #End If  
    End Function
    Function CreateWindow()  
        Dim sSignature, oShellWnd, oProc  
        On Error Resume Next  
        sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)  
        CreateObject("WScript.Shell").Run "%systemroot%\syswow64\mshta.exe about:""about:<head><script>moveTo(-32000,-32000);document.title='x86Host'</script><hta:application showintaskbar=no /><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""", 0, False  
        Do  
            For Each oShellWnd In CreateObject("Shell.Application").Windows  
                Set CreateWindow = oShellWnd.GetProperty(sSignature)  
                If Err.Number = 0 Then Exit Function  
                Err.Clear  
            Next  
        Loop  
    End Function

    pip 源切换至国内镜像

    使用 pip 安装软件时,使用国内镜像可以大大提高下载速度

    常用国内镜像
    https://pypi.tuna.tsinghua.edu.cn/simple/ # 清华大学
    https://mirrors.aliyun.com/pypi/simple/ # 阿里云
    https://pypi.douban.com/simple/ # 豆瓣
    https://pypi.mirrors.ustc.edu.cn/simple/ # 中国科学技术大学
    https://pypi.hustunique.com/ # 华中科技大学
    永久使用
    在用户的根目录下创建 .pip 文件夹,新建 pip.conf 文件
    示例:

    cd ~
    mkdir .pip
    cd .pip
    vim pip.conf

    在文件中写入要使用的镜像
    示例:
    使用清华镜像

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    [install]
    trusted-host = https://pypi.tuna.tsinghua.edu.cn

    新方法

    pip install pip -U
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

    Ubuntu下更新NVIDIA显卡驱动导致的重启无法进入操作系统

    在外网上搜索一番后,终于找到了症结所在:Ubuntu内核bug导致gdm3和nvidia驱动冲突,使得gdm3无法正常启动图形界面,而gdm不断尝试启动的后果就是屏幕的闪烁。

    解决方法

    sudo apt purge gdm gdm3 # 卸载gdm和gdm3
    sudo apt install gdm3 ubuntu-desktop    # 重新安装gdm3
    systemctl restart gdm       # 重新启动gdm3服务

    如果还是进不了。
    看到登录界面,在右下角选Ubuntu wayload.

    在Linux系统中使用Flatpak命令安装Scratch的方法

    如果你的Linux操作系统支持Flatpak命令安装软件,那么可以使用Flatpak命令来安装Scratch,以下是具体方法。
    使用Flatpak命令来安装Scratch

    1、如果你的系统还没有安装Flatpack包管理器,请运行以下命令(以Ubuntu 20.04系统为例):

    sudo apt-get update

    sudo apt install flatpak
    2、从Flatpak的Flathub仓库安装,运行以下命令:

    flatpak remote-add –if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

    flatpak install flathub edu.mit.Scratch

    注:当前安装的版本为3.6.0。

    3、安装完成后可运行以下命令运行:

    flatpak run edu.mit.Scratch

    注:可运行flatpak info edu.mit.Scratch命令查看相关的信息,返回如下信息即表示安装成功了:

    Scratch – Create stories, games, and animations, share with others around the

    world

    ID: edu.mit.Scratch

    Ref: app/edu.mit.Scratch/x86_64/stable

    Arch: x86_64

    Branch: stable

    Version: 3.6.0

    License: BSD-3-Clause

    Origin: flathub

    Collection: org.flathub.Stable

    Installation: system

    Installed: 513.0 MB

    Runtime: org.freedesktop.Platform/x86_64/19.08

    Sdk: org.freedesktop.Sdk/x86_64/19.08

    Commit: be95cc888f17693303a1b56392c90b1915965c828b160023cb66c2bfffb75e53
    Parent: 123e220a8e8392828b36807fec7ae55de9497d64054bf74e4847f464b4ce1123
    Subject: Add –device=all for webcam access (64e7093d)
    Date: 2020-06-15 05:11:25 +0000

    Ubuntu中安装NVIDIA显卡驱动

    a. ubuntu 18.04默认安装了第三方开源的驱动程序nouveau,安装nvidia显卡驱动首先需要禁用nouveau,不然会碰到冲突的问题,导致无法安装nvidia显卡驱动。

    编辑文件blacklist.conf

    sudo vim /etc/modprobe.d/blacklist.conf

    安装或使用vi

    在文件最后部分插入以下两行内容

    blacklist nouveau
     
    options nouveau modeset=0

    更新系统

    sudo update-initramfs -u

    没有信息显示,说明nouveau已被禁用,接下来可以安装nvidia的显卡驱动。

    2. 在英伟达的官网上查找你自己电脑的显卡型号然后下载相应的驱动。
    3. 在ubuntu下按ctrl+alt+f6进入命令行界面,(进入命令行的方式可能有所不同,)

    然后在命令行界面下输入:

    sudo service lightdm stop      //这个是关闭图形界面,不执行会出错。(执行该语句时提示no lightdm service loaded ,跳过即可)

    然后卸载掉原有驱动:

    sudo apt-get remove nvidia-*  (若安装过其他版本或其他方式安装过驱动执行此项)

    4.

    给驱动run文件赋予执行权限:

    sudo chmod  a+x NVIDIA-Linux-x86_64-版本号.run

    安装:

    sudo ./NVIDIA-Linux-x86_64-410.78.run -no-x-check -no-nouveau-check -no-opengl-files //只有禁用opengl这样安装才不会出现循环登陆的问题

    no-x-check:安装驱动时关闭X服务

    -no-nouveau-check:安装驱动时禁用nouveau

    -no-opengl-files:只安装驱动文件,不安装OpenGL文件
    出现找不到cc文件的问题,要执行下面的语句,否则安装完成,建立软连接也无法找到cc文件

    sudo apt-get install gcc
    sudo apt-get install g++
    sudo apt-get install make

    The distribution-provided pre-install script failed! Are you sure you want to continue? 选择 yes 继续。
    Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later? 选择 No 继续。
    问题没记住,选项是:install without signing
    问题大概是:Nvidia’s 32-bit compatibility libraries? 选择 No 继续。
    Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up. 选择 Yes 继续

    这些选项如果选择错误可能会导致安装失败,没关系,只要前面不出错,多尝试几次就好。

    挂载Nvidia驱动:

    modprobe nvidia

    检查驱动是否安装成功:

    nvidia-smi

    How to Install the PHP mcrypt Extension

    In the examples shown, replace “X.Y” with your app’s PHP version (for example, “7.2”).
    The mcrypt extension is an interface to the mcrypt cryptography library. This extension is useful for allowing PHP code using mcrypt to run on PHP 7.2+.

    The mcrypt extension is included in PHP 5.4 through PHP 7.1. It was removed from PHP 7.2 and moved to an unofficial PECL extension because the mcrypt library is no longer maintained.

    For PHP 7.2+, PHP instead uses libsodium as a cryptography library. ServerPilot builds PHP 7.2+ with the official libsodium extension. New PHP code should be written to use libsodium rather than mcrypt.

    Installing mcrypt on PHP 5, PHP 7.0, and PHP 7.1
    You do not need to install the mcrypt extension on PHP 5, 7.0, or 7.1. ServerPilot builds these PHP versions with the mcrypt extension so it is always available.

    Installing mcrypt on PHP 7.2, 7.3, or 7.4
    To install this extension on PHP 7.2 through 7.4, run the following commands as your server’s root user:

    sudo apt-get -y install gcc make autoconf libc-dev pkg-config
    sudo apt-get -y install libmcrypt-dev
    sudo pecl7.2-sp install --nodeps mcrypt-snapshot

    When you are shown the prompt

    libmcrypt prefix? [autodetect] :

    Press Enter to autodetect.

    Once installed, create a configuration file for the extension and restart PHP by running the following commands as root:

    sudo bash -c "echo extension=mcrypt.so > /etc/php7.2-sp/conf.d/mcrypt.ini"
    sudo service php7.2-fpm-sp restart

    Verifying mcrypt Is Installed
    You can check that the extension was installed with this command:

    php7.2-sp -i | grep mcrypt

    The output will look like this:

    $ php7.2-sp -i | grep mcrypt
    /etc/php7.2-sp/conf.d/mcrypt.ini,
    Registered Stream Filters => zlib.*, convert.iconv.*, bzip2.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
    mcrypt
    mcrypt support => enabled
    mcrypt_filter support => enabled
    mcrypt.algorithms_dir => no value => no value
    mcrypt.modes_dir => no value => no value

    Uninstalling the Mcrypt Extension
    To uninstall this extension, as root run the commands:

    sudo rm /etc/phpX.Y-sp/conf.d/mcrypt.ini
    sudo peclX.Y-sp uninstall mcrypt

    Next, restart PHP-FPM with the command:

    sudo service phpX.Y-fpm-sp restart

    内网穿透FRP在windows系统里开机自启的几个方法

    方法一:
    创建一个快捷方式到 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 里面
    这个方法最大缺点是电脑要登录后才能连接,所以一般不用这个方法

    方法二:
    用计划任务实现,方法看这里 http://diannaobos.com/post/405.html
    不过我用这个方法启用多个frp会有奇怪的问题,所以我不用这个方法

    方法三:
    用winsw将frp注册为系统服务
    这个方法最稳定,这是我最终用的方法。
    下载winsw https://github.com/kohsuke/winsw/releases ,改名为winsw.exe,放到frp相同的目录里,在同一个目录里创建一个utf8编码的文本文件,文件名是 winsw.xml,内容是:

    <service>
        <id>frp</id>
        <name>frp这里是服务的名称</name>
        <description>这里是服务的介绍,随便写</description>
        <executable>frpc</executable>
        <arguments>-c frpc.ini</arguments>
        <onfailure action="restart" delay="60 sec"/>
        <onfailure action="restart" delay="120 sec"/>
        <logmode>reset</logmode>
    </service>

    以管理员权限打开一个命令窗口,cd到frp所在目录,执行:
    winsw install
    winsw start
    大功告成!

    如果要卸载服务,执行命令:
    winsw stop
    winsw uninstall

    .Net 4在win7上安装失败的解决办法

    解决方法:
      1、在桌面上找到“计算机”,单击右键选择“管理”。
      2、在打开的“计算机管理”窗口中依路径“服务和应用程序——服务”打开,在列表中找到“Windows Update”并单击右键选择“停止”。
      3、按住“Win+R”键打开运行对话框,输入cmd并回车,在打开的界面输入net stop WuAuServ回车(停止windows update服务),如图所示。
      4、按住“Win+R”键打开运行对话框,输入%windir%并回车,在打开的界面找到SoftwareDistribution文件夹并将其重命名为SDold,如图所示。
      5、此时再打开原来的“计算机管理”窗口中依路径“服务和应用程序——服务”打开,在列表中找到“Windows Update”并单击右键选择“启动”,此时再安装Microsoft .NET Framework 4.5\4.0的安装包就能顺利通过了。