Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
AnswerRe: c# Pin
Abhinav S9-Jun-13 21:49
Abhinav S9-Jun-13 21:49 
AnswerRe: c# Pin
bfis10813710-Jun-13 0:38
bfis10813710-Jun-13 0:38 
AnswerRe: c# Pin
OriginalGriff10-Jun-13 9:09
mveOriginalGriff10-Jun-13 9:09 
QuestionHow to deal with environment variables and non admin users Pin
bfis1081379-Jun-13 2:08
bfis1081379-Jun-13 2:08 
AnswerRe: How to deal with environment variables and non admin users Pin
Eddy Vluggen9-Jun-13 5:06
professionalEddy Vluggen9-Jun-13 5:06 
GeneralRe: How to deal with environment variables and non admin users Pin
bfis1081379-Jun-13 10:30
bfis1081379-Jun-13 10:30 
GeneralRe: How to deal with environment variables and non admin users Pin
Dave Kreskowiak9-Jun-13 13:00
mveDave Kreskowiak9-Jun-13 13:00 
GeneralRe: How to deal with environment variables and non admin users Pin
bfis1081379-Jun-13 20:25
bfis1081379-Jun-13 20:25 
Well it was a machine environment variable since the path was going to be the same across all users. And you are right Application.StartupPath does work correctly but here is where the problems started. I was using a dll. I wasn't using Application.StartupPath. I was just trying to get information out of a file so I wasn't even using a path. I was just doing something like

string someString = File.ReadAllText("FileName.txt");

When it would run normally (not at startup) then it would read and write to the folder where the app was. If it was run at startup however, it would read or write to the user's folder. I misspoke myself about the Application.StartupPath. I have been doing a lot of debugging and apparently that wasn't what happened but I assure you the issue I just presented did happen. The file with a dll is in c:\test. Here is the code. Now the first time it's run as expected there is a file called error.txt which says "Could not find file 'C:\test\test.txt'." The path.txt file and the test.txt files are as expected. However when it runs at startup, the time in the test.txt file doesn't change and when I look in the user folder, I see a new error.txt file along with a test.txt file. The error.txt file says "Could not find file 'C:\Documents and Settings\User\test.txt'." and the time in the test.txt file is more up to date. So again I misspoke before and I assure you it was accidental but and I have found a way to solve my problem but this was my situation. I hope you accept my apology.

A button and form load with the following code.
C#
private void Form1_Load(object sender, EventArgs e)
        {
            TestClass tc = new TestClass();
            tc.ReadFile();
            tc.WriteFile();          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = Application.StartupPath + @"\CurrentFolderTest.exe";
            RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            File.WriteAllText("path.txt", Application.StartupPath);
            key.SetValue("foldertest", path);
        }


Here is the code from the dll

C#
public void WriteFile()
        {
            File.WriteAllText("test.txt", DateTime.Now.ToLongTimeString() + DateTime.Now.Millisecond.ToString());
        }
        public void ReadFile()
        {
            try
            {
                string test = File.ReadAllText("test.txt");
            }
            catch (Exception ex)
            {
                File.WriteAllText("error.txt", ex.Message);
            }
        }

GeneralRe: How to deal with environment variables and non admin users Pin
Dave Kreskowiak10-Jun-13 1:21
mveDave Kreskowiak10-Jun-13 1:21 
QuestionCrystal report login popsup why? Pin
zakirox1238-Jun-13 20:52
zakirox1238-Jun-13 20:52 
AnswerRe: Crystal report login popsup why? Pin
OriginalGriff8-Jun-13 21:59
mveOriginalGriff8-Jun-13 21:59 
GeneralRe: Crystal report login popsup why? Pin
zakirox1238-Jun-13 22:20
zakirox1238-Jun-13 22:20 
AnswerRe: Crystal report login popsup why? Pin
Abhinav S9-Jun-13 5:18
Abhinav S9-Jun-13 5:18 
QuestionSAD_1969_UTM_Zone_23S to WGS84 Coordinate convertion using C# Pin
pvt_infotech7-Jun-13 22:57
pvt_infotech7-Jun-13 22:57 
AnswerRe: SAD_1969_UTM_Zone_23S to WGS84 Coordinate convertion using C# Pin
Bernhard Hiller11-Jun-13 0:05
Bernhard Hiller11-Jun-13 0:05 
QuestionHow to sort serial no in datagridview ,c# Pin
Member 30804707-Jun-13 21:34
Member 30804707-Jun-13 21:34 
AnswerRe: How to sort serial no in datagridview ,c# Pin
Abhinav S7-Jun-13 21:40
Abhinav S7-Jun-13 21:40 
QuestionHow to use product key in my windows application. Pin
ajjuvirgo7-Jun-13 20:04
ajjuvirgo7-Jun-13 20:04 
AnswerRe: How to use product key in my windows application. Pin
Abhinav S7-Jun-13 20:50
Abhinav S7-Jun-13 20:50 
QuestionHow to validate a text box in windows form application using c#. Pin
ajjuvirgo7-Jun-13 20:03
ajjuvirgo7-Jun-13 20:03 
AnswerRe: How to validate a text box in windows form application using c#. Pin
OriginalGriff7-Jun-13 20:18
mveOriginalGriff7-Jun-13 20:18 
AnswerRe: How to validate a text box in windows form application using c#. Pin
Abhinav S7-Jun-13 20:51
Abhinav S7-Jun-13 20:51 
QuestionDoes C# have similar interrupts as embedded C Pin
Member 100880257-Jun-13 13:41
Member 100880257-Jun-13 13:41 
AnswerRe: Does C# have similar interrupts as embedded C Pin
Dave Kreskowiak7-Jun-13 14:02
mveDave Kreskowiak7-Jun-13 14:02 
GeneralRe: Does C# have similar interrupts as embedded C Pin
Member 100880257-Jun-13 16:36
Member 100880257-Jun-13 16:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.