将CMD命令重定向到EXE文件

时间:2014-03-13 00:03:48

标签: batch-file redirect cmd command internal

基本上我已经创建了一个选择批处理,我经常可以归档我的启动数据的内容,因为我经常更改它并且它工作绝对完美,但是我遇到的问题是每次我从.BAT编译批处理to.EXE with Advanced BAT to EXE转换命令' bcdedit'从不工作,并说“不被认为是内部或外部命令,可操作程序或批处理文件。” 现在我做的第一件事是确保我的硬盘驱动器上是否有环境变量,看起来很好:

Path: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Users\Support\DOCUME~1\MYFILE~1\Programs\SYSTEM~1\DISKEE~1\

它具有完美工作所需的所有变量加上一些外部的变量然后我想也许我应该尝试直接在我的文件夹上,通过我在另一个论坛上发现的一些研究: Setting or Modifying a System Wide Environment Variable In CMD.EXE 我做了一个单独的.BAT并且我调用了它,它似乎确实创建了单独的变量:

  

C:\用户\ ??? \文件\; C:\ Windows \ System32下; C:\视窗; C:\ Windows \ System32下\ WBEM; C:\ Windows \ System32下\ WindowsPowerShell \ V1.0 \; C:\ Program Files(x86)\ QuickTime \ QTSystem \; C:\ Program Files(x86)\ Intel \ OpenCL SDK \ 2.0 \ bin \ x86; C:\ Program Files(x86)\ Intel \ OpenCL SDK \ 2.0 \ BIN \ 64; C:\ Users \用户支持\ DOCUME〜1个\ MYFILE〜1 \程序\ SYSTEM〜1个\ DISKEE〜1" / F

但它仍然没有用!

我读了另一种形式:

Syswow64 Redirection

人员解决方案是使用Create Process()创建一个程序,使用sysnative(System32)自动将他重定向到文件夹,但我是C#的初学者,CMD是编码时最强的区域

请求我尽快帮助我,如果你有答案,请以最简单的方式说明,为什么。这是我的脚本,以防万一:

    :START
echo.
echo Call apath.bat
echo.
echo.
echo (E) - Start Process.
echo (C) - Launch Part 2 Of Process.
echo (N) - Load NoDrives Manager.
echo (D) - Display Currect Account and Computer Information
echo (X) - Exit EDIM.
echo.
echo NOTE - It will not work if not started with Admin Privillages.
echo.
:Choice
set/p Option=Please enter your option: 
if '%Option%' == 'E' goto :Incognito
if '%Option%' == 'C' goto :Touch
if '%Option%' == 'N' goto :Manager
if '%Option%' == 'D' goto :Data
if '%Option%' == 'X' goto :Exit
echo.
echo.
echo Invalid Option - Please Reselect.
goto :Choice
:RetryE
Echo An Error was found!
set/p RetryE=Retry? Y/N: 
if '%RetryE%' == 'Y' goto :Incognito
if '%RetryE%' == 'N' goto :Exit
:Incognito
Timeout 5
echo.
echo.
echo.
Echo Saving OriginalBCD...
bcdedit /export "Data/BCD/OriginalBCD"
IF %ERRORLEVEL% GTR 0 goto :RetryE
IF %ERRORLEVEL% LSS 0 goto :RetryE
Echo Checking presence of BCD...
IF NOT EXIST "Data/BCD/OriginalBCD" goto :RetryE
Echo Deleting Boot Entry...
bcdedit /delete {current}
IF %ERRORLEVEL% GTR 0 goto :RetryE
IF %ERRORLEVEL% LSS 0 goto :RetryE
Echo Saving EditedBCD...
bcdedit /export "Data/BCD/IncogBCD"
IF %ERRORLEVEL% GTR 0 goto :RetryE
IF %ERRORLEVEL% LSS 0 goto :RetryE
Echo Checking presence of BCD...
IF NOT EXIST "Data/BCD/IncogBCD" goto :RetryE
Echo Allowing User Control For Assigning System Reserved Partitions...
Echo -Commands-
Echo Diskpart
Echo List volume
Echo Select Volume "" (The one that has no Letter and remember number)
Echo Assign Letter=Z
Echo Select Volume "" (The one that has Letter E and remember number)
Echo Remove Letter=E  (This is the new system reserved partition)
Echo Then exit Diskpart to finish Part 1.
Diskpart
Echo Ready To Restart!
Timeout 5
Shutdown /r /t 30 
Goto :Start
:RetryC
set/p RetryE=Retry? Y/N: 
if '%RetryC%' == 'Y' goto :Touch
if '%RetryC%' == 'N' goto :Exit
:Touch
echo.
echo.
echo.
Echo Loading NDM...
Echo NOTE - Store the password somewhere safe!!!
Start "" "Data/NDM.exe"
Echo Loading EditedBCD...
bcdedit /import "Data/BCD/IncogBCD"
IF %ERRORLEVEL% GTR 0 goto :RetryC
IF %ERRORLEVEL% LSS 0 goto :RetryC
Echo Process Complete!
Timeout 5
Echo Returning to menu...
goto :Start
:Manager
echo.
Echo NOTE - Store the password somewhere safe!!!
Start "" /WAIT "Data/ndm.exe" 
Echo Returning to Menu...
goto :Start
:Data
echo.
echo.
echo.
echo Processing Data...
Systeminfo
diskpart /s "Data/discpart.txt"
Echo Returning to Menu...
goto :Start
:Exit
Exit

非常感谢!

1 个答案:

答案 0 :(得分:0)

默认情况下,

bcdedit在路径上,因此除非您重用PATH变量,否则问题出在批处理编译器中。

您可以使用普通批处理文件对其进行测试 - 如果有效,那么您就知道问题所在。