Click here to Skip to main content
15,922,427 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need help regarding developing windows service Pin
Rob Philpott10-Jun-13 10:09
Rob Philpott10-Jun-13 10:09 
AnswerRe: Need help regarding developing windows service Pin
Abhinav S10-Jun-13 20:15
Abhinav S10-Jun-13 20:15 
QuestionHow to draw 3D electron model around Atom using XNA?? Pin
nada 101510-Jun-13 0:59
nada 101510-Jun-13 0:59 
AnswerRe: How to draw 3D electron model around Atom using XNA?? Pin
Richard MacCutchan10-Jun-13 1:48
mveRichard MacCutchan10-Jun-13 1:48 
GeneralRe: How to draw 3D electron model around Atom using XNA?? Pin
nada 101510-Jun-13 1:54
nada 101510-Jun-13 1:54 
GeneralRe: How to draw 3D electron model around Atom using XNA?? Pin
Richard MacCutchan10-Jun-13 2:02
mveRichard MacCutchan10-Jun-13 2:02 
GeneralhI How Can i Expand Window? Pin
SgtSS9-Jun-13 23:41
SgtSS9-Jun-13 23:41 
AnswerRe: hI How Can i Expand Window? Pin
Abhinav S10-Jun-13 0:06
Abhinav S10-Jun-13 0:06 
GeneralRe: hI How Can i Expand Window? Pin
SgtSS10-Jun-13 14:31
SgtSS10-Jun-13 14:31 
QuestionRun RegisterStartupScript multiple times in c# Pin
Jun Xian9-Jun-13 22:05
Jun Xian9-Jun-13 22:05 
Questionstuck in (dll registration in system32 by c#) Pin
Sneha Bisht9-Jun-13 21:01
Sneha Bisht9-Jun-13 21:01 
AnswerRe: stuck in (dll registration in system32 by c#) Pin
Abhinav S9-Jun-13 21:47
Abhinav S9-Jun-13 21:47 
AnswerRe: stuck in (dll registration in system32 by c#) Pin
Dave Kreskowiak10-Jun-13 1:34
mveDave Kreskowiak10-Jun-13 1:34 
Questionc# Pin
zofi519-Jun-13 20:16
zofi519-Jun-13 20:16 
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 

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.