How to install BHO without Wix in C# - c#

I followed this link How to get started with developing Internet Explorer extensions? and after following it I got it to install on my own machine by using the Debug mode on Visual Studio. How do I install it on another users machine without them having to start up Visual Studio and run through Debug?

If you have have followed the link posted in the answer (making sure you have the register and unregister methods) then you can create a batch file that people can use to install it on their own machines.
Ex:
"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" /f /i "%~dp0YourDLL.dll"
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" /unregister "%~dp0YourDLL.dll"
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" "%~dp0YourDLL.dll"
"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\gacutil.exe" /f /i "%~dp0YourDLL.dll"
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /unregister "%~dp0YourDLL.dll"
"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" "%~dp0YourDLL.dll"
REG ADD "HKLM\Software\Microsoft\Internet Explorer\Extensions{0A0F07FC-0099-4AAF-8D2F-C6C710EE91CA}" /v "Icon" /t REG_SZ /d "%~dp0Resources\YourIcon.ico" /f
REG ADD "HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Extensions{0A0F07FC-0099-4AAF-8D2F-C6C710EE91CA}" /v "Icon" /t REG_SZ /d "%~dp0Resources\YourIcon.ico" /f
You do not have to include the REG ADD at the end if you don't have an Icon that you want to use but I couldn't find a way to have a dynamic path for the icon in Visual Studio that would work so I decided to register it through the batch file itself. If you want info on registry commands for batch files you can look here: Is it possible to modify a registry entry via a .bat/.cmd script?.
The %~dp0 before the YourDLL in the first part of the code is to get the current path that your batch file is located in. I found that information out through this How do I find the current directory of a batch file, and then use it for the path?

Related

Uninstalling an InstallShield Installscript MSI program using C# silently

This is going to be very specific to InstallShield, so I doubt anyone has dealt with this before, but I wrote a batch file to uninstall prior versions of our product and it doesn't work. (We always uninstall prior versions prior to an install/upgrade since the Upgrades in InstallShield don't seem to work). Uninstalling Installscript MSI projects is very different from typical uninstalls in that you need to "record" an uninstall and store the results in a file i.e.:
setup.exe /x /r /f1"C:\temp\UNINST.ISS"
This stores the uninstall image in c:\temp\UNINST.ISS and then you need to pass that to the uninstaller to get the product to uninstall:
setup.exe /s /f1"UNINST.ISS"
So I did this for all prior versions of our product and then wrote a batch script (with the product code being {7F2A0A82-BB08-4062-85F8-F21BFC3F3708} to do the uninstalls that looks like this:
echo Uninstalling 5.3.0
pause
if exist "C:\Program Files (x86)\InstallShield Installation Information\ {7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe" (
del /q "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe"
copy /y "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe" "C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe"
cls
echo Uninstalling 5.3.0
"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe" /s /f1".\Uninstall response files\5.3.0\UNINST-5.3.0.ISS"
:wait1
timeout /t 3 /NOBREAK > nul
tasklist | find /i "Setup-5.3.0.exe" >nul 2>nul
if not errorlevel 1 goto wait1
)
echo Uninstalling 5.3.1...
The problem is that it doesn't work. If I execute the uninstall from an elevated CMD window it works fine:
"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe" /s /f1".\Uninstall response files\5.3.0\UNINST-5.3.0.ISS"
But when I execute the batch script it just seems to pass right by the uninstall and not do anything. SO I thought I'd try to write a simple C# program to do this but that's not working either:
Console.Clear();
Console.WriteLine("Uninstalling 5.3.0");
if (File.Exists(#"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe"))
{
File.Copy(#"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup.exe", #"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe", true);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"C:\Program Files (x86)\InstallShield Installation Information\{7F2A0A82-BB08-4062-85F8-F21BFC3F3708}\setup-5.3.0.exe";
Directory.SetCurrentDirectory(#"..\..\..\");
startInfo.Arguments = "/s / f1\".\\Uninstall response files\\5.3.0\\UNINST-5.3.0.ISS\"";
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
}
I've tried debugging this and confirmed that the current directory is correct (using Directory.GetCurrentDirectory()), but I get this error:
process.StandardError' threw an exception of type 'System.InvalidOperationException' System.IO.StreamReader {System.InvalidOperationException}
There are some further instructions towards the bottom of this PDF: https://resources.flexera.com/web/pdf/archive/silent_installs.pdf
setup.exe /s /f1"C:\sample\uninstall.iss" /f2"C:\sample\uninstall.log"
Did you try it manually with full paths for both the /f1 and /f2 parameters?
I am actively trying to forget how to write batch files, but I think you can get the folder where the batch file is running from like this:
set here=%~dp0
cd %here%
Could changing the setup.exe file name cause problems? Maybe you can try without changing the name of the setup.exe and see if that completes?
Could passing the command to cmd.exe via the /c parameter be an idea? ("carries out the command specified by the string and then terminates"):
cmd.exe /c "%here%\setup.exe /s /f1"C:\sample\uninstall.iss" /f2"C:\sample\uninstall.log""
Maybe try adding the /SMS switch to ensure that the setup.exe does not exit prematurely before the actual uninstall is complete. As rumor has it this /SMS switch is not needed for late-generation Installshield setup.exe, but it is needed for older versions.
As Gravity pointed out the problem was a space between the / and the f1. It got added somehow during the cut & paste.

Issue with signing with Visual Studio For the Installer

I have a Visual Studio 2015 C# Solution, it has about 8 assemblies and executable and some exes require elevated permission. So I sign my executable and assemblies with a certificate on the post-build of each executable and assembly. Then I sign them on the pre-build of the installer, and then I post-build my MSI.
As a result, the MSI is signed while the install, but the executable that requires elevated permission does not, and it has the same date and time as the MSI (just a second before).
Here is the script that I am using..
"c:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe" sign /f C:\Work\source\Certificate\CodeSign.pfx /p xxxxpasswordxxxx /tr http://tsa.starfieldtech.com /td SHA256 "c:\source\app\bin\Debug\app.exe"
What am I doing wrong?
Update: As per Microsoft signtool removes administrative privileges? I have set the requestedExecutionLevel to requireAdministrator in the app's manifest.
After seeing what VS does with the file, it adds the files to the OBJ folder, so I had to sign the file that was in the obj\debug folder on pre-compile, and it works.
"c:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe" sign /f C:\Work\source\Certificate\CodeSign.pfx /p xxxxpasswordxxxx /tr http://tsa.starfieldtech.com /td SHA256 "c:\source\app\obj\Debug\app.exe"

Web deployment task failed (This access control list is not in canonical form and therefore cannot be modified)

Publishing ASP.NET MVC 4 application to IIS 8 on my machine giving the following error :
This access control list is not in canonical form and therefore cannot be modified.
I am under Windows 10 and using VS 2013 Ultimate.
I installed web deploy 3.5 from web platform installer 5, and I made sure that the services are working
Solution 1
I was able to solve this problem in the following way
Go to IIS
Right click on the website that you are publishing to and select Edit Permissions
Click the Security tab.
Click on Edit button
A Message box will appear which tell that the Permission was not correctly ordered.
Click Reorder on that message box.
Solution 2
Open the Command prompt (CMD) and execute the following two statements
icacls.exe C:\inetpub\wwwroot /verify /T /C /L /Q
icacls.exe C:\inetpub\wwwroot /reset /T /C /L /Q
note : Maybe you will want to open the CMD with Administrator privilege (Maybe I am not sure)
Cheers
You can run the following command to fix it
command prompt
icacls.exe C:\inetpub\wwwroot\<VIRTUAL DIRECTORY> /verify /T /C /L /Q
// If any entries are reported as being not in canonical order then run:
icacls.exe C:\inetpub\wwwroot\<VIRTUAL DIRECTORY> /reset /T /C /L /Q
Source
powershell
$path = C:\inetpub\wwwroot\<VIRTUAL DIRECTORY>
$acl = Get-Acl $path
Set-Acl $path $acl
Source
You can prevent this problem by modifying your Visual Studio package generation parameters: In the PropertyGroup section of your pubxml file, add
<IncludeSetACLProviderOnDestination>False</IncludeSetACLProviderOnDestination>

I want to copy filenames in dynamic folder on right-klick to clipboard but zip

I want to copy filenames on right-clicking the containing folder to clipboard, but if there are zip, iso, rar, or 7z files I need a list of the content from them too.
I tried in batch/cmd but it won't work and now I am testing with C#. But I don't know how to simulate an explorer contextmenue-event to send the parameters to C#-App.
On both ways I start with a regedit entry in:
HKEY_CLASSES_ROOT\Directory\shell\Liste\command\` REG_SZ with attribute C:\liste.bat "%1%"`
liste.bat:
set var=%1\
set listtmp
del c:\ESC\* /q /f
dir c:\ESC\
copy %var% c:\ESC\
cd c:\ESC\
dir /s /b >%listtmp%
if exist c:\ESC\*.zip
(7z l *.zip >>%listtmp%)
if exist c:\ESC\*.7z
(7z l *.7z >>%listtmp%)
echo listtmp|clip
C# offers the benefit of list handling in variables and enums for checking archives, but I don't understand how to use the parameter from a drop-menu to start my C#-app, so the batch is more handy, with C#-exes more people have doubt because adware... paranoid colleague ;)
I think there is a way, without copping the files and without that amount of variables. Oh and sorry when I not mentioned a vary necessary thing, this is my first post.
Next C:\bat\dirToClp.bat file could help with your I want to copy filenames on right-clicking the containing folder to clipboard:
#ECHO OFF >NUL
#SETLOCAL enableextensions
set "listtmp=%tmp%\list.tmp"
pushd "%~1"
dir /S /B /A-D>"%listtmp%"
if exist *.zip 7z l *.zip>>"%listtmp%"
if exist *.7z 7z l *.7z>>"%listtmp%"
type "%listtmp%"|clip
del "%listtmp%"
popd
echo Your clipboard now holds result of:
echo dir %CD%
pause
#ENDLOCAL
#goto :eof
Here echo and pause for when using clip in a batch script you should warn the user that their clipboard is about to be overwritten. Eventually /A-D switch could be removed from dir /S /B /A-D if desired (causes folder names not implicated in list).
Please pay your attention to 7z calls since I can't verify and confirm rightness of.
The value c:\windows\system32\cmd.exe /D /C c:\bat\dirToClp "%1" exported from registry as follows (but could be under HKEY_CLASSES_ROOT\Folder registry key instead of HKEY_CLASSES_ROOT\Directory):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\DirToClipboard]
[HKEY_CLASSES_ROOT\Directory\shell\DirToClipboard\command]
#="c:\\windows\\system32\\cmd.exe /D /C c:\\bat\\dirToClp \"%1\""
;
Here is not pure C:\bat\dirToClp.bat call but via cmd.exe /D /C because, for workaday and security reasons, I use "Open with PSPad" default action for .bat, .cmd, .vbs etc.
Also the batch saved in that C:\bat folder for I avoid placing files to disk root (and to %userprofile% root and to desktop as well) as a matter of general principle.

Could not load file or assembly 'itextsharp, Version=5.5.0.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its dependencies

I have used itextsharp library to generate pdf in my asp.net web application. It was working fine untill today when suddenly my laptop on which the application was running in the debug mode went off. When I switched on my laptop again and tried to run the application I satrted getting this error:
"Could not load file or assembly 'itextsharp, Version=5.5.0.0,
Culture=neutral, PublicKeyToken=8354ae6d2174ddca' or one of its
dependencies. The parameter is incorrect. (Exception from HRESULT:
0x80070057 (E_INVALIDARG))"
What could be the reason and how can I solve this? Please help.
Try removing the reference and add again...!!! Seems like the reference got removed due to improper shutdown.
Try to clean Temporary Files of Asp.Net, sometime I've experimented strage cases of files corruption(I know this should be a comment but It's verbose):
1 - Open notepad and paste the following.
#ECHO OFF
ECHO Per­form­ing IIS Reset
IISRESET
ECHO Delet­ing Cache
Del /F /Q /S %LOCALAPPDATA%\Microsoft\WebsiteCache\*.*
Del /F /Q /S %LOCALAPPDATA%\Temp\VWDWebCache\*.*
Del /F /Q /S “%LOCALAPPDATA%\Microsoft\Team Foundation\3.0\Cache\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\*.*“
Del /F /Q /S “C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\*.*“
ECHO Complete
2 - Save the file as a .bat file.
3 - run it from the com­mand prompt.
I had a backup of my project. Restored the backup and it worked. Thanks for all the suggestions.

Categories

Resources