Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access username from the command line? 1

Status
Not open for further replies.

MISMCSA

MIS
Jun 24, 2004
43
US
From the command line, how do I enter the username of a user logged on to the system?

Example: c:\Robocopy c:\Documents and Settings\ & Username & \Documents /MIR

What do I plug in for user name?

I know the location of the username is HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name
 
At the command line, type 'set'. This will show you the Environment variables for your session. one of them should be 'USERNAME' and should hold the username. To execute the command line above do this:
c:\Robocopy c:\Documents and Settings\%USERNAME%\Documents /MIR

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for that, it was helpful. I'm still working on getting it to fully function, but I know that helped.

I'm running Robocopy of a server, so I need to call it from my vbscript and then have it execute a command like the one above. This is how I have attempted to call the exe from the server.

WShell.run("CMD /C md \\mmsfile5\global\SECURED\Hotline\Robocopy.exe C:\Test d:\Test /MIR"),1 , True

How do I execute the command?

 
It looks like you have two commands in there:
WShell.run("CMD /C [red]md[/red] [blue]\\mmsfile5\global\SECURED\Hotline\Robocopy.exe C:\Test d:\Test /MIR[/blue]"),1 , True

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I removed the md as suggest and it worked. Thanks again.
 
And what about this ?
WShell.Run "\\mmsfile5\global\SECURED\Hotline\Robocopy.exe C:\Test d:\Test /MIR",1 , True
avoiding an unnecessary instance of cmd.exe as you don't use I/O redirection.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes, the worked also. Thanks.

Why exactly did I not need to use that? What would you use "CMD /C" for?

And for that matter I really don't know what the "1, True" does either. I did not use it and it still worked.

Thanks for your help.
 
Why exactly did I not need to use that? What would you use "CMD /C" for?
Open a command prompt and type 'help cmd' and you will get the answer to this.

And for that matter I really don't know what the "1, True" does either.
Open the Windows Script Host help and search for 'run' and it will answer this one.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
During logon Windows NT, 2000, XP, 2003 have the username declared as a SET variable and those are stored in the resistry.

By default, Windows 95/98/98se/Me do not have the username declared as a SET variable. Probably stems from the fact that (1) you can bypass Winows logon anyway and (2) it was targeted from home use only. The username, though, is found in various locations in the registry. (I found that out when I was in the DOS window and trying to locate and copy the logon username from the DOS prompt but it was far to complicated or difficult to get a value to persist into other DOS windows in the same log session, so I moved on.) If you try to create USERNAME in a DOS windows in these older environments, that SET variable does not populate to other DOS windows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top