Modifying the registry with msi installer - visual-studio

I am using Visual Studio's MSI plugin to create an install. My intentions is to make it run on startup using the registry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
for example this is Skype's key in the registry
"C:\Program Files (x86)\Skype\Phone\Skype.exe" /minimized /regrun
The problem I have is I created a string key in that location but I just need to make sure it's pointing to my program I'm installing which would be in their "Application Folder" but I am not sure where that would be(Program Files or Program Files (x86) or user defined location).
Is there a variable I can put in the value that would point to my program despite where it goes?

The kind of thing you want in the Registry view in the IDE of the setup project is to have the Value of the string in the registry be [TARGETDIR]My.exe
TARGETDIR is the property name for the Application Folder (see the properties window) and specifying it in square brackets causes it to be resolved to the actual value at install time. Note that you don't need a slash because [TARGETDIR] has a trailing one.
This should be a good start, despite being old:
https://www.red-gate.com/simple-talk/dotnet/visual-studio/getting-started-with-setup-projects/?_ga=2.217704863.888096756.1503861862-798639290.1503861862
https://www.red-gate.com/simple-talk/dotnet/visual-studio/visual-studio-setup---projects-and-custom-actions/?_ga=2.112181773.888096756.1503861862-798639290.1503861862
https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/?_ga=2.112181773.888096756.1503861862-798639290.1503861862
and the docs start here:
https://msdn.microsoft.com/en-us/library/wx3b589t(v=vs.100).aspx
and the standard properties start here, such as TARGETFIR:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa370905(v=vs.85).aspx

Related

Adding a context menu item in Windows for a specific file extension

I am trying to add a context menu item to a DLL file. The reason is that I have written an application which retracts and deployed a managed DLL file to the GAC. The application is all good, but now I want the ability to right-click a DLL and just click "copy to GAC".
I've tried to follow instructions as per this question: How add context menu item to Windows Explorer for folders but to no avail. When I right click a DLL, nothing new is appearing.
I've also tried the following: https://winaero.com/blog/add-register-dll-context-menu-commands-for-dll-files-in-windows-10/#comment-22928 - ran the reg file but no result as well.
Maybe there's a hardcoded restriction on DLL files for such actions?
Here's my current registry setup:
Any guidance would be appreciated.
The general steps to achieve this are as follows:
Fire up regedit
Identify the ProgID for your extension - go to HKCR\.yourextension and take note of the default value (in your case, dllfile)
Navigate to HKCU\Software\Classes (for user) or HKLM\Software\Classes (for all users)
Look for a matching key (in your case dllfile) - if it's not there, create it
Ensure it has a sub-key called shell
Add a sub-key to shell named as the command you want (refer to image below)
Add a sub-key to your new key called command
Modify the (Default) value to be the command you want to execute. %1 will give you the path of the file in context (remember to wrap it in " due to potential white-space in the path)
You seem to have done all the above, so you may be doing something wrong, as this is my result after a quick sanity test:
So, here are a few things I can think of that would make it behave non-intuitively:
You're adding this to HKLM rather than HKCU - due to how inheritance works, I do believe adding it to HKLM would require a restart, or at best, a shell restart
You've added this to HKCU but your dll requires elevated permissions to access
You have some silly syntax error somewhere ;)
The sample command I used to test this was a good old boring "C:\Windows\notepad.exe" "%1"
This is based on andromeda947's answer here:
If you have admin rights you can use HKEY_CLASSES_ROOT\SystemFileAssociations\.yourextension, which is simpler as it doesn't require an intermediate ProgID.
Option 1: edit the registry manually
add a new key at HKEY_CLASSES_ROOT\SystemFileAssociations\.yourextension\shell\your menu entry text\command creating any keys you need to in that path (if there's not one for .yourextension add it; if there's not one for shell add it; etc)
set the default value for command (the last key you created) to C:\path\to\yourapp.exe "%1"
Option 2: I made a tool to do this
you can download it here. This is an example of how to register notepad.exe as a context menu item for dll files.
regwincontext.exe dll "notepad it" C:\Windows\notepad.exe

MSI installer creates unattended shell open key

I created an MSI installer project in VS2015, set up everything, then added a file extension associtation with the "File Types Editor", assigned my extension to my application, as an Open command.
The COMMAND was the application from the "application folder", the EXTENSION was set, then the &OPEN was set as NAME=&Open, Arguments="%1" VERB=open. Nothing else.
I generated the .msi file, then started. At the end of the installation, I found out that in the registry Computer\HKEY_CLASSES_ROOT\\shell\open\command key there were two item, one is (Default) REG_SZ with value "myexe" "%1" as I expected
Unfortunately there was another item: "command", "REG_MULTI_SZ" and the Data was something weird, for example "LZ*a!t4(v=++Tt$)tOk_>[1jfrS!,nB`L6ciHLW!, "%1"" which I don't know what it is. When I delete the .msi file, and double click on a file with my registered extension, a popup dialog appears as "network resource cannot be found" and Windows wants my .msi installer back (browse dialog comes in)! I don't know how to prevent this unwanted situation. :( Any help would be highly appreciate!
Windows Installer uses so-called Darwin Descriptors to implement resiliency, wherein a corrupted installation can be repaired automatically. Your attempt to delete the .msi rather than to uninstall it acts like a corrupted installation, so the system attempts to fix it. However, since the .msi itself has been removed, it has to ask for help.
The short answer here is to suggest that you not worry about the exact values in the registry key. Since you're using an Extension table instead of a Registry table entry, the registry is an implementation detail; you should prefer to ignore such detail. Instead, if after a successful installation your program launches as expected upon double clicking the associated file, and it stops doing so after properly uninstalling your application, all is well.

How to change the path for "run command" "notepad"?

Where is in the registry the path executed when I run the "notepad" command in windows "Start->run command" interface? I want to change it for notepad++ (it is required so, although could look not really good)
If you are like me you use windows run command all the time. I hate using the mouse to point and click a shortcut on the start menu. WIN-R are probably the two most over used keys on my keyboard. After thinking about if awhile I hunted down how the run command works. It turns out that it makes a call to ShellExecute, which I guess is not too surprising. The next thing I wanted to find out was exactly how the commands are resolved. The following is an ordered list of how they are resolved ([1]):
The current working directory
The Windows directory (no subdirectories are searched)
The Windows\System32 directory
Directories listed in the PATH environment variable
The App Paths registry key
Naturally the next thing I wanted to do was customize existing commands or add new commands so I do not have to type as much (standard lazy approach). After examining my options which were to put the executable in one of those paths (since it only locates executables and not shortcuts), modify the path environment variable or add a key to App Paths. The App Paths option seems to be the easiest and most flexible to me. Here is a layout of what you need to do to add an App Paths entry ([1]):
HKEY_LOCAL_MACHINE-->
SOFTWARE-->
Microsoft-->
Windows-->
CurrentVersion==>
App Paths-->
file.exe-->
(Default) = The fully-qualified path and file name
Path = A semicolon-separated list of directories
DropTarget = {CLSID}
Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. I cannot guarantee that problems resulting from modifications to the registry can be solved. Use the information provided at your own risk.
The minimum needed to add a new entry is to add the key file.exe where file is the string you want to type into the run command and to add the Default entry which is the fully-qualified path to the file you want to execute. Note that even it the file you are going to reference isn't an exe file you still need to put the .exe on the key. Here is a sample registry file that I created to add a shorter keyword for Internet Explorer:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\ie.exe] #="C:\Program Files\Internet Explorer\iexplore.exe"
After entering that entry into the registry I can simply type “ie” at
the run command to open internet explorer.
Here is a list of some common commands I use at the run command:
cmd – Command prompt winword – Microsoft Word excel – Microsoft Excel
outlook – Microsoft Outlook iexplore – Internet Explorer firefox –
Mozilla Firefox notepad – Notepad compmgmt.msc – Computer Management
Console control appwiz.cpl – Add/Remove programs dialog mstsc –
Microsoft Terminal Service Client regedit – Registry Editor
…
If there is some program that I find myself using all the time I figure out what the run command is for it and if there is not a short easy one I add one to my App Paths as described above. Does anyone else have some other common run commands they use?

IIS Express 8 - Cannot write configuration file

I am trying to use IIS Express 8 for a MVC site in VS2012. I am getting the following error whenever I attempt to create the site:
Filename:
\?\C:\Users\xxxxxx\Documents\IISExpress\config\applicationHost.config
Error: Cannot write configuration file
Is there some way to force IIS Express to use a different location for the config & logs folders? I understand I can point to a different location when I am running iisexpress.exe from the command line, but I have no control over this when using Visual Studio.
Alternatively, has anyone got any suggestions why the error is happening? (Side note: My laptop is in a corporate environment which has some stupid encryption on the "Documents" folder, however I haven't had any problems with other software that saves to this location. I also have given the "Everyone" group full access to the folder.)
EDIT - After following the instructions at http://learn.iis.net/page.aspx/1286/iis-80-express-readme/ I still can't seem to get this working. I've tried the following:
Added HKCU\Software\Microsoft\IISExpress\CustomUserHome registry key pointing to my alternate directory
Added HKCU\Software\Microsoft\IISExpress\8.0\CustomUserHome registry key pointing to my alternate directory
Added HKLM\Software\Microsoft\IISExpress\CustomUserHome registry key pointing to my alternate directory
Added HKLM\Software\Microsoft\IISExpress\8.0\CustomUserHome registry key pointing to my alternate directory
Setting the %IIS_USER_HOME% environment variable pointing to my alternate directory.
Any other suggestions?
#Brad
I had your same problem just now. Removing the encryption on the IISExpress folder and the "Read Only" attribute solved it. In my company Documents is also encrypted, but I don't think removing that encryption from IISExpress would be a problem of any sort.
Hope this helps.
I had a very similar error message caused by a completely different problem.
The Error:
C:\VS\TFS_Projects\SomeSolution\SomeProject\SomeProject.csproj : error : Creation of the virtual directory http://localhost:55063/ failed with the error: Filename: \\?\C:\VS\TFS_Projects\SomeSolution.vs\config\applicationhost.config
Error: Cannot write configuration file due to insufficient permissions
More Details: I couldn't even open the project, as opening it would fail.
I could get prior changesets, and they would actually open fine, but if I got latest the projects couldn't be opened.
Solution: In my case, it turned out that when we changed TFS servers, someone had added the ".vs" folder to source control along with everything else. Under which, one developer had his applicationhost.config set up to run sites on a D:\ drive, while I had no such D:\ drive (well, it was a DVD drive.) I was able to get this working by finding a prior changeset with the un-altered applicationhost.config and replacing my local file. (I could have attempted to actually delete the folder, but I didn't go that route.)
Afterwards, we removed the ".vs" folder from source control.
(I put this solution here because it's where google landed me, so other people having this error message might find the above solutions don't fix it for them, and thus they might be having this problem.)
I'm also in a corporate environment with Encryption on the users folder, and removing encryption and removing the read only flags on everything in the IISExpress folder worked for me.
I'm using Visual Studio 2017 on Windows 10 and to fix this problem I had to disable the OneDrive setting "Save space and download files as you use them". After changing the setting my computer crashed but after rebooting I was then able to change SSL Enabled and everything worked.
For anyone googling this; this might be the same problem as this: http://connect.microsoft.com/VisualStudio/feedback/details/878812/use-iis-express-is-broken-in-vs-2012-on-windows-8-1
You can check it by downloading Prcocess Monitor and run it with a filter for "Path" contains "\Documents\IISExpress\config" and then try to change the project to use IIS Express. If there is a CreateFile entry with the result 0xC0190052 as one of the last entries then this is the same issue.
After struggling with this, and verifying encryption and read-only attributes, and having them not work, my solution ended up being:
Navigate to the folder containing the IISExpress folder (in my case, it was in my OneDrive, not Documents folder)
Right click on IISExpress folder > Security tab > Advanced button
Change Owner to yourself, even if it already is
Check the "Replace owner on subcontainers and objects" box
This may not appear until you've completed the Change owner dialog
Open the IISExpress folder
Right click on config folder > Security tab > Advanced button
Add a user > Add principal
Change location to local machine (and not a domain)
Enter the name NETWORK SERVICE and "Check Names"
Press OK to get back to the Advance Security dialog
Make sure to check "Replace all child object permission entries with inheritable permission entries from this object"
Worked in Windows 10 with IISExpress 10, for both VS 2013 and VS 2017.
C:\Users\xxxxxx\Documents\IISExpress\config\applicationHost.config
Uncheck the read-only attribute from the file. It worked for me.
Adding the registry entry seemed to work, however, using environment variables in the registry entry did not. In my environment only our documents directory is redirected, so I simply wanted to move the IIS Express config directory up one level to the %USERPROFILE% directory. However, that did not work. IIS Express read the environment variable literally and of course failed to run.
I had the same issue before, running VisualStudio as Administrator (Run as Administrtor) resolved the issue.
I also had the problem and tried to fix it with setting the registry key in HKCU\Software\Microsoft which didn't work.
The error I made, was using HKCU because, since I do not have permissions to edit the registry under by normal account (which I use to run visual studio), I was using an administrative account. Then of course, HKCU was for that account.
So I just used HKEY_USERS\"my normal user's SID" instead and, when starting iisexpress.exe manually, it created its files at the location indicated. What still didn't work was using iisexpress from visual studio. It still seemed that VS didn't use the registry setting at all.
Finally I resorted in setting a non UNC path for Shell Folders\Personal and User Shell Folders\Personal in HKU\"my normal user's SID"\Software\Microsoft\Windows\CurrentVersion\Explorer\ which did the trick.
I received the same error but in a different context. Opening a project (.csproj file) provided by another developer returned this error and failed to do anything:
Creating of the virtual directory http://localhost:58753/
failed with the error:
Filename: \?\C:\Users\xxxxx\Documents\Clients\xxx\Gen
II\xxx\,vs\config\applicationhost.config
Error: Cannot write configuration file
I removed both Encryption and the R/O attribute from the directory containing the project files and applied to all subfolders and files. Visual Studio can now read the project.
In my case I moved the folder to another location, so I had to edit the applicationhost.config file and changed the virtualdirectory entry to the new location. Removing encryption and setting read only off did not help. I imagine if I had just copied it instead of moving it, it would have happily continued working.

How do I update an Environment Variable in a Visual Studio Deployment Project

I would like to append a path to the PATH environment variable in a Visual Studio 2005 deployment project. How does one do this?
Use the registry editor view in the setup project and create the path key in the appropriate place
ie.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
and create a string value called "Path"
and enter this as your value:
"[%Path];[TARGETDIR]"
[%Path] is a placeholder for the original string in the existing Path value.
There are problems with the above mentioned approach of using the registry editor view and creating a key called PATH with value "[%Path];[TARGETDIR]". While the method works fine when installing the program, the default behavior during uninstall is to delete the entire PATH variable, not just the added [TARGETDIR]. I have not found a way to disable this behavior, although it seems like some conditional behavior might be possible.
You need to add a row to the Environment Table of the MSI file to do this. You can find information on that table here, http://msdn.microsoft.com/en-us/library/aa368369(VS.85).aspx. You can use Orca to do this or automate the procedure with some VB Script. The platform SDK contains the VB script file, WiRunSQL.vbs that can you used to automate build actions for your program.

Resources