B4J Question System Property user name

Discussion in 'B4J Questions' started by oldeast, May 22, 2019.

  1. oldeast

    oldeast Active Member Licensed User

    My new laptop, Win 10 now names the user folder with the first 5 letters of the email address so it does not match the user name and the program crashes.
    Dim username As String = GetSystemProperty("user.name""default")
                    fc.InitialDirectory =
    "C:\Users\" &username &"\Desktop"     ' Set starting folder
    so is it possible to look up the user folder name, rather than the user name..
  2. Daestrum

    Daestrum Well-Known Member Licensed User

    Your code works fine here, it opens the filechooser pointing at the desktop folder.
  3. oldeast

    oldeast Active Member Licensed User

    Yes it worked fine on my old laptop,because the user (account) name matches the user folder name,
    If you get a new computer Windows changed it so now the user name is not used for the user folder name , it uses the first five letter of your email address so the code fails.
    To make the code work I need to find the user folder name not the user name.
  4. Erel

    Erel Administrator Staff Member Licensed User

    1. Where is the error message?
    2. What are you trying to do? Why do you need this specific folder?
  5. oldeast

    oldeast Active Member Licensed User

    Thaks Erel,
    I wanted to start the browse on the desktop to assist the user..
    After the user.name didn't match the named folder C:/user/username its stopped working.
    I fixed it by creating a new user.
  6. DarkMann

    DarkMann Member Licensed User

    Just a quick thought to throw a spanner in the machine.

    Windows doesn't maintain the link between the user's chosen username - as displayed when the log on - and the name of the folder.

    When you first create a Local account, the folder name will probably be the same as the username. If the user subsequently changes their username, then the folder will not change and they won't match.

    If you start from a Microsoft account login, then this will be something similar to what you describe - part of the account name (email address) will be used to create the folder name and this also will then never change.

    If you want to access the Desktop of the current user then you'll need to start from the %HOMEPATH% system variable in windows.

    DonManfred likes this.
  7. oldeast

    oldeast Active Member Licensed User

    Thanks David, that's what i want to do, so if a user changes an account name the program won't be affected.
    I will use that solution in the distributed version.
  8. sorex

    sorex Expert Licensed User

    %userprofile% is actually the right one. %homepath% will fail when you don't run the jar file on the system drive.

    type SET in a dosbox for all the stuff you can access. some extra things can be fetched via vbscript.
  9. oldeast

    oldeast Active Member Licensed User

    thanks Sorex, ..i will try to use that ..can you give me a heads up on using it in fie chooser please
  10. sorex

    sorex Expert Licensed User

    this seems to work

    Log( GetSystemProperty("user.home""c:\") )
    which reads out that user profile variable
  11. oldeast

    oldeast Active Member Licensed User

    thanks, much appreciated..
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice