2

For some specific purpose, I need to install some fonts on the instances. It comes as no surprise when I choose StartUp Task to accomplish that goal. I've configured the Service Definitions as below:

<Startup>
  <Task commandLine="Fonts\InstallFonts.vbs" executionContext="elevated" taskType="simple" />
</Startup>

Nothing special here. Click and run, it failed. However, if I changed the commandLine into a cmd file including just nonsense, namely "echo test", the instance would run without ado. So there must be some issue with my scripting:

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("."))
Set fontFolder = objShell.Namespace(FONTS) 

Set rxTTF = New RegExp
rxTTF.IgnoreCase = True
rxTTF.Pattern = "\.ttf$"

Set fso = CreateObject("Scripting.FileSystemObject")

FOR EACH FontFile IN objFolder.Items()
    IF rxTTF.Test(FontFile.Path) THEN
        IF NOT fso.FileExists(fontFolder.Self.Path+"\\"+FontFile.Name) THEN
         FontFile.InvokeVerb("Install")
        END IF
    END IF
NEXT

The script should come with no error because I've tested it either locally or on Azure via RDP.

Weirdly, when I put it in the startup, the role just won't start. The instance just keeps recycling and at last says "I'm unhealthy". Even if I deprecate the vbs into just one line of code - the first line Const FONTS = &H14&, it just won't start. Even if I wrap the invocation of the vbs into a cmd file, namely to put something like "cscript /B file.vbs", it won't run either.

So I'm concluding that there must be some issue regarding the communication between the script and the Windows Azure monitor. I'm not sure but I think the monitor might take the running script as a failed task. Besides, I'm wondering if there is any timeout for the startup task, which should be the problem though, because the script can guarantee that no UI interaction block the process.

Any idea would be greatly appreciated.

4

3 回答 3

1

I am sure you must have but just for the sake of confirmation, have you checked that the InstallFonts.vbs file is exported with the package? I mean is the "Copy To Output Directory" is set to "Copy Always/Copy if newer"?

This is pretty much possible that it is not able to locate your file.

于 2013-07-26T11:18:54.723 回答
1

You need to write a cmd file as a start up task. In your cmd file, you can call the vbs file using the command line tool cscript. Azure start up can compile only command line tools.

于 2013-07-26T11:36:42.947 回答
1

Oh god, I finally solved the problem.

Although the compiler does quite a good job usually, it allows to use subfolder as a source of command, I mean something like "Subfolder\command.cmd", which will not work always. I've seen examples in which people put whatever we do in cmd in commandLine property, such as "copy fileA fileB" and it really works. But as for vbs, you need to be cautious. Until now I still don't know what's under the cover, but there should be some problem with the path. And the solution is definitely simple, instead of doing the subfolder work for tidiness, just leave the command file in the root folder like most people do:

<Startup>
  <Task commandLine="InstallFonts.vbs" executionContext="elevated" taskType="simple" />
</Startup>

And thank you all the same, Kunal. :)

于 2013-07-26T13:23:31.523 回答