Hello Bodgan,
Can you as Tasm Coder help me with some code to adjust permission to shut down Win2k ?
I try to port this : http://www.onlineprogrammer.org/articles/Articlea2-2-1.html

Thanks
Posted on 2002-03-05 04:38:35 by syntax_error
Try giving us your translation of the code and I'll try to help you out and correct some mistakes.


for starters: (just translated out of that C like code :) Can't gaurantee accuracy) - this is old style asm programming.



BOOL IsWindowsNT()
{
DWORD dwVersion = GetVersion();

if ( dwVersion < 0x80000000)
return TRUE;
else
return FALSE;
}

[color=blue]
PROC isWindowsNT
call GetVersion
cmp eax, 080000000h
jae @@NotNT
mov eax, TRUE
ret
@@NotNT:
xor eax, eax
ret
ENDP isWindowsNT
[/color]

void AdjToken()

[color=blue]PROC AdjToken[/color]

{
HANDLE hToken;
LUID tmpLuid;

[color=blue]Declare this on the data section[/color]

HANDLE handleProcess=GetCurrentProcess();

[color=blue]
call GetCurrentProcess
mov handleProcess, eax
[/color]


if(!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken))

[color=blue]
push OFFSET hToken
push TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY
push handleProcess
call OpenProcessToken
or eax, eax
jnz @@Continue1:
[/color]
Application->
MessageBox("Open Process Token Error","Error",MB_OK);
[color=blue]
;the message box
@@Continue1:
[/color]

if(!LookupPrivilegeValue(0,"SeShutdownPrivilege", &tmpLuid))

[color=blue]

;"SeShutdownPrivilege" must be declared as db on the data section

push OFFSET tmpLuid
push OFFSET SSP ;SeShutdownPrivilege
push 0
call LookupPrivilegeValue
or eax, eax
jnz @@Continue2
;Messagebox
@@Continue2:

....... blah!, blah!, blah! :)


ENDP AdjToken[/color]


oops, I'm not Bogdan :)
Posted on 2002-03-05 11:37:21 by stryker
hello stryker

many thanks for your help !!!

call GetVersion
cmp eax, 080000000h
jae @@NotNT

wow ,that makes my code lines smaller ,thanks !

But what is Luid ?
Im shure thats why it wont work.
Would you please help me again ?

Thanks

.386
.MODEL FLAT,STDCALL

global OpenProcessToken:Proc
global LookupPrivilegeValueA:Proc
global GetCurrentProcess:Proc
global GetVersion:Proc
global ExitWindowsEx:Proc
global MessageBoxA:Proc
global ExitProcess:Proc

TOKEN_QUERY equ (0008h)
TOKEN_ADJUST_PRIVILEGES equ 20h

LUID STRUCT
LowPart DWORD ?
HighPart DWORD ?
LUID ENDS


.DATA
;--msg txt
Text db 'info',0
nont db 'not nt',0
nt db 'nt',0
restartnow db 'restart now ?',0
error db 'error',0

;--Privilege
SSP db 'SeShutdownPrivilege',0

.data
handleProcess dd ?
hToken dd ?

tmpLuid LUID <>

.CODE
start:

call ShutdownNT

call ExitProcess ,0


ShutdownNT PROC
call GetVersion
cmp eax, 080000000h
jae @@NotNT

call GetCurrentProcess
mov handleProcess, eax

call OpenProcessToken,handleProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,OFFSET hToken
or eax, eax
jnz @@Question
jmp @@Error

@@Question:
call MessageBoxA,0,offset restartnow,offset Text,4
cmp eax,7
je @@DontShutdown

call ExitWindowsEx,1,0

call LookupPrivilegeValueA,0,OFFSET SSP,OFFSET tmpLuid
or eax, eax
jnz @@Error
ret

@@Error :
call MessageBoxA,0,offset error,offset Text,0
ret
@@NotNT:
call MessageBoxA,0,offset nont,offset Text,0
@@DontShutdown:
ret
EndP

ends
end start
Posted on 2002-03-05 18:31:41 by syntax_error
hmm, I don't know what LUID is, I checked your code and its fine to me. I haven't tried this shutdown thingy ever. Maybe their code doesn't work :) Try checking other sources. Also I noticed you forgot this part (Which I didn't convert) :



TOKEN_PRIVILEGES NewState;
LUID_AND_ATTRIBUTES luidattr;

NewState.PrivilegeCount = 1;
luidattr.Luid=tmpLuid;
luidattr.Attributes=SE_PRIVILEGE_ENABLED;
NewState.Privileges[0]=luidattr;

AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0);

if (GetLastError()!=0)
Application-> MessageBox("Adjust Token Privilage Error","Error",MB_OK);


this is after you call LookupPrivilegeValueA. :)
Posted on 2002-03-05 21:35:10 by stryker
hello stryker

meanwhile i found a sample src. from beytrayed i masm.
it looks similar to what you show me ,i port it to tasm...change invoke here and add there :)
but the same problem ,it wont work.
the exe inside the sample work.

i should go back to basic i think :-)

win2k is shit !!!
i code a file downloader where you can set the time the pc should shutdown ,now i own win2k and it wont work.
a whole day lost because those paranoid programmers :-(

anyway much thanks for your help.

ps: what should i do ?
i should delete the messagebox from the masm source ,compile it and execute it when time to shutdown is...hahaha
Posted on 2002-03-05 22:05:32 by syntax_error
Don't go back to BASIC. I too have problems in TASM, just try refining and check if there was an error on the code logic. It might seem it's correct but it's not. Try not to place that in a function, maybe it's the function thing that made it not work as intended it to be. I recalled creating an edit box using TASM during the handling of the WM_CREATE message, and to find out this doesn't work, it has to be after the call to RegisterClassEx...in MASM this works perfectly. Try to mix and match, eventually you'll get the desired result.

Should I say MASM :) Nah!!! TASM rules :) Oh! and I use win2k - veeery stable. You just have to code some more and redefine some code then it will work on win2k.

Good Luck!!!
Posted on 2002-03-05 22:16:02 by stryker
hello stryker,

thanks for the helpfull words :)
such thing helps sometime more then code snippets :-)
seeing that im not alone on my tasm quest helps a lot.

i ask myself often if i should change to masm.
moments like this...where a simple problem consume a lot time.
masm is more easy ,look in the board...full of masm snippets ,ready to test and functional.
or what others say about tasm : im half a virus coder because i use tasm ,how stupid !

if all jump from the bridge i wont jump after them so i stay and use tasm ,hard or not hard :-)

i feel that this board is more masm specific ,so thats why i ask Bogdan directly.
He often post Tasm src. here ,but seams to be in struggle at this time and not here :-)

why is there no tasm board ?
where is the tasm community ?
and why do i sit here and look at code what wont work ,i should go to take some hours sleep and then look again at it.
but if i go to bed i cant sleep because i think about the code ........ ahhhhh i make fresh coffee and then i fix this *$#/%&$? problem :-)

Sleep well and thanks
Posted on 2002-03-05 22:48:13 by syntax_error
I was not on the board for some time...

where is the code that offended you ? :)

i can not seem to find the link working...maybe you can email it to mee and i will see what is the problem, if there is still is one ...

nobody said TASM was easy just FAST... eh just kidding
Posted on 2002-03-06 16:42:30 by BogdanOntanu
Thank you BogdanOntanu,

i got alltime a error if i call LookupPrivilegeValueA,0,OFFSET SSP,OFFSET tmpLuid
im shure the settings i use from the windows.inc are wrong understanded by me.

<maybe you can email it to mee and i will see what is the problem, if there is still is one ...

Thanks for the Offer !!!
I mailed the source to you at saturday ,do you get it ?

Big Sorry for asking you to fix my code ,im shure you also had enough work :-)

THANKS !
Posted on 2002-03-11 02:35:18 by syntax_error
Posted on 2002-03-11 02:53:22 by bazik
syntax_error,

The problem is that many of the programmers here used to use TASM but Borland/Inprise no longer support it and in comparison to MASM, its a toothless terror that is out of date.

why is there no tasm board ?
where is the tasm community ?

The earlier forum used to have a TASM specific area but when the postings were coming in at about 100 to 1 for MASM as against TASM and NASM, there seemed to be little point in wasting the bandwidth.

You may have some luck with the older programmers here who have a background in TASM as well but the support and performance is with MASM.

Good luck with it.

hutch@movsd.com
Posted on 2002-03-11 03:33:06 by hutch--
Yes i have received your email and i will look over it when i will have the time ;)
Posted on 2002-03-11 04:58:15 by BogdanOntanu
Hello

Thank you bAZiK for the link :)
hope i learn from it what i made wrong.

hutch im sorry to hear that you allready try a tasm board where not much people post !
i search altavista ,dogpile + northernlight for tasm boards ,faq`s or tutorials.
all i found leads to here or iczelions page :)

i simply start with tasm because i know borland from other "good working" products.

@BogdanOntanu
Thank you :)
Posted on 2002-03-11 05:41:41 by syntax_error
one week later and i dont know why it wont work :(
i try to use it with&without procedure ,try different settings taken from different windows.inc files ,rewrite the code more then one time ,looking hours in the masm source and dont see the difference ,try hours to get the masm windows.inc file working in tasm...result : out of hash ....

the nasm source looks more weierd to me then the masm ,so i keep my fingers away from it :)

is there noone who use tasm and win2k who know how to shutdown my pc or how to use the masm.inc file or what is wrong with it ?

looks like i should make a big contest with big prices on this :)
but i run out of prices so i cant start a contest *hehe*

simple would be to use masm and rewrite my tasm code to masm ,but sounds for me like changing the flag like the wind is blown :(

better would be to understand why it wont work the way it work on masm.
Posted on 2002-03-16 06:35:54 by syntax_error
try the /kh# where # can be any number, this will solve that out of hash space problem - try increasing it to 100000

I use TASM under win2k. I would love to help but I'm way to busy with my homeworks and projects. If I have a time, I'll create one using TASM. :)
Posted on 2002-03-16 10:05:47 by stryker
i guess /kh32768 is the max, we use it in HE, after that one has to break app into smaller parts :(
Posted on 2002-03-17 08:25:49 by BogdanOntanu