1

I am following How to run a ".bat" file during installation?

to run a registry clean up of my Visual studio installer project. Some add-ins were loaded into Excel, and at uninstalltion I would like to remove them from the Add-in dialog by removing the registry.

The cmd command however cannot execute

REG DELETE "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options" /v "OPEN"

because it does not have administrator right

'reg' is not recognized as an internal or external command, operable program or batch file

How do we run a batch file from a VS installation project as administrator ?

Community
  • 1
  • 1
Kenny
  • 1,902
  • 6
  • 32
  • 61
  • See http://www.techgainer.com/create-batch-file-automatically-run-administrator/ Instead why dont you embed a manifest in your setup.exe to require adminitrative rights to run? – Ganesh R. May 12 '15 at 10:40
  • Do you mean the manifest of the main project added as "localized resource from..." in setup project, notably this part to be replaced by ? Does it mean user right for the plugin itself and not of installer? I am trying to run the .bat together with the Uninstaller. When I install, it ask for administrator right anyway. – Kenny May 12 '15 at 14:43
  • That manifest will ask for admin rights. I assums it is embedded in the installer. Can you embed a similar manifest in the uninstaller? – Ganesh R. May 12 '15 at 15:09
  • I am not sure how. uninstaller does not have any manifest. It takes the manifest from the main project as one of the resources. Build of uninstaller have no manifest either, only .msi and .exe (and other folder containing .exe of prerequisites) – Kenny May 12 '15 at 15:12
  • I just looked at your issue again and it does not seem to be a rights issue. You are trying to delete a key in the HKCU which is the logged in users hive which you should be able to. The problem seems to be the REG is not found. This could be a working directory issue or the %PATH% variable on that machine is corrupted. Reg.exe is in the system32 folder. So see if using %windir%system32\reg.exe ...... works – Ganesh R. May 12 '15 at 15:19
  • I supposed it was because of the administration right because I tested by running cmd and executing the command at cmd. When cmd is run without administrator right, REG is not found. REG is known when I executed cmd as administrator. Hope that gives some hints to the problem. – Kenny May 12 '15 at 15:24
  • when you run in a standard command prompt, the working directory is c:\Users\USERNAME\ folder. When you elevate the command prompt, the working directory is C:\Windows\System32. So its a %PATH% environment variable issue. – Ganesh R. May 12 '15 at 15:28
  • Try hardcoding the path to reg.exe in the batch file and see if works – Ganesh R. May 12 '15 at 15:29

0 Answers0