Jump to content

Batch - Using Dual Variables


Recommended Posts

Hey all,

First of all, you guys are my lifeline and I want to thank you for all of your help in the past!

I am trying to map a network drive, depending on what domain they are on...

I can't figure out how to get the dual variable to work properly, here is what I have:

set D_Domain1=Server1
set D_Domain2=Server2
set D_Domain3=Server3
set Server=%D_%USERDNSDOMAIN%%
net use O: \\%Server%\Share

I know that the %'s are wrong and is what is causing my problem... but I don't know how to fix it.

%USERDNSDOMAIN% is the user's full domain name and I want to set %Server% as D_InsertUsersDomainHere but the Double %%'s are tripping me up.

Any Ideas?

Edited by twig123
Link to comment
Share on other sites


There may be other ways to solve this, but this was my first thought:


set D_Domain1=Server1
set D_Domain2=Server2
set D_Domain3=Server3

for /f "tokens=1,* delims==" %%a in ('set D_^|find /i "%USERDNSDOMAIN%"') do set Server=%%b
net use O: \\%Server%\Share

Link to comment
Share on other sites

If only I could understand what you are trying to do....

...Where is USERDNSDOMAIN defined?

:w00t:

However maybe this is the missing point, (alternate solution to the one already posted) enabling delayed expansion of variables and use the !var! syntax together with the %var% one, that allows for

!var1_%var2%!

SETLOCAL ENABLEDELAYEDEXPANSION

SET USERDNSDOMAIN=Domain2

set D_Domain1=Server1
set D_Domain2=Server2
set D_Domain3=Server3
set Server=!D_%USERDNSDOMAIN%!

SET Server
PAUSE
net use O: \\%Server%\Share

jaclaz

Link to comment
Share on other sites

%USERDNSDOMAIN% is a system wide variable that is set by windows if a computer is joined to a Domain.

I was trying to make a new variable out of 2 existing variables to grab the data that was contained within the 3rd variable. Both of your replies seem to accomplish this goal in different ways.

Thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...