Saturday, August 10, 2013

Local Login Network Map Script

@echo off
cls

rem This script checks to see if the user has access to a particular share
rem Then maps that share to a drive letter.

rem it is placed in the
rem "\\storage2\logon\#Login Script" folder.
rem all users need to have rights to this folder or it will not work

rem you would place a cmd scrip in
rem "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" folder
rem so it runs for all users that login.
rem with this command
rem start "Check Network Share Access" /min "\\storage2\logon\#Login Script\CheckMaps.cmd"

setlocal ENABLEDELAYEDEXPANSION
setlocal ENABLEEXTENSIONS

Title Checking and Creating Maps to network shares.
Echo Checking access and creating drive mappings to the network shares.

rem backing up existing maps to the users desktop
net use >>"%HOMEDRIVE%%HOMEPATH%\desktop\oldmaps.txt"
net use /PERSISTENT:no>nul

echo F>%temp%\letters
echo G>>%temp%\letters
echo I>>%temp%\letters
echo N>>%temp%\letters
echo S>>%temp%\letters
echo T>>%temp%\letters
echo X>>%temp%\letters

for /f %%a in (%temp%\letters) do (
    net use|find /i "%%a:">nul
    if !errorlevel! EQU 0 net use %%a: /delete>nul
    net use|find /i "%%a:">nul
    if !errorlevel! GTR 0 Call :map_%%a
)

endlocal
if exist "%temp%\letters" del "%temp%\letters"
exit
goto end

:map_S
:sales
if exist \\storage2\Sales\. net use s: \\storage2\Sales>nul
copy S:\primenxt\Primenext.lnk "%HOMEDRIVE%%HOMEPATH%\desktop\Primenext.lnk">nul
goto end

:map_X
:engineering
if exist \\storage2\Engineering\. net use x: \\storage2\Engineering>nul
goto end

:map_F
:finance
if exist \\storage2\Finance\. net use f: \\storage2\Finance>nul
goto end

:map_T
:traffic
if exist \\storage2\traffic\. net use t: \\storage2\traffic>nul
goto end

:map_G
:cs
if exist "\\storage2\Creative Services\." net use g: "\\storage2\Creative Services">nul
goto end

:map_N
:news
if exist \\storage2\News\. net use n: \\storage2\News>nul
goto end


:map_I
:IFS
rem This one randomly maps to a cluster of servers
set /a ip=%random% %% 6 +89
start "Random IFS Share Map" /b net use I: \\163.193.136.%ip%\ifs 1>nul 2>nul

GOTO END
:end