Because you are using the @FULLNAME macro which then must make a call to the Network to find that information. However, the task scheduler service has NO Network access. Thus the error 5 access denied message.

You could run this type of code which might give you what you're looking for.



Break On
$ServiceTag=294012
$OS=@ProductType
$User = ReadValue("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon""AltDefaultUserName")
$Key = "HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters"
$Entry = "srvcomment"
$Expression = $User + " (" + $ServiceTag + ") " + $OS
$DataType = "REG_SZ"
$UpdateKey=WriteValue($Key$Entry$Expression$DataType)