How the below scenario can be achieved,
1) There should be only one exe which should execute some code
2) Also, it should add an entry in the add/remove programs
3) When i uninstall the entry from add/remove programs, i need to call some functions/api's to complete the uninstallation.
If the "call some functions/api's" you need is as simple as removing files at next reboot - make it a "delete on reboot" as explained here:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\Delete on reboot\command]
#="CMD /E:OFF /C REG ADD >HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v \"Del %1 >OnNextReboot\" /d ^\"cmd.exe /c DEL /F /Q \\"%1\\"\" /f\""
[HKEY_CLASSES_ROOT*\shell\Open]
[HKEY_CLASSES_ROOT\Folder\shell\Delete on reboot\command]
#="CMD /E:OFF /C REG ADD >HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v \"Del %1 >OnNextReboot\" /d ^\"cmd.exe /c RD /S /Q \\"%1\\"\" /f\""
To remove registry entries on reboot use this (explained here):
[HKEY_CLASSES_ROOT*\shell\Delete on reboot\command]
#="CMD /E:OFF /C REG ADD >HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v \"Del %1 >OnNextReboot\" /d ^\"cmd.exe /c DEL /F /Q \\"%1\\"\" /f\""
[HKEY_CLASSES_ROOT*\shell\Open]
[HKEY_CLASSES_ROOT\Folder\shell\Delete on reboot\command]
#="CMD /E:OFF /C REG ADD >HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Currentversion\RunOnce /v \"Del %1 >OnNextReboot\" /d ^\"cmd.exe /c RD /S /Q \\"%1\\"\" /f\""
Related
I developed an asp.net mvc application to manage some business process in our organisation. This application use the following main frameworks :
Asp.NET MVC 5.0;
Entity framework 6.0 to manage db access;
MS Identity 2.0 to manage security : users, roles, access authorizations...;
Bootstrap;
I noticed that the packages directory of this solution has become very huge(more than 350 MB).
I tried to use the "Remove unused packages" feature of ReShaper but it did not significantly reduce the size of the packages folder. I think that there's some unnecessary packages that must be removed.So, my questions are :
Is it normal to have a packages directory with a size more than 350 MB for a simple asp.net MVC solution ?
How could I reduce the size of this directory and remove all unused and unnecessary packages?
Thanks for your help.
It's 2018, disk space is cheap, 350 MB is not "huge".
There's loads of metadata in those packages, and each package exists as a .nupkg and in extracted form, doubling its size (barring ZIP compression used for packages). So if a package like MVC 5.2 is 300 KB and its extracted size is 1,5 MB, in total that'll already be nearly 2 MB for one package. And you probably have dozens, if not more packages, each taking up their own disk space.
This only becomes a problem when other people on your team upgrade packages and then you pull their version, your packages directory still contains the older versions, as well as the newer versions.
So it can help to regularly clean your packages directory if this happens. Then only the currently used packages will be downloaded again.
Multiple versions of a package installed in a solution also cause older versions to coexist next to newer ones; upgrade all packages for a solution at once ("Manage NuGet Packages for Solution") or consolidate them on the Consolidate tab. This ensures all projects reference the same package version.
Packages included in one of my projects is 450Mb and works as desired and without issues. So I would not be so worried about yours being 350Mb.
If Resharper could not remove any unused packages then it would suggest that they are all being used at some point in your application. How can you find the unused NuGet packages in a solution? was a useful post on Resharpers tool for this.
Note also you can use the Visual Studio Extension ResolveUR - Resolve Unused References
If the packages are being used the project will break when trying to build and the package has been removed.
I reduced the size considerably with a script that removes languages other than English and things like Android/Xamarin, that I don't use:
FOR /F %%G IN ('DIR packages\ru /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\ja /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\de /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\fr /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\es /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\it /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\ko /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\zh* /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\monoandroid* /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\sl* /B /A:D /S') DO RMDIR /S /Q "%%G"
FOR /F %%G IN ('DIR packages\wp* /B /A:D /S') DO RMDIR /S /Q "%%G"
Today I'm wondering if I could delete a TEMP file. I have the coding to delete the correct path name but it wont work on any other win pc due to only allowing me to using my folder naming on pc.
This is because when I play a mp3 though resources in winforms it wont let me play another song till TEMP file from previous play is deleted.
I'm looking for all files delete to save me from selecting a path name where I prefer to delete all files in the TEMP as I want to share my tool with others.
Heres the coding I'm using
if (System.IO.File.Exists(#"C:\Users\g\AppData\Local\Temp"))
{
System.IO.File.Delete(#"C:\Users\g\AppData\Local\Temp");
MessageBox.Show("TEMP File Deleted");
}
else
{
MessageBox.Show("Not Done");
}
You can use Path.GetTempPath() to get the path of the temporary folder, But There may be some files in the temp location are used by another processes, so you should care about the IOExceptions while deleting those files/folders,
// for deleting sub directories in temp
foreach (string subDirectory in Directory.GetDirectories(Path.GetTempPath()))
{
try
{
Directory.Delete(subDirectory, true);
}
catch
{
}
}
// for deleting files in temp
foreach (string tempfile in Directory.GetFiles(Path.GetTempPath(),"*.*",SearchOption.TopDirectoryOnly))
{
try
{
System.IO.File.Delete(tempfile);
}
catch
{
}
}
cls
#echo off
cd %temp%
del %temp%\*.* /f /s /q
for /D %%f in (%temp%\*) do rmdir "%%f" /s /q
del c:\windows\temp\*.* /f /s /q
for /D %%f in (c:\windows\temp\*) do rmdir "%%f" /s /q
del C:\Windows\Prefetch\*.* /f /s /q
for /D %%f in (C:\Windows\Prefetch\*) do rmdir "%%f" /s /q
del "C:\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /f /s /q
for /D %%f in ("C:\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*") do rmdir "%%f" /s /q
del "C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*" /f /s /q
for /D %%f in ("C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*") do rmdir "%%f" /s /q
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
cls
Save this code in a .bat file ...
It will clear all the temp or dump files from your system.
for more deep clean use below in ".bat" file
#echo off
del /s /f /q %windir%\temp*.*
rd /s /q %windir%\temp
md %windir%\temp
del /s /f /q %windir%\Prefetch*.*
rd /s /q %windir%\Prefetch
md %windir%\Prefetch
del /s /f /q %windir%\system32\dllcache*.*
rd /s /q %windir%\system32\dllcache
md %windir%\system32\dllcache
del /s /f /q "%SysteDrive%\Temp"*.*
rd /s /q "%SysteDrive%\Temp"
md "%SysteDrive%\Temp"
del /s /f /q %temp%*.*
rd /s /q %temp%
md %temp%
del /s /f /q "%USERPROFILE%\Local Settings\History"*.*
rd /s /q "%USERPROFILE%\Local Settings\History"
md "%USERPROFILE%\Local Settings\History"
del /s /f /q "%USERPROFILE%\Local Settings\Temporary Internet Files"*.*
rd /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
md "%USERPROFILE%\Local Settings\Temporary Internet Files"
del /s /f /q "%USERPROFILE%\Local Settings\Temp"*.*
rd /s /q "%USERPROFILE%\Local Settings\Temp"
md "%USERPROFILE%\Local Settings\Temp"
del /s /f /q "%USERPROFILE%\Recent"*.*
rd /s /q "%USERPROFILE%\Recent"
md "%USERPROFILE%\Recent"
del /s /f /q "%USERPROFILE%\Cookies"*.*
rd /s /q "%USERPROFILE%\Cookies"
md "%USERPROFILE%\Cookies"
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?
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 Performing IIS Reset
IISRESET
ECHO Deleting 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 command prompt.
I had a backup of my project. Restored the backup and it worked. Thanks for all the suggestions.
I have various types of VM's running that I'd like to use my local machine's proxy settings. This way any browser activity from the VM would go through the host proxy even if the VM's proxy settings are turned off. But they seem to ignore the settings and just go straight out to the internet bypassing the proxy.
I have a WinInet settings being setup via winhttp.dll and wininet.dll external calls. But I'm not able to find the magic answer to getting the VM's to go through the proxy instead of bypassing.
Help?
I've had luck with the following reg hack for 32bit:
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v MigrateProxy /t REG_DWORD /d 0x1 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0x1 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d myproxy.local:3128 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d ^<local^>; /f
REG ADD "HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxySettingsPerUser /t REG_DWORD /d 0x0 /f
For 64bit I've had less luck, but this works for browsers. :
REG ADD "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /v MigrateProxy /t REG_DWORD /d 0x1 /f
REG ADD "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0x1 /f
REG ADD "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d myproxy.local:3128 /f
REG ADD "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d ^<local^>; /f
REG ADD "HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxySettingsPerUser /t REG_DWORD /d 0x0 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v MigrateProxy /t REG_DWORD /d 0x1 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0x1 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d myproxy.local:3128 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d ^<local^>; /f