创建一个简单的批处理文件,解压,安装和更多 [英] Create a simple batch file that extract, install and more

查看:474
本文介绍了创建一个简单的批处理文件,解压,安装和更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个在工作中的日常任务,是从的下载 ZIP文件 USB STICK驱动器那一定是提取内容快速格式化的 FAT32

在我提取的 zip文件 USB STICK ,有一个特殊的文件(称为的setup.bat ),我需要为右键单击并选择以管理员身份运行。

最后一步是从电脑中弹出的 USB STICK 并给予在 USB STICK 以销售人员。

现在我的问题是,我可以创建一个批处理文件做这件工作给我吗?我插入的 USB STICK驱动器插入机器,我跑在的批处理文件,一切都可以自动完成?

第1步
插入USB记忆棒(当然,这是我一个手动步骤。)

第2步
运行,我们创建批处理文件。

第3步
该批处理文件执行:快速格式化为FAT32的USB记忆棒
我并不需要提供一个名称的体积。它可以是空的。

第四步
该批处理文件执行:提取从位于进入下载文件夹复制到U盘上的ZIP文件的内容。
(zip文件的名称是:PLC-stick_8.3)

第五步
该批处理文件执行:以管理员身份运行特定文件:SETUP.BAT
这是位于已经从zip文件到USB棒中提取的包中的文件。

第六步
该批处理文件执行:卸载/弹出USB棒

感谢您这么多,在您的帮助,有一个美好的一天。

sambul35
非常感谢你的帮助。它几乎做到了完美。我只收到一对夫妇的警告消息。我是pretty肯定,这是我从你的条件失去了一些东西。任何建议我做错了吗?你可以阅读下面的执行。所以再次感谢你。


 类型的文件系统是FAT32。
QuickFormatting 1.9 GB
初始化文件分配表(FAT)...
格式化完成。
       1.9 GB的总磁盘空间。
       1.9 GB可用。        4,096字节在每个分配单元。
      490432磁盘上可用的分配单元。           在每一FAT条目32位。卷序列号是2495-4F8F等待0秒,preSS任意键继续......解压完成。运行安装程序...该系统找不到指定的路径。
'bootinst.bat'不被识别为内部或外部的命令,
可运行的程序或批处理文件。安装完成'removedrive'不被识别为内部或外部的命令,
可运行的程序或批处理文件。
所有任务完成。删除闪存驱动器。


解决方案

下面的批处理执行你所需要的所有任务。它做了几个假设:


  • 您处理USB拇指驱动器是在工厂与一个现有的分区pformatted $ P $

  • 的大拇指总是在转播挂载到相同的驱动器盘符的 D:的。您可以更改
    在脚本中的驱动器盘符

  • 您下载,解压和复制到这批目录
    RemoveDrive 工具。它弹出一个USB闪存驱动器的最佳方式
    从Cmd的

  • 您没有从默认的移动用户帐户Downloads文件夹
    位置

  • 保存此的 AutoFlash.bat 的在您的用户帐户访问的目录,
    创建桌面快捷方式,请选择在其
    属性 - 快捷方式 - 高级的选项的以管理员身份运行

如果这些条件得到满足,勾了一个USB拇指,等到它在Windows资源管理器访问,然后通过快捷方式运行该脚本自动完成所有的任务:

 <  - !开始批处理脚本
关闭@echo
SETLOCAL ENABLEEXTENSIONS EnableDelayedExpansion
CD / D%〜DP0&安培;置行驶= D:&放大器;设置安装= 0&放大器;回声/
设置文件=%USERPROFILE%\\下载\\ plc-stick_8.3.zip
如果存在%驱动器%\\ NUL(格式%驱动器%/ Q / FS:FAT32 / Y / V:USBFlash
)否则(设置加载= 1&安培;回声闪存驱动器未安装)
超时3
如果不安装%EQU%1(回声/
    CSCRIPT // NOLOGO%〜F0?.wsf的%文件%%驱动器%\\
    回声解压完成。运行安装程序...&安培;回声/
    打电话%驱动器%\\ SETUP.BAT
    超时3及回声安装完成&安培;回声/
    removedrive%驱动器%-L
    呼应所做的一切任务。删除闪存驱动器。
)其他(回声/&安培;回声重新插入驱动器或打开磁盘管理)
超时/吨3 / NOBREAK> NUL
退出/ B-----开始WSF脚本--->
<&工作GT;< SCRIPT LANGUAGE =VBScript中>
设置objShell =的CreateObject(Shell.Application)
设置银= Wscript.Arguments
设置的WshShell = WScript.CreateObject(WScript.Shell)设置DestFldr = objShell.NameSpace(银(1))
设置SrcFldr = objShell.NameSpace(银(0))
设置FldrItems = SrcFldr.Items
DestFldr.CopyHere FldrItems,&安培; H214
< / SCRIPT>< /工作>

让我知道如果有正在运行的脚本中的任何问题。

One of my daily task at work, is to extract the content from a downloaded ZIP FILE into a USB STICK drive that must be quickly formatted in FAT32.

After I extract the ZIP File into the USB STICK, there is one file in particular (called setup.bat) that I need to right click and select Run as Administrator.

The final step is to eject the USB STICK from the computer and give the USB STICK to a sales person.

Now my question is, can I create a batch file that does this job for me? I insert the USB STICK drive into the machine and I run the BATCH FILE, everything can be done automatically?

Step #1 Insert the USB Stick (Of course this is a manual step from me.)

Step #2 Run the batch file that we create.

Step #3 The batch file executes: Quick format the USB Stick in FAT32 I do not need to give a name to the volume. It can be empty.

Step #4 The batch file executes: Extract the content from the ZIP FILE located into the downloads folder into the USB Stick. (The name of the zip file is: plc-stick_8.3)

Step #5 The batch file executes: Run as Administrator a specific file: setup.bat This is a file located within the package that has been extracted from the zip file into the USB Stick.

Step #6 The batch file executes: Unmount/Eject the USB Stick

Thank you so much in advance for your help and have a beautiful day

sambul35 thank you so much for your help. It is almost done and perfect. I only received a couple of warning message. I am pretty sure this is something that I am missing from your conditions. Any suggestion what I am doing wrong? You can read the execution below. Thank you so much again.


The type of the file system is FAT32.
QuickFormatting 1.9 GB
Initializing the File Allocation Table (FAT)...
Format complete.
       1.9 GB total disk space.
       1.9 GB are available.

        4,096 bytes in each allocation unit.
      490,432 allocation units available on disk.

           32 bits in each FAT entry.

Volume Serial Number is 2495-4F8F

Waiting for 0 seconds, press a key to continue ...

Unpack completed. Running setup...

The system cannot find the path specified.
'bootinst.bat' is not recognized as an internal or external command,
operable program or batch file.

Install completed

'removedrive' is not recognized as an internal or external command,
operable program or batch file.
All tasks done. Remove Flash Drive.

解决方案

The batch below performs all the tasks you need. It makes several assumptions:

  • the USB Thumb drives you process are preformatted at factory with one existing partition
  • thumbs are always automounted upon hookup to the same drive letter D: . You can change the drive letter in the script
  • you downloaded, unpacked and copied to this batch directory RemoveDrive tool. Its the best way to eject a USB flash drive from Cmd
  • you didn't move your user account Downloads folder from its default location
  • save this AutoFlash.bat in your user account accessible directory, create a desktop shortcut to it, select in its Properties-Shortcut-Advanced option "Run as Administrator"

If these conditioned are met, hook up a USB Thumb, wait until its accessible in Windows Explorer, then run this script by the shortcut to auto perform all your tasks:

<!-- : Begin batch script
@echo off
setlocal EnableExtensions EnableDelayedExpansion
cd /d %~dp0 & set "drive=D:" & set "mount=0" & echo/
set "file=%USERPROFILE%\Downloads\plc-stick_8.3.zip"
if exist %drive%\nul (format %drive% /q /fs:FAT32 /Y /v:USBFlash
) else (set "mount=1" & echo Flash drive is not mounted)
timeout 3
if not %mount% equ 1 (echo/
    cscript //nologo "%~f0?.wsf" "%file%" "%drive%\"
    echo Unpack completed. Running setup... & echo/
    call %drive%\setup.bat
    timeout 3 & echo Install completed & echo/
    removedrive %drive% -L
    echo All tasks done. Remove Flash Drive.
) else (echo/ & echo Reinsert the drive or open Disk Management)
timeout /t 3 /nobreak >nul
exit /b

----- Begin wsf script --->
<job><script language="VBScript">
Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set DestFldr=objShell.NameSpace(Ag(1))
Set SrcFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
</script></job>

Let me know if there're any problems running the script.

这篇关于创建一个简单的批处理文件,解压,安装和更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆