batch-file - 如果文件运行后要重复运行,您将如何从批处理文件中删除一行?
问题描述
我无法控制我所在的 GPO 政策。这是我能做到的唯一方法
我有一个在整个企业中使用的登录脚本。此批处理文件用于将用户映射到他们有权访问的网络驱动器。最近,我们的 NEC 命令更改了这些驱动器的路径位置。我需要推出一个更新的批处理文件来替换当前驻留在 C: 上的启动文件夹中的那个。新文件有一行我添加(net use * /delete /y),以便删除所有已映射的现有驱动器。完成此操作后,它会通过相应地映射所有驱动器来移动到脚本的正常部分。
我遇到的问题是,由于此文件位于启动文件夹中,因此每次用户登录时它都会继续运行。用户有时会手动将驱动器映射到他们的配置文件以获取不包括的更具体的文件夹访问权限在脚本中(我们不会修改脚本以适应每个单独的用户)。如果它继续运行,它将每次删除手动映射的驱动器,这将成为一个主要问题。
我需要做的是让批处理文件运行一次,以替换旧的命名约定路径。完成后,我想从文件中删除 net use * /delete 行,然后保存它,以便以后每次都能正常运行。这是可行的吗?有没有办法在批处理文件完成运行后从批处理文件中删除一行并保存它,以便存储在机器上的文件不包含 net use 行?
这是当前写入的文件,其中写入了删除选项(删除现有的映射驱动器)
net use * /delete /y
net user /domain %username% >%userprofile%\mygroups.txt
del %userprofile%\mygroupsparsed.txt 1> NUL 2> NUL
FOR /F "tokens=2,3 delims=*" %%G IN (%userprofile%\mygroups.txt) DO (ECHO %%G & echo %%H)>>%userprofile%\mygroupsparsed.txt
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwhelpdesk net use V: "\\jblmfs\jblm\dpw\Helpdesk" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwhelpdesk net use P: "\\jblmfs\jblm\dpw\Techs\TechsOnly" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwhelpdesk net use O: "\\jblmfs\jblm\dpw\Techs" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWUSERS net use I: "\\jblmfs\jblm\dpw\IDrive" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWUSERS net use M: "\\jblmfs\jblm\dpw\DwngVault" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWUSERS net use N: "\\jblmfs\jblm\dpw\BaseData" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWUSERS net use S: "\\jblmfs\jblm\dpw\DesignRvw" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWITADMINS net use O: "\\jblmfs\jblm\dpw\Techs" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWITADMINS net use Q: "\\jblmfs\jblm\dpw\Users" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWITADMINS net use T: "\\jblmfs\jblm\dpw\HelpDesk" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWITADMINS net use U: "\\\jblm\dpw\jblm" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWITADMINS net use P: "\\jblmfs\jblm\dpw\Techs\TechsOnly" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwhousinggroup net use R: "\\jblmfs\jblm\dpw\RCI_Housing" 1> NUL 2> NUL
so
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWOBUDGET net use J: "\\jblmfs\jblm\dpw\lewidfv-lewis\jblm\dpw\DPW_Retain\Budget" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWOBUDGET net use Q: "\\150.192.16.77\atlasair" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWOESD net use J: "\\jblmfs\jblm\dpw\DPW_Retain\COE" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwecmd net use K: "\\jblmfs\jblm\dpw\DPW_Retain\ECMD" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwecmd net use W: "\\jblmfs\jblm\dpw\DPW_Retain\WinEst" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWOCOE net use J: "\\jblmfs\jblm\dpw\DPW_Retain\COE" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWOCOE net use K: "\\jblmfs\jblm\dpw\DPW_Retain\ECMD" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwenrdforestry net use F: "\\jblmfs\jblm\dpw\Forestry" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==lewispwenrd net use O: "\\jblmfs\jblm\dpw\Pollution" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWXCOMPINSP net use Y: "\\jblmfs\jblm\dpw\Comp_Inspec" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWXCOMPINSP net use W: "\\jblmfs\jblm\dpw\Hazmat" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==LEWIPWXHAZMAT1210 net use W: "\\jblmfs\jblm\dpw\Hazmat" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==JBLMIMCOMDPWGSO-Admin net use L: "\\jblmfs\jblm\dpw\Working" 1> NUL 2> NUL
for /F %%f in (%userprofile%\mygroupsparsed.txt) do if %%f ==JBLMIMCOMDPWGSO-Spt net use L: "\\jblmfs\jblm\dpw\Working" 1> NUL 2> NUL
干杯。
解决方案
推荐阅读
- iphone - 使用 JavaFX FileChooser 不选择 DCIM jpg 文件
- django - 选择的条目超过 1000 个时无法保存管理表单
- excel - 如果行与上面的行不同,则循环,将行粘贴到不同的工作表中
- python - Python计算字典列表中的值
- python - 如何将日期轴添加到我的绘图对象图形中?
- code-behind - 如何从aspx文件中提取c#?
- html - 如何在html网站的css中赋予data-autoplay属性
- sqldelight - 如何在后台线程中执行查询?
- language-agnostic - 用文本文件中的另一个递归替换一个 Windows 路径
- java - SpringToolsSuite 说“Nombre”列不能为空