B4J Question System Property user name

oldeast

Active Member
Licensed User
Longtime 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.
B4X:
Dim username As String = GetSystemProperty("user.name", "default")
                Log(username)
                fc.Initialize                        
                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..
thanks
 

Daestrum

Expert
Licensed User
Longtime User
Your code works fine here, it opens the filechooser pointing at the desktop folder.
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime 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.
Thanks
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime 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.
Thanks
 
Upvote 0

DarkMann

Member
Licensed User
Longtime 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.

David
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime 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.
Graham
 
Upvote 0

sorex

Expert
Licensed User
Longtime 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.
 
Upvote 0

oldeast

Active Member
Licensed User
Longtime User
thanks Sorex, ..i will try to use that ..can you give me a heads up on using it in fie chooser please
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
this seems to work

B4X:
Log( GetSystemProperty("user.home", "c:\") )

which reads out that user profile variable
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…