批处理文件中无法识别sc.exe

时间:2015-09-09 12:45:59

标签: mongodb batch-file client-server

这是我们用来构建这个批处理文件的代码,它将连接到我们将用于MongoDB的服务器。 ****是我的用户名帐户,不想与任何人分享。

sc.exe create MongoDB binPath = 
"C:\Users\****\Desktop\FanshaweCollege\semester3\Servers\bin\mongod.exe 
--service --config=\"C:\Users\****\Desktop\FanshaweCollege\semester3\Servers\mongodb.cfg\"" 
DisplayName= "MongoDB" start= "auto"

老师不会帮助我们,他也不知道问题是什么。我开始搜索谷歌,但我能找到的唯一问题是我需要更改环境变量,并将其设置为全部。

错误是:

 'sc.exe' is not recognized as an internal or external command, operable program or batch file.

我如何才能实现这个目标

2 个答案:

答案 0 :(得分:1)

尝试where sc.exe搜索它的位置。然后使用该命令的完整路径。

sc.exe create MongoDB binPath = "C:\Users\****\Desktop\FanshaweCollege\semester3\Servers\bin\mongod.exe 
--service --config=\"C:\Users\****\Desktop\FanshaweCollege\semester3\Servers\mongodb.cfg\"" 
DisplayName= "MongoDB" start= "auto"

您必须处理双引号/单引号("')。不确定是否可以使用\ in路径执行此操作,因为在您的示例中,它可以解释为文件夹。尝试插入符号(^)或双引号内的单引号

在您的示例中,正确的语法应为:

C:\Windows\System32\sc.exe create MongoDB ^
    binPath="'C:\*****\mongod.exe' --service --config=^
    'C:\Users\****\Desktop\FanshaweCollege\semester3\Servers\mongodb.cfg'" ^
    DisplayName="MongoDB" start="auto"

注意:插入符号(^)是为了逃避车厢返回。

或者在一行中:

C:\Windows\System32\sc.exe create MongoDB binPath="'C:\*****\mongod.exe' --service --config='C:\Users\****\Desktop\FanshaweCollege\semester3\Servers\mongodb.cfg'" DisplayName="MongoDB" start="auto"

答案 1 :(得分:0)

您需要将sc.exe的位置添加到环境变量"路径"