@subst

samintz

Scott Mintz
May 20, 2008
1,313
11
Solon, OH, USA
#1
Here is a simple function to tell if a drive has been subst'ed. It works akin to @cdrom and @remote.
Code:
[C:\] function subst=`%@if[%@index["%@winapi[kernel32.dll,QueryDosDeviceW,"%1",BUFFER,1024]",\??\] != -1,1,0]`

[C:\] echo %@subst[c:]
0

[C:\] echo %@subst[p:]
1
 
May 20, 2008
457
2
#2
Here is a simple function to tell if a drive has been subst'ed. It works akin to @cdrom and @remote.
Code:
[C:\] function subst=`%@if[%@index["%@winapi[kernel32.dll,QueryDosDeviceW,"%1",BUFFER,1024]",\??\] != -1,1,0]`

[C:\] echo %@subst[c:]
0

[C:\] echo %@subst[p:]
1
Another, simpler option for this may be to compare the results of @truename with the @subst arg.
 

samintz

Scott Mintz
May 20, 2008
1,313
11
Solon, OH, USA
#4
I forgot about that. Well, in keeping with my Persistent Subst command, I'll rename it to @psubst and add in support for whether a drive is SUBST'ed, Persistently SUBST'ed, or neither.
IsSubst.btm
Code:
@echo off
iff %@index["%@winapi[kernel32.dll,QueryDosDeviceW,"%1",BUFFER,1024]",\??\] != -1 then
    iff %@regquery["HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices\%1"] != -1 then
        echos 2
    else
        echos 1
    endiff
else
    echos 0
endiff
and the new function is:
Code:
function psubst=`%@execstr[IsSubst.btm %1]`
echo %@psubst[c:] %@psubst[p:] %@psubst[y:]
0 2 1
 
#5
Scott, do you use persistent SUBSTs? And do they give you any problems? I used them for a while after discovering the technique but backed off trying to solve a problem (XPS writer not working on one machine). That turned out to be unrelated to the SUBSTs (owner of %TEMP was from a previous install of the OS) but I never reinstated them.