Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

windows - Error when trying to register a task with task scheduler (Win7)

To enable my application to startup with admin rights at user login, I use a task in task scheduler. And it works fine. Mostly. Now I've received bug reports saying that this fails:

rootFolder->RegisterTaskDefinition( _bstr_t(name.toWideCharPointer()), task,              
   TASK_CREATE_OR_UPDATE, _variant_t(L"Builtin\Administrators"), _variant_t(), 
   TASK_LOGON_GROUP, _variant_t(L""), &registeredTask) -> 0x80070534

0x80070534 seems to mean "No mapping between account names and security IDs was done". I'm following (pretty much verbatim) the example at: http://msdn.microsoft.com/en-us/library/aa381911(v=VS.85).aspx

Ideas what has gone wrong, and how to fix it ? The application has manifest set so the user needs to be admin to run it.

Question: The "Builtin\Administrators" group, it is language dependent, isn't it ? I think that the user in question might have a non-english Windows 7. If so I imagine it would work better with specifying "S-1-5-32-544" instead ( http://support.microsoft.com/kb/243330 )

Update: So the explicit call looks like:

rootFolder->RegisterTaskDefinition(
            _bstr_t(name.toWideCharPointer()),
            task,
            TASK_CREATE_OR_UPDATE,
            _variant_t(L"S-1-5-32-544"),    // Language independent "BUILTINAdministrators" 
            _variant_t(),
            TASK_LOGON_GROUP,
            _variant_t(L""),
            &registeredTask)

Make sure that the application is executed with elevated privileges, otherwise that call will fail.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem indeed lies in the parameter _variant_t(L"Builtin\Administrators"), which is hard-coded to English version of Windows. By using the language agnostic security identifier "S-1-5-32-544" ( http://support.microsoft.com/kb/243330 ), the problem is resolved.

Update: So the explicit call looks like:

rootFolder->RegisterTaskDefinition(
            _bstr_t(name.toWideCharPointer()),
            task,
            TASK_CREATE_OR_UPDATE,
            _variant_t(L"S-1-5-32-544"),    // Language independent "BUILTINAdministrators" 
            _variant_t(),
            TASK_LOGON_GROUP,
            _variant_t(L""),
            &registeredTask)

Make sure that the application is executed with elevated privileges, otherwise the call will fail.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...