Mapping a drive based on system variable

Hello, we are running Windows 2003 on our terminal server. We have our users using terminal services to run an application on the server. We have their RDP session setup so that it launches a specific program when they connect to the server. Essentially, their RDP session is shelled out to this application. We would like it so that if these users RDP in to our terminal server, they get a specifc drive mapping. However we only want them to get the drive if they RDP into this server. We don't want them to get the drive if they are just logging in to a workstation. This client is using KIX32.exe to run their login scripts. In the script I have added the following statements so that when these users RDP to the server, they will get a new mapped drive. For some reason, these new statements are not mapping the drive. Any ideas on what the problem is would be greatly appreciated.

if %computername% == "server" (GOTO :true) ELSE Goto :False
net use J: /delete
net use J: \\server\directory
GOTO :end
Workstation not permitted J:\ mapping


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IF %PCNAME%==SERVER (blah blah blah)
The script you've posted is (mostly) a batch script, not a Kix script.
In batch, the correct version would be

if /i not "%ComputerName%"=="server" goto EndRDP
net use J: /delete
net use J: \\server\directory /persistent:no

The Kix version is here:

If @WkSta = "Server"
  Use J: /delete
  Use J: \\Server\Share

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StarfishTechAuthor Commented:
OK, I've updated my KIX script and it is half working. The old J:\ drive is being deleted but the new J:\ drive is not being mapped.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

StarfishTechAuthor Commented:
If I manually run the script, I see that it complains about line 45. Says it's an invalid expression. The expression on line 45 is:

Use J: \\el-shaddai\Cleveland_Foxpro
Add quotes around the share path:
Use J: "\\el-shaddai\Cleveland_Foxpro"
StarfishTechAuthor Commented:
Worked great! Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.