Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

Login script that changes based on a PC name

Hi,

I need to write a login script that looks at a range of PC names and skips a section in my script based on whether or not a PC name exists. Basically, I need to map a drive, but I only want to map that drive if the script is called from PCs named L4_01 to L4_32. I have another naming convention (L7) that use the same login names, and I need them to map seperate directories. any idea? also, are there any really difinitive resources on teh web for finding script examples?

Thanks,

Justin
0
woodsman707
Asked:
woodsman707
  • 2
  • 2
1 Solution
 
MSGeekCommented:
Sounds like you would be better off creating a group for your workstations, then through a group policy place the path to your script under logon script in the Logon/logoff section of the group policy.
0
 
oBdACommented:
Oh no, it's MSGeek with his group policy based logon scripts again ;).

Hi woodsman707,

you can put something like that that into your logon script:

=============8<------------------------------------------
@echo off
setlocal

rem ***************************************************************
rem *** Start mapping depending on computername:
for /f "tokens=1,2 delims=_" %%a in ("%ComputerName%") do (
  set Prefix=%%a
  set Number=%%b
)
if %Prefix%==L4 goto Map_L4
if %Prefix%==L7 goto Map_L7
goto Common

:Map_L4
if %Number% LSS 1 goto Common
if %Number% GTR 32 goto Common
rem *** Map the drive(s) for your L4_xx clients here:
echo net use L: \\server\l4share
goto Common

:Map_L7
if %Number% LSS 1 goto Common
if %Number% GTR 32 goto Common
rem *** Map the drive(s) for your L7_xx clients here:
echo net use L: \\server\l7share
goto Common

:Common
rem *** End mapping depending on computername
rem ***************************************************************
=============8<------------------------------------------

As for script examples, http://www.robvanderwoude.com/ has a nice collection.
0
 
oBdACommented:
Do I need to tell you to remove the "echo" in front of the "net use" command to arm the script? Probably not.
0
 
MSGeekCommented:
The shorter the login script the faster the login.  If you can apply a login script to a container instaed o f an entire organization, it makes things a bit more tidy.

oBda..  I do admire your scripting, I have added many to my knowledge base.
0
 
woodsman707Author Commented:
ok, I think I understand most of this. Thanks a lot, I appreciate it.

Justin
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now