2

我正在按照我的 ServiceDefinition.csdef 中的以下内容启动启动脚本

<Startup>
  <Task commandLine="Microsoft.WindowsAzure.Caching\ClientPerfCountersInstaller.exe install" executionContext="elevated" taskType="simple" />
  <Task commandLine="startup.cmd" executionContext="elevated" taskType="simple" />
</Startup>

startup.cmd 文件是

@echo off
REM StartupLog.txt can be found at (E or F):\approot\bin

Echo Copying MyUtil to system root                                                        >> StartupLog.txt 2>&1
copy /y MyUtil.exe %SystemRoot%                                                           >> StartupLog.txt 2>&1
IF ERRORLEVEL 1 GOTO ErrorExit

REM It's ok if the next fails, the task may not be scheduled 1st time
Echo Trying to delete MyUtil from scheduler                                               >> StartupLog.txt 2>&1
schtasks /Delete /F /TN "MyUtil"                                                          >> StartupLog.txt 2>&1

Echo Adding MyUtil to Scheduler                                                           >> StartupLog.txt 2>&1
schtasks /Create /SC MINUTE /MO 2 /SD 11/01/2012 /TN "MyUtil" /TR %SystemRoot%\MyUtil.exe >> StartupLog.txt 2>&1
IF ERRORLEVEL 1 GOTO ErrorExit                                                            >> StartupLog.txt 2>&1
GOTO End

:ErrorExit
REM   Report the date, time, and ERRORLEVEL of the error.
%ERRORLEVEL%                                                      >> StartupLog.txt 2>&1
DATE /T                                                           >> StartupLog.txt 2>&1
TIME /T                                                           >> StartupLog.txt 2>&1
ECHO An error occurred during startup. ERRORLEVEL = %ERRORLEVEL%  >> StartupLog.txt 2>&1
ECHO -----------------------------------------------------------  >> StartupLog.txt 2>&1
EXIT /B 1

:End    
ECHO Exiting at end with 0                                        >> StartupLog.txt 2>&1
ECHO -----------------------------------------------------------  >> StartupLog.txt 2>&1
EXIT /B 0

(E: or F:)\approot\bin 中的错误是:

Copying MyUtil to system root                                                        
        1 file(s) copied.
Trying to delete MyUtil from scheduler                                                
SUCCESS: The scheduled task "MyUtil" was successfully deleted.
Adding MyUtil to Scheduler                                                            
ERROR: No mapping between account names and security IDs was done.

(43,4):LogonType:'1' is not recognized as an internal or external command,
operable program or batch file.

如果我在 RDP 进入 WebRole 之后运行 startup.cmd 文件,那么这些任务就会很好地添加到调度程序中。由于某种原因,它总是无法通过部署。有谁知道如何解决这一问题?我恢复到 OSVersion=2 直到我可以解决这个问题。

4

2 回答 2

0

原因可能是执行脚本的用户(还)没有 AppData 目录。您可以尝试在启动任务的顶部添加这些吗?

md "%~dp0appdata"
reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f
于 2012-11-20T06:51:29.213 回答
0

我遇到了完全相同的问题,在浪费了几个小时认为这是一个权限问题之后,结果发现它需要在指定为 /TR 参数的路径周围加上双引号。实际上我有命令行参数,所以我需要像“\”appname.exe\“\”parameter\””这样指定它

和你一样,我在我的任务中使用了环境变量——尽管我不确定为什么,这可能是相关的。也像您一样,以我的 RDP 用户身份启动时任务运行良好,但在 SYSTEM 下作为实际启动任务运行时却失败了。

我知道几个月过去了,所以你可能已经从这个问题上移开了,但我很好奇这些报价是否也为你解决了问题(以及奖励积分,解释为什么它关心!)。

于 2013-05-08T22:34:26.627 回答