Windows – How to we run a logon script to mount drives UAC

batchmountuacwindows

We have a small environment where we are setting up mountable drives using a login.bat file, reason why we are doing this because our script first tests whether the folder is created for that user, and then if so makes a folder, then finally it mounts the drive.

Our issue is when we logon the script fails because it runs "net use" as an administrative account as this is default with UAC enabled. We investigated and found launchapp.wsf and information on Microsoft sites about this however these scripts are poorly written and have errors on the code.

We do not want to disable UAC and compromise security and we want to use a script because we want to test whether the folder exists, thus we cannot use GPO to mount a drive.

@echo off
net use h: /delete /yes
if not exist "\\domain.com\user\%username% mkdir "\\domain.com\user\%username%"
net use h: "\\domain.com\user\%username%
label h: HOME

TLDR: How do we make computers with UAC mount a drive through a login script as the local user rather than admin, what launchapp.wsf script variants worked for you?

Best Answer

This is what mine is (stored in \DomainController\SYSVOL\domain.local\scripts) Then, in the AD Users > Properties > Profile > Logon Script > login.bat This script adds Q R X P U and S volumes.

@Echo OFF

ECHO "Please Wait..."

REM net use /d Q:
NET USE Q: >nul
IF %ERRORLEVEL% NEQ 0 (net use q: \\hqfile01\Q)

REM net use /d R:
NET USE R: >nul
IF %ERRORLEVEL% NEQ 0 (net use R: \\hqfile02\Downloads)

REM net use /d X:
NET USE X: >nul
IF %ERRORLEVEL% NEQ 0 (net use X: \\hqfile01\Audio)

REM net use /d P:
NET USE P: >nul
IF %ERRORLEVEL% NEQ 0 (net use P: "\\hqfile02\CopierStore\%username%")

REM net use /d U:
NET USE U: >nul
IF %ERRORLEVEL% NEQ 0 (net use U: "\\hqfile01\Users\%username%")

REM net use /d S:
NET USE S: >nul
IF %ERRORLEVEL% NEQ 0 (net use S: \\hqfile02\Scratch)

:DONE

None of my users are admins and UAC is on. This works fine.