HKCU and HKLM/.../Run not running .Net apps

M

Mark

I've had a problem with getting a small c# app that I've written to run at a
particular user login on XP. I've added a reference to it into the registry
locations:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (first
attempt)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run (second
attempt)

Basically, it doesn't run! Other apps in the same keys run without problems.
So, I decided to pare-down the code to see if it was something I'd coded.
Eventually, I ended up with this:

namespace WindowsApplication1
{
public class Thing : System.Windows.Forms.Form
{
public Thing()
{
}

static void Main()
{
// while(true) {}
System.Diagnostics.EventLog.WriteEntry("Test", "Testing...");
}
}
}

Still, the app doesn't run at login. I've uncommented the infinite loop to
see if it was running but just not logging anything (crude but effective!).
Still nothing (i.e. no 100% CPUI activity). There are no errors in any of
the event logs. What I do know is:

- It works fine on a Win 2000 box
- I've only tested it on one XP Pro box as that's all I have access to so
perhaps it's just my PC? (I have all the latest patches etc.)
- The .Net version is 1.1
- I've had a look on the newsgroups and the MS web site but could find
anything there about this.
- I don't know if it's C# only as I don't have VB.net to try it on!

Am I missing something obvious here (as in perhaps it's well-known that .Net
apps can't be added to autorun at logon)?

TIA
Mark
 
M

Mark

Fixed! Might be a bug or combination of bugs? See below...

Mark said:
I've had a problem with getting a small c# app that I've written to run at a
particular user login on XP. I've added a reference to it into the registry
locations:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (first
attempt)
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run (second
attempt)

Basically, it doesn't run! Other apps in the same keys run without problems.
So, I decided to pare-down the code to see if it was something I'd coded.
Eventually, I ended up with this:

namespace WindowsApplication1
{
public class Thing : System.Windows.Forms.Form
{
public Thing()
{
}

static void Main()
{
// while(true) {}
System.Diagnostics.EventLog.WriteEntry("Test", "Testing...");
}
}
}

Still, the app doesn't run at login. I've uncommented the infinite loop to
see if it was running but just not logging anything (crude but effective!).
Still nothing (i.e. no 100% CPUI activity). There are no errors in any of
the event logs. What I do know is:

- It works fine on a Win 2000 box

When I looked _really_ carefully, I noticed that the command in the registry
was:
"path to myapp.exe"<space>

Note the single space _after_ the final quote (not visible in regedit.exe).
Win2K doesn't seem to mind this space, but XP ignores the line. Is this an
XP bug?

Now the strange thing is that I'm using Environment.Commandline to get the
executable. It is Environment.Commandline that is adding the space to the
end of the command line, but only when the executable is run outside of
Visual Studio. Weird! So, if you're debugging an app in VS, the
Environment.Commandline shows exactly what you'd expect, but if you run your
exe normally, you'll get a space at the end.

Workaround: Always use Environment.Commandline.TimeEnd() instead and it'll
bite off the mischevous trailing space! Is this a .Net framework bug or a
Vis Studio bug?

[snip]
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top