Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Bat file that gets username and inserts it into a share location


Recommended Posts

Posted

Hello,

 

i'm not really a scripting\coding person, I just put ticks in the right boxes all day ;)

 

So I was hoping someone could help me with something I am trying to do on a windows network, I have a server path: \\server\share\AUSER\files

 

Where the AUSER can be different users each with a folder in that location.

 

I want to create a mapped drive to that location, so can use net use D: \\blah...

 

but, is there a way I could get the %username% of the logged on user and insert that into the \\ path to replace AUSER before mapping it as:

 

\\server\share\NOAREALUSER1\files etc?

 

Any help appreciated

 

thank you.

Posted

Hello,

 

Thank you, but I need to find a way to insert the username into the middle of the path like: \\server\files\"unique username here"\files.

 

So i'm thinking, something that gets the %username%, then concatenate the path around the username, then use the new unique path for the net use bit...

Posted

The principle is the same

 

Net use d: "\\server\share\%username%\files\"

 

As far as I can remember at this time in the morning after a night out, this should work.

 

 

Sent from my iPad using EduGeek

Posted

Just to confirm the following string

 

%username% is the actual command used to retrieve that information about who the user is.

 

Just thought I'd clarify that.

 

 

Sent from my iPad using EduGeek

Posted

hi,

 

win 2008 r2

 

I had some luck creating separate variables and concatenating them together to form unique paths based on their %username%, this works for what I need, but I am sure there's smarter ways to do this.

 

thanks

Posted

2008R2, you can use Group Policy Preferences to do it ( User Config > Preferences > Windows Settings > Drive Maps). Use the %username% variable still to do something like:

Action: Update

Letter: D

Location: \\server\share\%username%\files

Label as: User Files

 

etc.

 

If you're not familiar with scripting it may be easier for you to read/diagnose issues going forward.

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



×
×
  • Create New...