* Sync up to trunk head (r64829).
[reactos.git] / dll / win32 / mstask / task_scheduler.c
index 1d2ac21..9b98108 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "corerror.h"
 #include "mstask_private.h"
-#include "wine/debug.h"
 
-WINE_DEFAULT_DEBUG_CHANNEL(mstask);
+#include <corerror.h>
 
 typedef struct
 {
@@ -85,16 +83,57 @@ static HRESULT WINAPI MSTASK_ITaskScheduler_SetTargetComputer(
         ITaskScheduler* iface,
         LPCWSTR pwszComputer)
 {
-    FIXME("%p, %s: stub\n", iface, debugstr_w(pwszComputer));
-    return E_NOTIMPL;
+    TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
+    WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 3];  /* extra space for two '\' and a zero */
+    DWORD len = MAX_COMPUTERNAME_LENGTH + 1;    /* extra space for a zero */
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(pwszComputer));
+
+    /* NULL is an alias for the local computer */
+    if (!pwszComputer)
+        return S_OK;
+
+    buffer[0] = '\\';
+    buffer[1] = '\\';
+    if (GetComputerNameW(buffer + 2, &len))
+    {
+        if (!lstrcmpiW(buffer, pwszComputer) ||    /* full unc name */
+            !lstrcmpiW(buffer + 2, pwszComputer))  /* name without backslash */
+            return S_OK;
+    }
+
+    FIXME("remote computer %s not supported\n", debugstr_w(pwszComputer));
+    return HRESULT_FROM_WIN32(ERROR_BAD_NETPATH);
 }
 
 static HRESULT WINAPI MSTASK_ITaskScheduler_GetTargetComputer(
         ITaskScheduler* iface,
         LPWSTR *ppwszComputer)
 {
-    FIXME("%p, %p: stub\n", iface, ppwszComputer);
-    return E_NOTIMPL;
+    TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
+    LPWSTR buffer;
+    DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for the zero */
+
+    TRACE("(%p)->(%p)\n", This, ppwszComputer);
+
+    if (!ppwszComputer)
+        return E_INVALIDARG;
+
+    /* extra space for two '\' and a zero */
+    buffer = CoTaskMemAlloc((MAX_COMPUTERNAME_LENGTH + 3) * sizeof(WCHAR));
+    if (buffer)
+    {
+        buffer[0] = '\\';
+        buffer[1] = '\\';
+        if (GetComputerNameW(buffer + 2, &len))
+        {
+            *ppwszComputer = buffer;
+            return S_OK;
+        }
+        CoTaskMemFree(buffer);
+    }
+    *ppwszComputer = NULL;
+    return HRESULT_FROM_WIN32(GetLastError());
 }
 
 static HRESULT WINAPI MSTASK_ITaskScheduler_Enum(