0

I'm searching to get back the String on the red block. The red block is the string

I already tried the following code:

Environment.UserName
My.User.Name
SystemInformation.UserName
System.Security.Principal.WindowsIdentity.GetCurrent().Name
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Environment.GetFolderPath(Environment.GetEnvironmentVariable("%USERNAME%"))

But this code don't work, because the computer of my company uses a domain, and the String that I need is different as the user. The user is composed only by the name, and the string is composed by the name and the first name of the employees.

4
  • Is this what you are looking for? msdn.microsoft.com/library/ts4s4536(v=vs.100).aspx Commented Dec 15, 2015 at 11:18
  • No, this one give me only the user, i already tried this one too, but thank you Commented Dec 15, 2015 at 11:21
  • What about just Environment.GetEnvironmentVariable("%USERNAME%") Commented Dec 15, 2015 at 11:43
  • Environment.GetEnvironmentVariable("%USERNAME%") give me a empty String Commented Dec 15, 2015 at 11:46

2 Answers 2

1

I finally found what I need here

We have to import that :

“System.DirectoryServices.AccountManagement”
“System.DirectoryServices”

And write this two lines to get back the red block.

Dim currentADUser As System.DirectoryServices.AccountManagement.UserPrincipal
currentADUser = System.DirectoryServices.AccountManagement.UserPrincipal.Current
Sign up to request clarification or add additional context in comments.

Comments

0

You can try using either

HttpContext.Current.Server.MachineName

or

System.Environment.MachineName;

5 Comments

That give me the Computer name, i don't need it, I need to get the red block on the photo. And I think is a Windows vairiable like %USERNAME%, but I can't find it.
From the ComputerName, You'll have to construct the complete path. That's the way it works. Or are you looking to read the path of a file?
I don't need the path, I just need the string in the red block. I've to open a excel-file who is called like this red block.
Isn't that the MachineName?
No, press your Windows button, click on the user and you get the the same window as the photo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.