I have a batch file that I'm configuring to check if the user whose logged in is a specific user or not. No matter what I do the batch file always crashes on the ) ELSE ( line. I've spent five hours on this and I've definitely shrunk and improved the commands over what they were, but it's still not working. I'd appreciate any suggestions on how I can get it to work (also, if I'm doing plainly stupid, let me know, I'm kind of a dummy when it comes to batch files):
@ECHO OFF
::
SETLOCAL
::
IF "%USERNAME%" EQU "jdoe" (
IMDISK -a -s 32M -m #: -p "/FS:exFAT /Q /Y /V:MERGEABLES"
FOR /F "tokens=2 delims==" %%D IN ('WMIC LOGICALDISK WHERE "size=33538048" GET Name /format:value'^) DO (
COPY "\\WIN2K8R2-F-01\Remote Applications\Batches\Merge PDFs.lnk" "%%D\Merge PDFs.lnk"
GOTO End
^)
) ELSE (
IMDISK -a -s 256M -m #: -p "/FS:exFAT /Q /Y /V:RAMDRIVE"
FOR /F "tokens=2 delims==" %%D IN ('WMIC LOGICALDISK WHERE "size=268304384" GET Name /format:value'^) DO (
COPY "\\WIN2K8R2-F-01\Remote Applications\Batches\Archive Folders.lnk" "%%D\Archive Folders.lnk"
GOTO End
^)
)
::
:End
::
IF EXIST "%SystemDrive%\BGInfo.exe" (
"%SystemDrive%\BGInfo.exe" "%SystemDrive%\BGInfo.bgi" /Timer:0 /AcceptEula /Silent
)
::
ENDLOCAL
UPDATE
So, I rewrote my version and honestly I don't see much difference between my original and the rewrite, but the rewrite worked. However, in the end I can't use this script because of one issue courtesy of Microsoft. The issue is that normal users are not allowed to format drives. That throws IMDISK out the window and now I'll have to mess with hidden folders and shortcuts, etc. RUNAS doesn't help and I couldn't get it to work anyway. I'm pretty sure I messed it up, but I don't see the point in pursuing a fix anymore. For anyone who cares, here's the final version of the script. Maybe it will help someone else:
@ECHO OFF
::
IF /I "%USERNAME%" EQU "jdoe" (
IMDISK -a -s 32M -m #: -p "/FS:exFAT /Q /Y /V:MERGEABLES"
::
TIMEOUT 4
::
FOR /F "tokens=2 delims==" %%D IN (
'WMIC LOGICALDISK WHERE "size=33423360" GET Name /format:value'
) DO (
PUSHD %%D
::
COPY "\\WIN2K8R2-F-01\Remote Applications\Batches\Merge PDFs.lnk" "Merge PDFs.lnk"
::
POPD
::
GOTO End
)
) ELSE (
IMDISK -a -s 256M -m #: -p "/FS:exFAT /Q /Y /V:RAMDRIVE"
::
TIMEOUT 4
::
FOR /F "tokens=2 delims==" %%D IN (
'WMIC LOGICALDISK WHERE "size=268304384" GET Name /format:value'
) DO (
PUSHD %%D
::
COPY "\\WIN2K8R2-F-01\Remote Applications\Batches\Archive Folders.lnk" "Archive Folders.lnk"
::
POPD
::
GOTO End
)
)
::
:End
::
IF EXIST "%SystemDrive%\BGInfo.exe" (
"%SystemDrive%\BGInfo.exe" "%SystemDrive%\BGInfo.bgi" /Timer:0 /AcceptEula /Silent
)
One thing I couldn't figure out is how to pass the %%D variable from the loop directly to the COPY command. That's why I'm using PUSHD and POPD, but that just feels dirty...
SETLOCAL ENABLEDELAYEDEXPANSIONinstead of justSETLOCAL. I don't know if it will work though.