Страница 17 из 24 38)---------------------------------------------------------------------------- Q> Как "зашедулить" задачу ? A> #include #include #include #include #pragma hdrstop #define BREAK_ME 1 /// #undef to get working code #undef BREAK_ME #pragma pack( push ) #ifdef BREAK_ME #pragma pack( 2 ) #else #pragma pack( 4 ) #endif #include #pragma pack( pop ) #define lenof(x) ( sizeof (x) / sizeof (x)[0] ) int main( int argc, char *argv[] ) { wchar_t server[256], cmd[1024]; AT_INFO at; DWORD rc, id; if ( argc < 2 || argc > 3 ) { puts( "usage: nsja [\\\\server] \"command\"" ); return 1; } if ( argc > 2 ) mbstowcs( server, argv[2], lenof( server ) ); else server[0] = L'\0'; mbstowcs( cmd, argv[argc - 1], lenof( cmd ) ); memset( &at, '\0', sizeof at ); at.Command = &cmd[0]; rc = NetScheduleJobAdd( server, (byte *) &at, &id ); if ( rc != ERROR_SUCCESS ) printf( "NSJA() returned %lu\n", rc ); return 0; } 39)---------------------------------------------------------------------------- Q> Как посмотреть,что же там уже "нашедулено"? A> #include #include #include #include #pragma hdrstop #define BREAK_ME 1 /// #undef to get working code #undef BREAK_ME #pragma pack( push ) #ifdef BREAK_ME #pragma pack( 2 ) #else #pragma pack( 4 ) #endif #include #pragma pack( pop ) #define lenof(x) ( sizeof (x) / sizeof (x)[0] ) int main( int argc, char *argv[] ) { wchar_t server[256]; AT_ENUM *pBuf, *pJob; DWORD i, rc, nRead, nLeftBeforeCall, hResume; bool goForIt; if ( argc > 2 ) { puts( "usage: nsje [\\\\server]" ); return 1; } if ( argc > 2 ) mbstowcs( server, argv[2], lenof( server ) ); else server[0] = L'\0'; hResume = 0; printf( "%8.8s %.70s\n", "JobId", "Command" ); printf( "%8.8s %.70s\n", "--------", "----------------------------------------------------------------------" ); goForIt = true; while ( goForIt ) { pBuf = NULL; rc = NetScheduleJobEnum( *server == L'\0'? NULL: server, (BYTE **) &pBuf, 8192, &nRead, &nLeftBeforeCall, &hResume ); if ( rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA ) { printf( "Doh! rc = %lu\n", rc ); return 1; } for ( pJob = pBuf, i = 0; i < nRead; ++ i, ++ pJob ) { printf( "%8lu %.70S\n", pJob->JobId, pJob->Command ); } if ( pBuf != NULL ) NetApiBufferFree( pBuf ); if ( rc == ERROR_SUCCESS ) goForIt = false; } return 0; } |