Configuring a Windows Protocol in a VS2010 Deployment Project - c#

I have an application that is called in a command line fashion. I wish to associate a protocol with it, let's call that protocol runapp. runapp will call runapp.exe.
I plan to have this configured through the Registry portion of the application Deployment Project. I started by looking at other protocols, specifically mailto. I noticed that I need the following:
a new key under HKEY_CLASSES_ROOT called runapp
a new series of keys to create HKEY_CLASSES_ROOT\runapp\shell\open\command
under the runapp key, I will add two strings, (Default) with value URL:runapp protocol and a second string URL Protocol and no value
also under the command key, I need to add one string, (Default) with value "C:\path\runapp.exe" "%1"
I set all these up just fine. When I actually run the installer, though, before my (Default) strings, there is already another valueless (Default) string. So it looks like I am settings a (Default) string in the wrong way. What's the right way?
Secondly, I manually hacked this incorrect key in regedit after backing everything up. Now, with my keys looking very much like mailto's, I finally stop getting the "No program found" error, but my application actually doesn't seem to execute at all.
Any thoughts on how to correctly set (Default) strings and further troubleshoot protocol issues? Thanks.

Related

C# ask user for servername and save for everytime application is ran

I've tried searching but had no luck as I'm not sure I'm using the correct terminology.
I'm trying to figure out how to ask a user to input their server name on the first application run, store that and insert it into filepath/connection string.
Pseudocode for initial run:
I see this is the first time you ran this application. Please input your fileserver name.
user inputs: fileserver123x
Write Fileserver123x to text file.
Initialize database connection
string fileServername = read text file;
connection = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\'"+fileServerName+#"'\share\folder\Database.accdb;Persist Security Info=False;");
rest of code
I'm looking to see if there is a better/more professional way to store the user file server information other than via text file and read it each time the DB connection is initialized.
Any thoughts?
Your concept looks fine, I'd suggest a few improvements:
Store the file server name in the Windows registry instead of a text file. This is where well-behaved Windows programs store their configuration data.
Store the complete path to the database instead of the file server name. That way, your customers don't have to use a fixed share/folder name.
Make a configuration window where this configuration data can be modified. This can also serve as the window you show on your first run.
Don't read the configuration data each time a connection is opened. Read it once when your application starts and store it in a global variable.
(Note: In general, global variables are a code smell, but storing global configuration data is usually considered a legitimate use case. If you want a more advanced solution that simplifies unit testing, look into dependency injection for your configuration data.)

Access to registry seems to be different from different sources

I am trying to add a registry key in my C# code under
HKEY_CLASSES_ROOT\*\shell\blabla
I want the user to be able to send any file to my application, kind of like Open with UltraEdit or so.
I don't have administrator rights and the users won't have administrator privileges, too.
If I am doing that in my C# code as posted below, I get a
System.UnauthorizedAccessException
Registry.SetValue("HKEY_CLASSES_ROOT\\*\\shell\\blabla", null, "FastSearch");
string path = Application.ExecutablePath;
Registry.SetValue("HKEY_CLASSES_ROOT\\*\\shell\\blabla" + "\\Command", null, path + " \"%1\"");
If I run Regedit and attempt to do it manually myself, I get a similar error:
Error! Key could not be created. Error when writing to the registry.
BUT, if I double click a *.reg file that attempts to write the SAME KEY, everything works!
So why is that?
And do I have a chance to get this done through code?
Or should I just change my code to run that *.reg file?
UPDATE:
Actually the *.reg file did not write the SAME KEY as stated above, but
HKEY_CURRENT_USER\Software\Classes\*\shell\blabla
I didn't notice that. It seems as anything added under HKEY_CURRENT_USER\Software\Classes*\shell\blabla is also added to HKEY_CLASSES_ROOT\*\shell\blabla. Sorry for the confusion.
Although the problem is solved already and the reason for successful import of *.reg file was found out also in the meantime in comparison to C# code, here is a complete answer for this question.
HKEY_CLASSES_ROOT Key (short HKCR) as described by Microsoft shows file name extension associations and COM class registration information which are effective for the current user.
The real locations in registry for those keys are:
HKEY_LOCAL_MACHINE\Software\Classes (short HKLM\Software\Classes) containing the defaults for all users using a machine and
HKEY_CURRENT_USER\Software\Classes (short HKCU\Software\Classes) containing the user specific settings which override the default settings from HKLM\Software\Classes.
A registry write to HKEY_CLASSES_ROOT is always redirected to HKLM\Software\Classes. A write access to any key in HKLM requires administrative privileges which is the reason for the error message.
Microsoft recommends to write directly to either HKLM\Software\Classes or to HKCU\Software\Classes depending on changing the defaults or the effective file associations for the current user.
Write operations to keys under HKCU do not require administrative privileges.
HKCR should be used only for reading currently effective settings for file name extension associations and COM class registration information and not for adding or changing them.

Is it possible to change the device name programatically in Attachmate EXTRA?

I've written a win forms application that uses Attachmate EXTRA. The application itself works great but I was just notified that there is a need to be able to switch to different device names for the sessions. The names would be set before the sessions are launched and then the session would go through the connection process. The only way I can think to do this is create and save a separate session with each device name needed and go that route but I would like to be able to do this dynamically instead if possible.
I've tried doing this during debug to look at the object but have been unable to find a method or property to set.
After having a support ticket entered and getting confirmation, the only way to change the device name programatically is to open the .EDP file, replace the string with the new device name, save the file and then run that .EDP file.
Apparently their new application, Reflection, can handle these types of things with calls without making changes to the files.

Getting back "ResolveIOD" while trying to open HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\ on Windows 7?

I'm trying to get at the UserData registry subkeys on a C# 3.5 application so I can look up the installed location of an external program to start it.
Doing something like this:
RegistryKey installerKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Installer");
and then
RegistryKey userDataKey = installerKey.OpenSubKey("UserData");
returns null; if I go back and call installerKey.GetSubKeyNames() to figure out which subkey names are present under Installer it only returns one subkey name: ResolveIOD. I haven't been able to find what only being able to find this key indicates.
regedit does not show the ResolveIOD key being there, and it shows that much more than just that one key is present - UserData, Folders, Secure, etc are all there and not returned by GetSubKeyNames() either.
This is my first time accessing anything in the Installer section of the registry hive, so I've probably done something wrong. Is there some kind of special permission I have to request in order to read these (probably sensitive, security-wise) keys from a client application, or is this generally not an acceptable thing to do on Windows 7 and I should find an alternative way of figuring out where the program is located?
Because I'm seeing this mentioned on other registry questions: This is running as a 32-bit application on 64-bit Windows.
First, to ensure you are accessing the 64-bit registry rather than the Wow6432Node sandbox, use the RegOpenKeyEx function with KEY_WOW64_64KEY (http://msdn.microsoft.com/en-us/library/ms724878%28v=vs.85%29.aspx) included as one of the access options.
pinvoke.net has a C# example: http://www.pinvoke.net/default.aspx/advapi32/RegOpenKeyEx.html
Also note that with UAC enabled, an unelevated app will, at best, only have read access to HKLM.

How to add registery key-value in Visual Stadio Setup Project to another program?

I have c# program that needed to be in
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
To run at startup after installation.
I use Visual Studio 2017 Setup Project but in it's Registry tab goes as far as :
HKEY_LOCAL_MACHINE\Software\
I know a program should not change others registry but in my case, I couldn't find any other way to do it.
I wrote a program to send it's ping or beacon or heart beat and authenticate to a server every N minutes and it should run after reboot.
I tried to wrote a service but as far as i understand i could not send string to service programmatically, it has custom command which it revise only integers. after that i tried to use WCF but it is too complicated for such simple task after that i realize if i could put my program in registry and it run after reboot, it will do the job.
You can right-click on the key name and select New key, and keep doing that until you need to create an actual name-value pair. That's when you right-click and add New string value.

Categories

Resources