locked
Pass username variable in URL RRS feed

  • Question

  • Hello,

     

    I need to create a url link on each computer. I have to set the url www.url.com/username . Username have to be the username of the windows session.

     

    Do you know how can i do this ?

     

    Thank you for your help.

     

    Marc

    Friday, March 4, 2011 2:19 PM

Answers

  • Depending on the environment (where you are using this), %username% might work. Otherwise, we detail on what you are doing.

     


    Richard Mueller - MVP Directory Services
    • Marked as answer by IamMred Tuesday, March 15, 2011 8:04 PM
    Saturday, March 12, 2011 2:37 AM
  • I did this once with PowerShell and used something like this:

    $un = $env:%unsername%

    $URL = "http://URL.com/$un"

     If you use double quotes PS will recognize the variable. If you use single quotes you will get the variable name in $URL.

    If you need to actually go to the webpage, then pass it to the System.Net.WebClient class (info here) or pass to IE with a "iexplore $URL".

    If you are just trying to create a Shortcut on the desktop of the machines after someone logs in, I would build a logon script that grabs the username and uses it to build a shorcut which is then saved to their desktop. You would access the desktop by calling C:\Documents and Settings\%username%\Desktop. Or if you use roaming profiles you would just create the url once and copy it to everybody's home directory desktop (so long as their not logged in at the time).

    Here's a link to the $env variable types in PowerShell.

    As you can see, there are a lot of possibilities here.

    Are you trying to create a shortcut for every user that they can click on to access this URL? Are you trying to access this webpage at each logon? Or is it something completely different?

    • Marked as answer by IamMred Tuesday, March 15, 2011 8:04 PM
    Sunday, March 13, 2011 6:10 AM

All replies

  • UserName = CreateObject( "WScript.NetWork" ).UserName
    • Marked as answer by Bill_Stewart Friday, March 4, 2011 5:48 PM
    • Unmarked as answer by Marc3k Friday, March 4, 2011 7:11 PM
    Friday, March 4, 2011 2:29 PM
  • Why do you put this answer as as solution?
    Friday, March 4, 2011 7:10 PM
  • I don't want to use a script to make a url to a website. DO you know if there is other possibility?
    Friday, March 4, 2011 7:11 PM
  • Hi,

    Why do you put this answer as as solution?

    Because that is how you get the logon user name in a script.

    I don't want to use a script to make a url to a website.

    (?) This is a scripting forum. If you don't want a script answer, perhaps ask somewhere else?

    Bill

    Friday, March 4, 2011 7:16 PM
  • Variable can be use without a scripts.
    Friday, March 4, 2011 8:27 PM
  • ?

    Bill

    Friday, March 4, 2011 8:40 PM
  • Depending on the environment (where you are using this), %username% might work. Otherwise, we detail on what you are doing.

     


    Richard Mueller - MVP Directory Services
    • Marked as answer by IamMred Tuesday, March 15, 2011 8:04 PM
    Saturday, March 12, 2011 2:37 AM
  • I did this once with PowerShell and used something like this:

    $un = $env:%unsername%

    $URL = "http://URL.com/$un"

     If you use double quotes PS will recognize the variable. If you use single quotes you will get the variable name in $URL.

    If you need to actually go to the webpage, then pass it to the System.Net.WebClient class (info here) or pass to IE with a "iexplore $URL".

    If you are just trying to create a Shortcut on the desktop of the machines after someone logs in, I would build a logon script that grabs the username and uses it to build a shorcut which is then saved to their desktop. You would access the desktop by calling C:\Documents and Settings\%username%\Desktop. Or if you use roaming profiles you would just create the url once and copy it to everybody's home directory desktop (so long as their not logged in at the time).

    Here's a link to the $env variable types in PowerShell.

    As you can see, there are a lot of possibilities here.

    Are you trying to create a shortcut for every user that they can click on to access this URL? Are you trying to access this webpage at each logon? Or is it something completely different?

    • Marked as answer by IamMred Tuesday, March 15, 2011 8:04 PM
    Sunday, March 13, 2011 6:10 AM
  • Thanks HonoSA.


    Your solution works perfectly.

     

    Marc

    Friday, March 25, 2011 12:15 PM