我想通过一个批处理文件来创建基于Windows用户名的快捷查找变量 - 批
我是线沿线的思考:
if %username% in (a,b,c,d) (
shortcut ShortcutName DestinationPath
)
else (
shortcut OtherShortcutName OtherDestinationPath
)
我遇到的问题与第一部分,因为我已经知道如何通过命令行创建快捷方式...
希望我能找到一些帮助。
我想通过一个批处理文件来创建基于Windows用户名的快捷查找变量 - 批
我是线沿线的思考:
if %username% in (a,b,c,d) (
shortcut ShortcutName DestinationPath
)
else (
shortcut OtherShortcutName OtherDestinationPath
)
我遇到的问题与第一部分,因为我已经知道如何通过命令行创建快捷方式...
希望我能找到一些帮助。
例如:
@ECHO OFF &SETLOCAL
if defined Array[%username%] (
shortcut ShortcutName DestinationPath
) else (
shortcut OtherShortcutName OtherDestinationPath
)
一些更多的代码来获得更清晰:
@ECHO OFF &SETLOCAL
set "Array[Peter]=true"
set "Array[James]=true"
set "Array[Robby]=true"
set "Array[Jimmy]=true"
set "MyUserName=Jimmy"
call:check "%MyUserName%"
set "MyUserName=Paul"
call:check "%MyUserName%"
goto:eof
:check
if defined Array[%~1] (
echo %~1 is in the array.
) else (
echo %~1 is NOT in the array.
)
exit /b
..输出为:
Jimmy is in the array.
Paul is NOT in the array.
是不是真的有一个数组键入批处理文件,但我们可以通过iterat来修改它荷兰国际集团在空格分隔的列表与for
:
@ECHO OFF
set Array=Peter James Robby Jimmy
for %i in (%array%) do (if %i==%USERNAME% (echo %USERNAME% is found) else (echo %USERNAME% not found))
如果罗比已登录,输出为:
Not found
Not found
Robby is found
Not found
@echo off
for %%i in (a b c d) do (^
if %%i'==%username%' (shortcut ShortcutName DestinationPath &goto isuser)^
)
rem else
shortcut OtherShortcutName OtherDestinationPath
:isuser
rem other code...
whoa ...请downvoters请告诉我哪里出错了?请给出意见。 – nephi12
不为我工作(在Windows 7)。我得到以下错误:''arrayi“kann syntaktisch die dieser Stelle nicht verarbeitet werden.' –
更改为'%%我在(%数组%)中do(if %% i ==%USERNAME%(echo%USERNAME%被发现)其他(回声%USERNAME%未找到))'使它工作 –