How do I mark a directory to be deleted after reboot? - windows-7

I've got an uninstaller that performs some actions and then prompts the user to reboot. I'd like a directory to be deleted after the reboot takes place. I know there's a way to do this, I'm just not sure how.
I'm using a WiX installer, and I'd imagine I could use that to do so, somehow, but I'm open to alternatives (whatever's simplest is just fine with me). My target platform is Windows 7, though it would be nice if this worked with older versions of Windows as well.
What's the simplest way to mark this directory for deletion after a reboot?

If you have a locked file condition Windows Installer can handle the deletion after the reboot but there is no built-in way of instructing it to only delete it after a reboot. I think the only way you could do it would be to use a custom action to record a RunOnce registry entry that instructs it to do the delete. You can't use the Registry table for this as Windows Installer has no way of recording to the registry as part of an uninstall.
Still, you are coloring outside the lines on this one so I'd want to understand the why of this requirement in determining if it's valid.

Try using SysInternal's "MoveFile". Specify "" as the target and poof! Assuming you don't end up in permission hell... :(

Related

How to make a program run at startup (as admin) with WiX on Windows 10

Can someone tell me how to properly install this program to run with admin privileges at startup on Windows 10 using WiX?
All the help I've seen via Google has been old ones saying to use the Startup folder. Now, although the Startup folder still seems to work, I don't think it's the preferred way to do it anymore.
I also need think the need to run as admin adds a wrinkle in the process.
I can see few ways to do it:
Set registry values using WIX:
in this case you should add your app install path to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (x86) or HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run (x64). Problem is to get windows version. I guess it's possible to do by WIX (using few RegistryKey elements with condition) but I haven't tried.
Use custom action to set registry values: the same as previous, but using C#. Also in this case it will be easy to determine windows version and add your app to the right key.
Using custom actions and Task Scheduler. For example you can use this library to add task to run after startup.
Run cmd using WIX to set up Task Scheduler (or via custom actions). The same as previous but without any libs.
A program requesting or requiring admin is a function of the EXE not WiX. The EXE should be manifested to request elevation.
MSFT has said it is not a best practice to have things in startup request admin. It's a horrible user experience.
The better approach is to do what you said you do in your comment. Have a component running as a service that the non-priv UI can communicate with.

Disable automatic registry update

I'm currently trying to change some few things on my work computer (as a challenge) and after few search, came into this matter.
I try to edit a registry that will finally give me freedom (AutoConfigURL of internet explorer).
When I edit it or delete it, it comes back after a short while (matter of seconds).
Which leads me to the conclusion that there is a script somewhere that recreates the registry automatically.
Maybe PowerShell or just a .bat file.
My question being: what are your ideas of finding out where is that script and how to disable it?
Thanks to you all!
You could use Process Monitor to see what's changing the key. It's an advanced monitoring tool for Windows that shows real-time file system, Registry and process/thread activity. That might can help you to find out the program which changes the registry key.
You could also try the solution in this answer. Try to set permissions for registry keys. Immediatly remove all the permissions after you edit the registry key, then it will be read only.

How do I prevent Windows from performing installations until a reboot occurs?

I am testing installation scripts and must put Windows into a state that a reboot is pending from another installation. I have read how to test whether a reboot is needed. A proper way to set the need is not clear.
The honest answer: I don't know for sure. There are a lot of different registry locations that indicate that a reboot is necessary. I just tried to make an ad-hoc list here: How do I reference the Reboot Pending Property in Burn (WiX). I am not sure what mechanism uses them all, but some of these reboot entries could conceivably cause further installs to be blocked.
As you know there are certain Windows Updates that manage to schedule reboot prompts that will not cease or go away and not allow further software to be installed (at least not Windows Installers). I am not familiar with the APIs used to trigger this - chances are they are Microsoft's own functions that can only be called by TrustedInstaller (Windows Modules Installer service - used to install Windows Updates- capable of replacing files protected by Windows Resource Protection ). Just a theory. If I get time tomorrow I will have another look.
There are features in group policy to disable Windows Installer by policy, but I would not go down that path if I were you. Group policy is heavy stuff and it won't prevent non-MSI installs (so far as I know). I am sure you have already found this option.
Looking at this script: Get-PendingReboot-Query, the SCCM section seems to indicate what is referred to as a "Hard Reboot" ($CCMClientSDK.IsHardRebootPending). Maybe something which indicates a reboot that will not allow anything else to be done before the reboot is done? If you have SCCM available this is the option I would investigate. Unfortunately I am not up to speed on the issue. Maybe try your luck on serverfault.com or even superuser.com where system administrators and power users lurk?
I wouldn't advise you to proceed with a reboot automatically. You should better inform the user that before going with the installation, a reboot is needed.
If you want to make sure that after the reboot (any reboot), the installer will be running, you can take advantage of the Run and RunOnce registry keys:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa376977(v=vs.85).aspx
Basically, if you detect that a reboot is pending, then create those registry behind and also inform the user that he should reboot first the machine.
After reboot, the installation will be loaded automatically by Windows if you create the registries.
You can add an entry in the registry, based on which you can check for reboot. Or perform reboot.
Though I would advise you to avoid reboot, if you can. Windows installer automatically detects if the reboot is required and will indicate the same. Though you can suppress it.
There is a PendingRenameOperations registry, which is set when a reboot is required to do file updates, during an upgrade. In our product, we check for this registry key along with few other product-related registry keys - then display an message to user that reboot is required or not. If reboot is accepted by the user, then install/upgrade is terminated.
Nice article on the same: https://technet.microsoft.com/en-us/library/cc164360(v=exchg.80).aspx

Keep two files in different folders in sync on Windows

Let's say I have
c:\prod\foo.txt
and
c:\work\foo.txt
I would like to get c:\prod\foo.txt automatically and immediately updated from the other file, whenever I change & save c:\work\foo.txt
How can this be accomplished? Installing tools is okay. Windows 7 and up.
Symbolic linking is not a solution for me, as the c:\work is deleted every now and then.
Have you looked at SyncToy?
A: Run SyncToy silently addresses this issue.
SyncToy can be used in conjunction with the Windows Scheduler to automate sync operations.

Why does InstallShield ask for a restart?

I have an installshield installer that works fine under normal circumstances. But when I run it while a particular software is running, the installer asks for a restart at the end.
Now on some research I have come to learn that a restart is asked only when the installer wants to modify files that are currently locked by other processes.
Is there anyway that I can find out which is the file installsheild wants to modify? (but cannot because it is locked by another process)
I would also like to know if it is only file modifications that affect the restart/no restart or is it also associated with registry key modifications.
You can use WhyReboot after the setup, it will show you pending reboot file and registry keys that could not be modified during the setup.
You tagged your question with "windows-installer", so I'm assuming you're using InstallShield to author an MSI installer.
Run the other software app, do a complete log of your install, like:
msiexec -i file.msi -l*vx test.log
In the resulting log, look for all lines containing "RESTART MANAGER". You will get more data on what is prompting for the reboot.
In my case, my installshield project had a "RebootPrompt" User Interface at the end of the Installation sequence with a condition "NOT INSTALLED". So all new installations would always show that Reboot prompt even if not needed.

Resources