I am trying to add my application to StartUp, when I use my code to add an application to startup registry, it gets added but when I check in msconfig or taskmgr its disabled by default. Any idea how to fix this? Tested on Windows 8 and 8.1
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("TestApp", Application.ExecutablePath);
rk.Close();
Should I try to create a shortcut in shell:startup instead?
Thank you for help.
Related
I can see the app in registers but it wont startup.
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey(#"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); // Add the value in the registry so that the application runs at startup
rkApp.SetValue("WindowsSelfRepairTool", System.Reflection.Assembly.GetEntryAssembly().Location);
This is the code I copied from internet, it gets my application to registers because I can see it "On startup" in task manager as well as in the registry editor. But for some reason, when I restart the computer the app wont start.
Also I tried this code in Console App and added code Process.Launch("..") to launch the WPF one. Console starts successfuly but it doesnt run the WPF.. Any help?
I changed my registry via C# with the following code:
RegistryKey regKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
RegistryKey openSubKey = regKey.OpenSubKey(#"SOFTWARE\ASA\Suite", true);
openSubKey?.SetValue("Password", encryptedString, RegistryValueKind.String);
openSubKey?.SetValue("UserName", UserNameTextBox.Text, RegistryValueKind.String);
openSubKey?.SetValue("DomainName", DomainNameTextBox.Text, RegistryValueKind.String);
openSubKey?.Close();
regKey.Close();
These entries did already exist and were only replaced. When I use the same kind of code to read the settings I get the correct settings back, BUT when I open the registry with regedit.exe and search for it manually I find only the old values. In the regedit.exe it is this path: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ASA\Suite
I already looked into the path without WOW6432Node (and even in the HKCU) but there is no ASA entry at all.Has someone an idea what that could be? Why don't I see the changes I made? I am completly puzzled here...
EDIT: I changed my project from anyCPU to x86 and no change, but as soon as I changed it to x64 the keys read were the ones that regedit.exe shows. But I open the 32bit variant of the registry hive, and when I write something here the question persists... why can't I see the changes made? A x86 app under x64 Windows should automatically write to the WOW6432Node, shouldn't it?
EDIT2: I tested the x86 version on an x86 Windows. I change the registry and can read it, but with regedit I cannot see the changes... wtf is this?
EDIT3: I found the changed keys under HKCR\VirtualStore\MACHINE\SOFTWARE\ASA\Suite I don't know why yet, but I search for an answer and post it here.
May be somebody else is overwriting it ?
May be this can help?
http://www.advancedinstaller.com/user-guide/registry-wow6432-node.html
The Wow6432Node registry entry indicates that you are running a 64-bit Windows version.
The operating system uses this key to display a separate view of HKEY_LOCAL_MACHINE\SOFTWARE for 32-bit applications that run on 64-bit Windows versions. When a 32-bit application writes or reads a value under the HKEY_LOCAL_MACHINE\SOFTWARE\\ subkey, the application reads from the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\\ subkey.
A registry reflector copies certain values between the 32-bit and 64-bit registry views (mainly for COM registration) and resolves any conflicts using a "last-writer-wins" approach.
Ok, I have the answer. I didn't wanted to use a manifest so I removed it and thus didn't got asked if the app had to be elevated. So, because a normal user (even if the logged in user had admin rights) can't write to the HKLM, it wrote a key to HKCU\VirtualStore... that way my app could also read the keys but in the regedit.exe it was not where it was expected.
To get around this I implemented a manifest and changed the line with the requestedExecutionLevel:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Now I don't even have to build an x64 and an x86 version but can use Any CPU instead and let my app do the work (i.e.: to look if to use the RegistryView.Registry32 or RegistryView.Registry64)
I know how to tell the registy to run my app on startup.
There are a lot of threads about it.
I used this one:
How do I set a program to launch at startup.
The problem I face is:
I give the user the option to disable/enable this option
when the user uninstall,
there is a key left in the registry that tells the app to run (although the app was already uninstalled)
I know I can handle it by a shortcut in the startup folder, but I tried it already and I have problem with it too.
Thanks
Eli
To remove the entry in the registry you should instruct your installation program to remove the registry value.
If you are using the build in installation project in VS you could do that by implementing the Uninstall event.
If it is a click once installation you just have to ignore it.
Simple solution without using Custom Actions
I just added a registry Key by the Registry editor until I got to the Run folder and added to it the value "name of my app" (on the right panel) and I didn't wrote a path just left it ""
I played with the checkbox (add key, delete key)
and even though I left it with the key. when I uninstalled it was gone.
I have a windows application that uses an assembly that stores some configuration settings in the default application settings.
The settings can be changed in run time and are persisted thus:
Properties.Settings.Default.SelectedCOMPort = options.SelectedCOMPort;
Properties.Settings.Default.Save();
The settings are saved correctly and I confirm this by looking at the user.config file saved in the users application directory E.g.
C:\Documents and Settings\e399536\Local Settings\Application Data\MyCompany\MyTool
However when the tool is closed and then started again all the settings are loaded with their default values.
Checking the user.config file once the application is running confirms that the settings are still as saved.
The settings are loaded thus:
options.SelectedCOMPort = Properties.Settings.Default.SelectedCOMPort;
Why are the default settings being used and not the saved ones?
Have I missed something??
# Tenaciouslmpy
The settings are loaded during the constructor of the assembly, which itself is loaded in the form load event of the main assembly.
# Austin
This is a standalone app that I am debugging in Visual Studio.
If you are recompiling the application between runs, note that it will consider that a new version of the app and will not automatically load per-user settings. You need to call Settings.Default.Upgrade in this situation.
One way to do this only when needed is to add a NeedsUpgrade setting (value True) to the application's default per-user settings. On app startup, check if NeedsUpgrade is true. If so, call Upgrade, set NeedsUpgrade to False, and save the settings. The next time the app version changes, NeedsUpgrade will reset to True and you'll auto-call Upgrade to bring in any existing user settings again.
Make sure you're setting NeedsUpgrade after calling Upgrade, or it will get wiped out when the settings are upgraded.
if (Settings.Default.NeedsUpgrade)
{
Settings.Default.Upgrade();
Settings.Default.NeedsUpgrade = false;
Settings.Default.Save();
}
This sounds like you're debugging the application from Visual Studio when every time you start a new session you start with the default data.
If you're seeing this with an installed release, then I would guess you're not actually using the string values when you think you are.
i have replaced windows shell with my application it worked perfectly, after closing my application i have to launch windows explorer with the following piece of code
Code to start explorer
Process.Start(#"c:\windows\explorer.exe");
Registry key i have used to replace shell
HKEY_Local_Machine\Software\Microsoft\WindowsNT\CurrentVersion\WinLogon\Shell
it doesnt show taskbar and start menu, it just shows mydocuments folder. I need start menu and taskbar while after explorer started
My guess is that since explorer isn't defined as the shell, it won't run as the shell. I think that you'd have to change the registry settings to make explorer the shell again before you run it.
So, as you wrote you replaced the shell in the registry with your own version. So it's up to you to show a start menu, etc. If you like to start a explorer and let it act as a shell, go on and replace the entry in the registry with the old one.
Due to the fact, that you like to be the shell again, next time windows starts, maybe the following trick will do it:
Prerequisities:
Place your program in registry as shell and start windows
Your program runs and wants to start explorer as shell
Action to to:
Replace entry in registry against entry containing explorer as shell
Start the explorer
Replace entry in registry back to your app as shell programm
Wait till next boot...
You will probably have to kill the existing shell process (i.e. your app) before starting explorer again.