problem with NetScheduleJobAdd( c++

Hi,

i am having problem executing a job.
see this code:

[code]
#define UNICODE
#include
#include
#include
#include

#pragma comment(lib,"netapi32.lib")

void Log(wchar_t * txt);

void add_job();
void DisplayErrorText(DWORD dwLastError );



int main()
{

add_job();
system("pause");

//NetScheduleJobGetInfo
return 0;
}



void Log(wchar_t * txt)
{

FILE * fp=fopen("somefile.txt","a");
fputws(txt,fp);
fclose(fp);



}




void add_job()
{

DWORD nStartIn=30;

DWORD dwRemoteTime;

wchar_t Servername[255];
DWORD len=256;
GetComputerNameW(Servername,&len);



AT_INFO a_info;
memset(&a_info, '', sizeof(a_info));



SYSTEMTIME si;
GetLocalTime(&si);

TIME_OF_DAY_INFO lpTimeOfDay;
if(NetRemoteTOD(Servername,(LPBYTE *)&lpTimeOfDay)==NERR_Success)
Log(L"
NetRemoteTOD :OK
");
else
{

DisplayErrorText(GetLastError());

Log(L"
NetRemoteTOD :FAILED
");

}

//Log(Servername);








// Generate the job time
// Divide the elapsed time by 60, giving us the total # of minutes since the epoch
DWORD dwJobTime = lpTimeOfDay.tod_elapsedt / 60;



// Subtract the timezone from the elapsed time to get the local time
if (lpTimeOfDay.tod_timezone != -1)
dwJobTime -= lpTimeOfDay.tod_timezone;

// Add the start delay to the job time
dwJobTime += nStartIn;


a_info.JobTime=36000000; //dwJobTime;


a_info.DaysOfMonth=0;//NULL; // now+3 min
a_info.DaysOfWeek=0;//NULL;
a_info.Flags=JOB_ADD_CURRENT_DATE;//JOB_RUNS_TODAY ;
a_info.Command=L"\D$\test.bat";





DWORD jobid=0;

if(NetScheduleJobAdd(TEXT("\OWNER-CPU\"),(LPBYTE )&a_info,&jobid)==NERR_Success)
Log(L"
NetScheduleJobAdd :OK
");
else
{
DisplayErrorText(GetLastError());
Log(L"
NetScheduleJobAdd :FAILED
");
}
// if(jobid)






}



void
DisplayErrorText(
DWORD dwLastError
)
{
HMODULE hModule = NULL; // default to system source
LPTSTR MessageBuffer; //lpstr
DWORD dwBufferLength;
DWORD dwFormatFlags;

dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM ;

//
// if dwLastError is in the network range, load the message source
//
if(dwLastError >= NERR_BASE && dwLastError <= MAX_NERR) {
hModule = LoadLibraryEx(
TEXT("netmsg.dll"),
NULL,
LOAD_LIBRARY_AS_DATAFILE
);

if(hModule != NULL)
dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
}

//
// call FormatMessage() to allow for message text to be acquired
// from the system or the supplied module handle
//
if(dwBufferLength = FormatMessageW(
dwFormatFlags,
hModule, // module to get message from (NULL == system)
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
(LPTSTR) &MessageBuffer,
0,
NULL
))
{
DWORD dwBytesWritten;

//
// Output message string on stderr
//

/*
WriteFile(
GetStdHandle(STD_ERROR_HANDLE),
MessageBuffer,
dwBufferLength,
&dwBytesWritten,
NULL
);

*/ Log(MessageBuffer);



//
// free the buffer allocated by the system
//
LocalFree(MessageBuffer);
}

//
// if we loaded a message source, unload it
//
if(hModule != NULL)
FreeLibrary(hModule);
}

[/code]


Maybe its the syntax of the path D$ orso..?

thanx



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories