0

I have created a simple weather application and I added the code below to let the user let it run on Startup:

RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (startupCheck.Checked) {
  rk.SetValue("WeTile", "\"" + Application.ExecutablePath.ToString() + "\"");
} else {
  rk.DeleteValue("WeTile", false);
}

Now this runs fine on both my computers. But when I gave the app to my girlfriend. She said the app does not run on windows start up. I read it online that it could be because of the user permission or the location so I told her to move the app to c:/ and try checking the box again and then restarting. Now it works but on every startup she has the default windows message saying you want to run this app?

How do I get rid of this? What is the best way to add to windows startup that works with both windows 32/64 bit without any user permission disruptions?

Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
Muhammad Ali
  • 3,478
  • 5
  • 19
  • 30

2 Answers2

1

It sounds like you may have run afoul of Windows' file blocking security function. Applications created on another computer are automatically blocked from executing unless the user specifically "unblocks" the file. Have your girlfriend right-click on the executable, select "Properties" and see if there is a button at the bottom of the dialog to unblock the file.

File properties dialog box showing 'unblock' button

Once unblocked, you should no longer see the confirmation prompt at startup.

jmbpiano
  • 561
  • 3
  • 19
  • 1
    That's inconvenient :/ Does everyone who downloads my app needs to do this? – Muhammad Ali Feb 27 '15 at 06:17
  • 1
    If you're distributing just the raw files or a zipped archive, then yes. If you're planning on distributing your app to a larger audience, I would recommend packaging your app into a signed installer and distributing that instead. Visual Studio has some deployment tools to help you do so, or you could check out [WiX](http://wixtoolset.org/). – jmbpiano Feb 27 '15 at 06:27
  • You are right I was giving out just the raw file, but my final plans are to distribute for a larger audience. So my question is that what difference does it make if I distribute with a singed installer? Also I've only been able to get a setup file of MSI in VS and it's not customizable... Did you mean publish app? – Muhammad Ali Feb 27 '15 at 07:03
  • 1
    When you use an installer, the individual application files no longer have to be unblocked to run. The installer itself has to be approved by the user when they run it, but that's a one time thing. Signing the installer with a trusted certificate streamlines some of the user interactions (particularly on Windows 8). – jmbpiano Feb 27 '15 at 16:12
  • 1
    I'll be honest, I haven't played much with the deployment features in VS. When I distribute internal apps to people in my company, I give them an MSI generated by WiX that is signed using a certificate issued by our company's root authority. This works out pretty smoothly for our users. If you want to distribute to the world at large, you would want to invest in a code-signing certificate issued from a public provider like Verisign or GoDaddy. – jmbpiano Feb 27 '15 at 16:23
  • Thank you for your information. I would also like to add that my antivirus (AVG) is trying to block my program in the PC I created and another PC. My program has some registry entries for windows Startup. Do you think this is because of registry or like you said the program needs to be installed? – Muhammad Ali Feb 27 '15 at 19:00
  • It's very possible you're tripping some of AVG's heuristics by creating those registry entries and using an installer could get around it, but I couldn't tell you for sure. Frankly, dealing with a false positive from AVG sounds like a big enough can of worms that I'd suggest you open up a new question for it. – jmbpiano Feb 27 '15 at 20:21
0

You could add it to the Windows startup folder, check if it's not there already and if not, add it (assuming this is what the user wants).

See How do I set a program to launch at startup

Community
  • 1
  • 1
Alex B
  • 1
  • Yeah I looked into it, but it bugs me, how other apps like Dolby Digital, Utorrent, f.lux are in the same registry directory and they are running fine. – Muhammad Ali Feb 27 '15 at 03:43