News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Question about enuming schedule job (Unicode string)

Started by purpleendurer, November 01, 2009, 09:36:17 AM

Previous topic - Next topic

purpleendurer

First, I create a Schedule Job with AT command.

at 18:35 "xcopy.exe"


Then, Run my program to display the JobID & Command of the Schedule Job.

The JobID "00000001" is right, but the Command is not  "xcopy.exe"

the Command  is a  Pointer to a Unicode string that contains the name of the command, batch program, or binary file to execute.

%S is in vain?

I felt at a loss.



Here is my code:
Quote

.586
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\windows.inc

INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib

INCLUDE \masm32\include\Netapi32.inc
INCLUDELIB \masm32\lib\Netapi32.lib

INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib


.DATA?

dwLeftBeforeCall dword ?
dwRead dword ?
dwJobCount dword ?
pBuf dword ?    ;ponter to AT_ENUM
Buf512 byte 512 dup(?)


.DATA

szCation db "ScheduleJob", 0
szFmt db "%08lu %S", 0


.CODE

start:

    mov dwLeftBeforeCall, 0

    invoke NetScheduleJobEnum, NULL, addr pBuf, MAX_PREFERRED_LENGTH, addr dwRead\
                        , addr dwJobCount, addr dwLeftBeforeCall

    mov edi, pBuf
    .while (dwRead > 0)
        push edi

        lea eax, (AT_ENUM ptr [edi]).Command

        invoke wsprintf, addr Buf512, addr szFmt, (AT_ENUM ptr [edi]).JobId, eax

        invoke MessageBox, NULL, addr Buf512, addr szCation, NULL

        pop edi
        add edi, sizeof AT_ENUM
        dec dwRead
    .endw

    .IF (pBuf != NULL)
            invoke NetApiBufferFree, pBuf
    .ENDIF

    invoke ExitProcess, 0
END start



purpleendurer

I had worked it out.


The define of AT_ENUM in windows.inc of MASM32 is incorrect.

The right is:

_AT_ENUM struct
    JobId       dd      ?
    JobTime     dd      ?
    DaysOfMonth dd      ?
    DaysOfWeek  UCHAR   ?
    Flags       UCHAR   ?
    align1      db      ?
    align2      db      ?
    Command     dd      ?
_AT_ENUM ends


I modified the code:

.586
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\windows.inc

INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib

INCLUDE \masm32\include\Netapi32.inc
INCLUDELIB \masm32\lib\Netapi32.lib

INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib


_AT_ENUM struct
    JobId       dd      ?
    JobTime     dd      ?
    DaysOfMonth dd      ?
    DaysOfWeek  UCHAR   ?
    Flags       UCHAR   ?
    align1      db      ?
    align2      db      ?
    Command     dd      ?
_AT_ENUM ends


.DATA?

dwLeftBeforeCall dword ?
dwRead dword ?
dwJobCount dword ?
pBuf dword ?    ;ponter to AT_ENUM
Buf512 byte 512 dup(?)


.DATA

szCation db "ScheduleJob", 0
szFmt db "%08lu %S", 0


.CODE

start:

    mov dwLeftBeforeCall, 0

    invoke NetScheduleJobEnum, NULL, addr pBuf, MAX_PREFERRED_LENGTH, addr dwRead\
                        , addr dwJobCount, addr dwLeftBeforeCall

    mov edi, pBuf
    .while (dwRead > 0)
        push edi


        invoke wsprintf, addr Buf512, addr szFmt, (_AT_ENUM ptr [edi]).JobId, (_AT_ENUM ptr [edi]).Command

        invoke MessageBox, NULL, addr Buf512, addr szCation, NULL

        pop edi
        add edi, sizeof _AT_ENUM
        dec dwRead
    .endw

    .IF (pBuf != NULL)
            invoke NetApiBufferFree, pBuf
    .ENDIF

    invoke ExitProcess, 0
END start


ecube

yeah masm32 needs alot of updates on structures, we should have a thread for any people find incorrect so hutch can make the changes for future versions, infact I'll go start that.

Vortex

Hi purpleendurer,

The structure alignment problem is a known issue. Here, you can find a scheduler API demo.