Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 

Sign in to follow this  
SilverBulletUK

Username in Batch File?

Recommended Posts

Hey guys,

Need your guidance yet again :wacko: ...!!

Im trying to make a batch file to make a folder named after the user who is logged onto the computer at the time.....

Little explanation......

@echo off
SYSINFO.BAT >> C:\Logs\***username here***\Output.txt
Exit

how could i set the variable needed to replace "***username here***" is this even possible, forgive me this is really simple but its late!!! :}

Does this make any sense?

Share this post


Link to post
Share on other sites

Ah ha!

Cheers Fella!! :D

%USERNAME% Worked........Now ive just got to figure out how to make the following Directory Structure...

%username%\%DATE%\%TIME%\

And yes....ive tried the above Vars :P Ideas...?

Share this post


Link to post
Share on other sites
SiMoNsAyS    0

mmm problem is that the simbols used for date and time ("\", "/", ":") can not be used to create the folder...

maybe sending the strings to a .txt file... dunno :unsure:

Share this post


Link to post
Share on other sites

Ahhhh,

Explains why when I try i get %username%\Logs\25\01\05\

Intresting theory you get there.....but how to get rid of the "\" in the output.....

Guess im off to google for a few more hours...! :D

Share this post


Link to post
Share on other sites

This Makes A Folder Based On The Current Date

@echo off
cls
color F2
mode con: Cols=55 Lines=3
Title What Year Is It Test 2
SET D1=%date:~-4,10%
SET D2=%date:~7,-5%
SET D3=%date:~4,-8%
SET D4=%date:~0,-10%
echo.
@echo The Year Is %D1%
ping -n 3 127.0.0.1>nul
cls
echo.
@echo Today Date %D2%
ping -n 3 127.0.0.1>nul
cls
echo.
@echo The Month %D3%
ping -n 3 127.0.0.1>nul
cls
echo.
@echo The Day %D4%
ping -n 3 127.0.0.1>nul

if exist %D3%-%D2%-%D1% goto E1
if not exist %D3%-%D2%-%D1% goto W1

:W1
mkdir %D3%-%D2%-%D1%
echo.
echo Folder %D3%-%D2%-%D1% Was Made!
ping -n 3 127.0.0.1>nul
exit

:e1
echo.
echo Folder Was Already Made!
ping -n 3 127.0.0.1>nul

The Folder Named Would Be 02-07-2005 or The Day

It Was ran On

Adjust To your Needs

Edited by gunsmokingman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×