Solved Application to multiple usernames

July 15, 2012 at 11:39:42
Specs: Windows XP
I need help with making a program in Visual Basic 10 (Regular kind, not .net or script) that works for anyone. So far, I made a program able to play games on it and I added a feature called "DOWNLOAD" (download basically copies from a directory to the user's directory. In other words, by clicking download, I have an action that copies a folder with everything in it inside the computer (it is stored in a folder accessible to anyone), to the person's desktop. The problem is that there are hundreds of users on that computer so I would have to write all day...
My.Computer.FileSystem.CopyDirectory("C:\test", "C:\Documents and Settings\Joey\Desktop\Games", True)
My.Computer.FileSystem.CopyDirectory("C:\test", "C:\Documents and Settings\Bob\Desktop\Games", True)

because if a user named bob viewed my application, then it would not work for him since it says Documents and Settings\JOEY\ and not Documents and Settings\BOB\

How can I make one code that will include anyone who opens the application?
If you ever downloaded something from the internet, you'll notice that when you install it, the product "KNOWS" where to go (somehow it always goes to Program Files no matter who is viewing it) .
How can I do the same???
Please write back ASAP since I need this right away!!!!!!!!!

See More: Application to multiple usernames

Report •

July 15, 2012 at 11:47:55
✔ Best Answer
This is similar to one of your other questions. Use the Environ("USERNAME") function to get the user's name and then string concatenation to build the directory name.

Report •

July 15, 2012 at 13:09:21
I don't really understand what you mean by "and then string concatenation to build the directory name." So how would I be able to "string" them together? Suppose there are 3 users, bob, joey, and frank. Can you please give me an example, or some code of how this would work.

Report •

July 15, 2012 at 13:42:55
You use the operator & to join strings. So you do something like:

Name = "C:\Documents and settings\" & Environ(”USERNAME”) & "\Desktop\Games"

Then you do:

CopyDirectory("C:\Test", Name)

I haven't actually verified this as I don't have VisualBasic, but I hope you get the idea and can adapt it accordingly. Basically you are dynamically creating the string for the target of the copy operation.

Report •

Related Solutions

July 15, 2012 at 14:02:06
Thank you very much! You were right!

Report •

July 15, 2012 at 14:27:31
Don't hard-code "C:\Documents and settings\". For one, there's no guarantee that directory is correct. For another, it's guaranteed to be incorrect for Vista, Win7, and any non-English install of every version of Windows.

joey.hi: Visual Basic 10 (Regular kind, not .net or script)
VB10 is VB.NET.

How To Ask Questions The Smart Way

Report •

July 15, 2012 at 23:38:01
That's very true. The directory may not even be on the C: drive. More portable would be to use


To retrieve the user's home directory. So you would do

Name = Environ("USERPROFILE") & "\Desktop\Games"

Report •

Ask Question