exe c++ boot at windows start but not working, run manually it works
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: exe c++ boot at windows start but not working, run manually it works

  1. #1
    Join Date
    Dec 2010
    Posts
    2

    exe c++ boot at windows start but not working, run manually it works

    Hello,
    I created a small application in C + + with Visual C++ 2010 Express. No error message.
    - Started manually: everything is OK (it wrote a text in a txt file)
    - To run this application at start of windows, I created a key regedit (HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run), the program starts without problems (I see it in task manager) but it does not work, the text file is not written !!!!!
    Where is the problem?
    A parameter in the project properties in vc++?
    Thank!

    Here is the code:

    #include <fstream>
    #include <windows.h>

    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    static std:fstream g_log("log2.txt");
    g_log << "message" << std::endl;
    Sleep(INFINITE);
    return 0;
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,611

    Re: exe c++ boot at windows start but not working, run manually it works

    Quote Originally Posted by rv2010 View Post
    - To run this application at start of windows, I created a key regedit (HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run), the program starts without problems
    Try to move it from HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER. It looks like your App is started too early: before your user profile will be loaded.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: exe c++ boot at windows start but not working, run manually it works

    Hi,

    You should specify a full path name to the file you want to open.
    Try calling GetCurrentDirectory and see if it's the same.

    With regards
    Programartist

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,100

    Re: exe c++ boot at windows start but not working, run manually it works

    Where do you expect this log2.txt to be made ?

    Without a path, it'll be in the current directory.
    Which for boot time is the windows directory as far as I know.
    UAC prevents write access in the windows directory.

    Try putting a full path to where you want the file to be made.

  5. #5
    Join Date
    Dec 2010
    Posts
    2

    Re: exe c++ boot at windows start but not working, run manually it works

    it was indeed a problem of relative path, I put it in absolute and it works now.
    Thank you for your answers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center