Solved

Hide Application in Win9x/Nt Platforms without error

Posted on 2003-11-13
14
264 Views
Last Modified: 2010-04-05
I asked before how to hide my application from the task manager in Win9x and NT Platforms. All of the code worked BUT. When a run it on NT Platform the Win9x code seems to crash my application. What can I do to work on both Platforms withou crashing my Application. Thanx
0
Comment
Question by:fabyola
14 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 9739065
Hi,

procedure TForm1.Button1.Click(Sender: TObject);

  function isNT: Boolean;
  var
    osv: TOSVERSIONINFO;
  begin
    Result := false;
    osv.dwOSVersionInfoSize:=SizeOf(TOSVERSIONINFO);
    GetVersionEx(osv);
    if osv.dwPlatformId = VER_PLATFORM_WIN32_NT then result:= true;
  end;

begin
  if isNT then
  begin
    // place NT code here
  end else
  begin
    // place 9x code here
  end;
end;

Markus
0
 
LVL 17

Expert Comment

by:geobul
ID: 9739332
Or:

  if (GetVersion < $80000000) then begin
    ShowMessage('winNT family'); // your NT code here
  end else begin
    ShowMessage('win9x family'); // your Win9x code here
  end;

Regards, Geo
0
 

Author Comment

by:fabyola
ID: 9740250
But the problem is when I put in the Win9x code in the project, and when the application runs it crashes it. The application doesn´t even run. I need the a code that hides from the task manager in which it has both the Win9x and NT Platforms and it won´t crash the application.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:fabyola
ID: 9741550
The Crash happens right after i try to open the application.
0
 

Author Comment

by:fabyola
ID: 9747000
Nobody answered me. I guess this one is a tough one. I promise that who ever get´s this one for me I´ll increase the points to 225. I need this quick. Please
0
 
LVL 6

Accepted Solution

by:
DaFox earned 125 total points
ID: 9749098
Hi,

type
  TFNRegSvcPrc = function(dwProcessId: Cardinal; dwType: Cardinal): Cardinal; stdcall;

// ...

procedure TForm1.Button1.Click(Sender: TObject);

  function isNT: Boolean;
  var
    osv: TOSVERSIONINFO;
  begin
    Result := false;
    osv.dwOSVersionInfoSize:=SizeOf(TOSVERSIONINFO);
    GetVersionEx(osv);
    if osv.dwPlatformId = VER_PLATFORM_WIN32_NT then result:= true;
  end;

var
  RegisterServiceProcess: TFNRegSvcPrc;
begin
  if isNT then
  begin
    // place NT code here
  end else
  begin
    @RegisterServiceProcess := GetProcAddress(GetModuleHandle('KERNEL32'), 'RegisterServiceProcess');
    RegisterServiceProcess(0, 1);
  end;
end;

Markus
0
 
LVL 6

Expert Comment

by:pritaeas
ID: 9763195
Hi. This trick does NOT work on NT4. RegisterServiceProcess is not in the WinNT API's. The only way is to write an actual service.

hth, pritaeas
0
 
LVL 6

Expert Comment

by:DaFox
ID: 9763391
Hi,

>> This trick does NOT work on NT4. RegisterServiceProcess is not in the WinNT API's. The only way is to write an actual service.

This was fabyola's question:

"I asked BEFORE how to hide my application from the task manager in WIN9X AND NT PLATFORMS. ALL OF THE CODE WORKED BUT. When a run it on NT Platform the Win9x code seems to crash my application. What can I do to work on both Platforms withou crashing my Application."

He already has the code; 9x: RegisterServiceProcess(), NT: hook NtQuerySystemInformation()

This was my answer:

// cut

var
  RegisterServiceProcess: TFNRegSvcPrc;
begin
  if isNT then
  begin
    // this code gets executed if current OS is NT platform
  end else
  begin
    // this code gets executed if current OS is 9x/ME
    @RegisterServiceProcess := GetProcAddress(GetModuleHandle('KERNEL32'), 'RegisterServiceProcess');
    RegisterServiceProcess(0, 1);
  end;
end;

// cut

The problem with the code fabyola has is that he statically linked to kernel32.RegisterServiceProcess, but we have to link dynamically to it to not get an AV if running on NT platform. I never said that RegisterServiceProcess works in NT, it doesn't, and that's why I placed the function in the lower part of the if statement.

Markus
0
 

Author Comment

by:fabyola
ID: 9772125
What can I do to work on NT4 ???
0
 
LVL 6

Expert Comment

by:DaFox
ID: 9773086
Didn't you already accept the other question? I thought you already have the information...

Markus
0
 

Author Comment

by:fabyola
ID: 9780170
Is it the same way that I do in any NT platform. Windows 200/XP etc.. ?
0
 
LVL 6

Expert Comment

by:DaFox
ID: 9780392
Yes, on NT, 2000, XP, 2003 you have to hook NtQuerySystemInformation API. There's no other/easier way. Normally an application shouldn't hide itself from the process list, that's because MS made it that difficult for you.
It's the same for all NT platform operating systems.

Markus
0
 

Author Comment

by:fabyola
ID: 9818798
But what i want is to hide only from the task manager. Not in the process list. I made it hide it from tha task in Windows 200. Do you think that it would work in NT4 ?
0
 
LVL 6

Expert Comment

by:DaFox
ID: 9819645
What makes you think it doesn't work for the task manager in Windows NT? AFAIK it uses the same APIs for all NT platforms. If it works on W2k it should also work on NT4.

Markus
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question