How to update DLL in approot/bin - iis

I currently have an Azure instance running. The problem is that Publishing to staging is taking 15+min each time.
I was hoping to make small changes to my code and update the corresponding DLL in the VM directly myself via remote desktop. However, when I try to copy paste the DLL into the approot/bin folder, I get an error that the file is currently in use.
I have already stopped the IIS instance in the IIS manager. What other service/process do I have to stop in order to update the file?
Thanks

To answer your question after you RDP your instance, you can kill the role host process WaWebHost.exe or WaWorkerHost.exe which will release the DLL holdout and you can copy the DLL.
You have a very small window to copy your DLL to bin folder once you kill the host process so have it ready to copy. May be open a command window and write your command to copy DLL from Source to BIN, and then kill the host process (WaWebHost.exe/WaIISHost.exe/WaWorkerhost.exe) and then launch the command to copy DLL.
I also think you know that DLL will not persist so finally you would need to update package with proper dll as usual process.

Related

NT Authority/System can't see protected OS files

The Question:
Why can't the LocalSystem account (NT Authority\System) see files in the Recycle Bins or the Temporary Internet Files directory?
Background:
I created a scheduled task to run using the System account. The purpose of the task is to execute the Disk Cleanup Utility with predefined setting (for example: cleanmgr.exe sagerun:1). When it executes, it seems to run with no errors. But when I check the resources it's supposed to clean (Temporary Internet Files, Recycle Bin etc.), they're still there.
So I thought maybe cleaning up the two resources manually might work. I developed a console application in C# that clears the Recycle Bin and the Temporary Internet Files. I test it and it works just fine. But again, when I attempt to run it as a scheduled task with the System account, I run into the same issue again.
Following the log, it looks like when running the application with System account, it sees no files are in the Recycle Bin or the Temporary Internet Files directory.
Upon checking the Security tab for the Temporary Internet Files directory, it shows System as a full access account to that directory.
I'm so puzzled by this issue. I may be missing something but I assumed the LocalSystem account has the highest privilege on a machine. Is that not the case?

How to hard remove uninst.exe that is generated by NSIS?

I am using NSIS to write an installer for my windows application. After installing the application, an uninst.exe is also generated in my program directory. Later on I need to uninstall my program but I failed to do that in control panel. Therefore I went to the file system and tried to delete the directory. Everything other than that uninst.exe was removed. I've tried changing permission of this file and other methods but it doesn't work.
WriteUninstaller does not set file permissions or any other attribute that might prevent you from deleting it. It sounds like the file might still be in use by something on your machine.
Things to try:
Use Task Manager or Process Explorer to see if there is a uninst.exe process still running.
Use the find handle feature in Process Explorer to find any open handles to the file.
Use Process Monitor to get detailed information about the failed delete operation.
Check %LOCAL­APP­DATA%\Virtual­Store to make sure UAC Virtualization is not tricking you with "ghost" files.
Disable your Anti-Virus.
Reboot the machine and try to delete the file again.

Updating VSTO Excel Add-In

I have written an VSTO Excel 2010 AddIn and successfully installed it on a machine that is not my development machine. I installed it manually by first creating a folder to hold the AddIn application files. The folder is C:\TestXL2010. I then placed all of the files from my machines project bin\release folder into the TestXL2010 folder on the test machine. Next I created and ran the installation registry script that contains the following lines.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\TestXL2010]
"Description"="TestXL2010"
"FriendlyName"="TestXL2010"
"LoadBehavior"=dword:00000003
"Manifest"="file:///C:/TestXL2010/TestXL2010.vsto"
At this point, everything appears to function as expected. Now the problem. I made some changes to the application, rebuilt the solution and copied the new set of files into the TextXL2010 folder. Excel does not appear to see the new files. It is acting as if it is still running on a cached set of the original files. I have tried uninstalling, renaming, etc. to no avail. Excel just appears to be stuck on the first version of the application. Any suggestions as to what I need to do to either clear the cached version or make Excel see the new version would be greatly appreciated.
well this could be because application is getting loaded from clickonce cache, to avoid append |vstolocal in manifestpath like "Manifest"="file:///C:/TestXL2010/TestXL2010.vsto|vstolocal", . vstolocal ensure that your solution is loaded from the installation folder, rather than the ClickOnce cache.
Check your system Task Manager for a background Excel.exe process running. Kill it or reboot to clear it. If an add-in fails, a copy of Excel may keep running in the background and it prevents new or changed add-ins from taking effect.

Can't delete files, IIS lock

I have a poweshell command which deletes the folder(i.e. Summer) from wwwroot directory and recreates the folder with the necessary files(images, css, dll etc) in it. The problem is every once in a while the IIS tends to lock some of the images or files in the directory so the powershell command fails to delete the file. I do recycle/stop the apppool before running powershell script which is used by site but still the problem persists. This issue is random i.e. the powershell script can delete the folder sometime while it can't other time. The weird thing is, if i start deleting the contents (subfolders, files) inside 'Summer', at the end, i am able to delete 'Summer' folder, but it is an manual process and which is tedious.
Is there any command which i can put in powershell or batch file to delete 'Summer' folder, even though when it is locked by IIS?
I agree with #Lynn Crumbling and recommend iisreset.
Sysinternals has two tools that provide other options:
The ProcExp tool allows you to find which processes have open handles to a given file, and allows you to close that handle. The downside of this tool is that it's not a command line tool.
The MoveFile tool allows you to schedule the file to be removed after reboot.
You can use the IIS powershell commandlets to start and stop app pools, web sites etc
Import-Module WebAdministration;
Stop-WebAppPool ${appPoolName}
Stop-WebSite ${webSiteName}
you can then start them again afterwards using the opposite commands
Start-WebAppPool ${appPoolName}
Start-WebSite ${webSiteName}
As put in comment, fully stopping IIS using iisreset stop would work.
Also, you may want to stop only the application from which you are trying to delete files from. Look at the Administration Guide.

SelfDeleting application in VC++?

I want to delete a folder which contains the currently running application. How can i do it..? is there any way of doing it ? i.e the folder which contains the application should delete after the application has finished running ?
Your best bet is probably to use the Win32 API MoveFileEx. It has a flag that can be set for deleting files when they are in use on the next reboot called MOVEFILE_DELAY_UNTIL_REBOOT. Set the new filename parameter of MoveFileEx to NULL to perform this type of delete.
If dwFlags specifies
MOVEFILE_DELAY_UNTIL_REBOOT and
lpNewFileName is NULL, MoveFileEx
registers the lpExistingFileName file
to be deleted when the system
restarts.
Note: Normal files that are in use can be deleted normally using the Win32 API DeleteFile depending on if they were opened (Using the Win32 API CreateFile) with FILE_SHARE_DELETE permission. I don't think running programs by default on Windows have that permission though. When a file is specified to be deleted that is in use but that was opened with this flag, then the file will be removed when the last file handle is closed.
This is hairy. I had to implement this once for a self-patching app, where the patcher had to (by client request) delete itself after installing the patch. You can do this by launching a helper DLL which deletes your process, along with itself.
The full method for deleting your process can be found here: http://www.handcraftedbytes.com/articles/writing-install-and-uninstall
As others have pointed out, you're not going to be able to delete the folder that your executable resides in while it exists there. My suggestion is to:
Use MoveFileEx to move your executable off to a temporary directory,
delete your application's directory,
delete your executable using the self-deleting DLL method described in the link above.
You cannot delete an executable file that is currently running, however you can delete a batch file that is currently running (cmd.exe loads the whole file into memory and then you can delete it).
So the simplest solution would be to launch a batch that tries to delete the .exe in a loop (because it may not work the first time - until your .exe has been unloaded) and then exit your process - with the batch file still running.

Resources