Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:56:46+00:00 2026-05-25T13:56:46+00:00

I have written a wrapper application in .Net that starts another WinForms application with

  • 0

I have written a wrapper application in .Net that starts another WinForms application with a specified user name and password. For the background behind why I am needing to do this, you can look at the following question that I posted earlier this week:

How to secure a network folder containing an Access database, while still allowing a WinForms application to connect to the database

Here is the code for the wrapper application:

string sysFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = (sysFolder + @"\AppMain.exe").Replace(@"file:\",  @"\\");
pInfo.UserName = GetUserName();
pInfo.Password = ToSecure(GetPassword());
pInfo.UseShellExecute = false;
Process p = Process.Start(pInfo);
p.WaitForExit();

The methods GetUserName() and GetPassword() simply retrieve the user name and password from an encrypted text file. The method ToSecure() just converts a String to a System.Security.SecureString.

Ok. Now here is the weird part! 🙂 This wrapper application actually works correctly MOST of the time; but for some strange reason it seems to run into a problem right after a system restart. After a restart, for about 5 minutes the application that is being launched (AppMain.exe), throws a UnauthorizedAccessException when the application tries to write to the windows registry. I have no idea why this is only going wrong in the first 5 minutes and then suddenly starts working correctly.

Note also that I have to close the application and restart it after five minutes into the boot for it to work correctly. If I just press “continue” on the expection, it keeps giving the execption when attempting to write to the registry.

Here is the code that will throw the exception when the application is started after a reboot.

Microsoft.VisualBasic.Interaction.SaveSetting("app", "settings", "time", DateTime.Now.ToString());

I have confirmed this behaviour on XP and on Windows 7. Anyone have any idea why this is happening at startup and why the exception suddenly goes away if I launch the application after 5 minutes into the boot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:56:47+00:00Added an answer on May 25, 2026 at 1:56 pm

    I have finally discovered what is causing this problem. I found the answer here:

    http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.loaduserprofile.aspx

    ProcessStartInfo.LoadUserProfile was the missing piece to the puzzle. In the process information object there is a property LoadUserProfile which indicates if the user’s profile must be loaded, and the default value for this property is false. But if the process that you are calling is needing to access HKEY_CURRENT_USER as my called process was trying to do, then this property must be set to true.

    So once I set LoadUserProfile to true in pInfo then my application worked 100%, even directly after a restart.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some written a number of unit tests that test a wrapper around
I have written an AIR Application that downloads videos and documents from a server.
I have written some code in my VB.NET application to send an HTML e-mail
I have a database winforms application using SQLite written in C#. I'm attempting to
I have written a small wrapper for the dict built-in class that loads entries
Summary I have written an Excel wrapper in .NET using Visual Basic and Visual
I have written a DLL that uses MS Word to spell check the content
I have written something that uses the following includes: #include <math.h> #include <time.h> #include
I have written a watir script that downloads files. One of the files it
Scenario I've written a WMI Wrapper that seems to be quite sufficient, however whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.