MOPO3 |
Отправлено: 23.08.2004, 09:57 |
|
Ученик-кочегар
Группа: Участник
Сообщений: 22
|
После того как сервис должен стартовать, я его не вижу в Services
Вот код, подскажите что не так делаю ?
CODE |
#include <vcl.h>
#pragma hdrstop
#include "serip_main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
/**************************************/
HANDLE hDevice = INVALID_HANDLE_VALUE;
/**************************************/
TVirtSeripMon *VirtSeripMon;
//---------------------------------------------------------------------------
__fastcall TVirtSeripMon::TVirtSeripMon(TComponent* Owner)
: TForm(Owner)
{
// Proveriaem versiju Windows
OSVERSIONINFO os;
os.dwOSVersionInfoSize=sizeof(os);
GetVersionEx(&os);
if (os.dwPlatformId!=VER_PLATFORM_WIN32_NT)
{
Info->Font->Color = clBackground;
Info->Lines->Add("Program will work only on Windows NT platform...");
}else{
Info->Font->Color = clBackground;
Info->Lines->Add("OS checked!");
Info->Lines->Add("Programm should work normally...");
}
}
//---------------------------------------------------------------------------
void __fastcall TVirtSeripMon::ExitClick(TObject */*Sender*/)
{
if (hDevice!= INVALID_HANDLE_VALUE)
{
CloseHandle(hDevice);
SC_HANDLE sc = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
if (sc)
{
SC_HANDLE hSrv = OpenService(sc,"SeripSpy",SERVICE_START | SERVICE_STOP |DELETE);
CloseServiceHandle(sc);
if (hSrv)
{
SERVICE_STATUS ss;
ControlService(hSrv,SERVICE_CONTROL_STOP,&ss);
CloseServiceHandle(hSrv);
}
}
}
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TVirtSeripMon::StartClick(TObject */*Sender*/)
{
//Probuem otkrit nash devais
hDevice = CreateFile("\\\\.\\SeripSpy",
GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if (hDevice == INVALID_HANDLE_VALUE) // Nash devais ne prisutstvuet v sisteme
{
// Proveriaem prava dostupa
SC_HANDLE sc = OpenSCManager(NULL,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS);
if (!sc)
{
Info->Font->Color = clBackground;
Info->Lines->Add("Serip Spy cannot install device driver...");
Info->Lines->Add("You must have administrative privileges to install it...");
}
// Probuem najti devais
SC_HANDLE hSrv=OpenService(sc,"SeripSpy",SERVICE_START | SERVICE_STOP |DELETE);
CloseServiceHandle(sc);
if (!hSrv)
{
Info->Font->Color = clBackground;
Info->Lines->Add("Your system does not have SeripSpy device driver installed...");
Info->Lines->Add("Use button \"Install Device\" to install it...");
}else{
// Startuem ego
if (!StartService(hSrv,0,NULL))
{
Info->Font->Color = clBackground;
Info->Lines->Add("Unexpected error occured...");
Info->Lines->Add("SeripSpy device driver may be missing...");
CloseServiceHandle(hSrv);
}else{
CloseServiceHandle(hSrv);
hDevice=CreateFile("\\\\.\\SeripSpy",
GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
Info->Font->Color = clBackground;
Info->Lines->Add("Unexpected error occured...");
Info->Lines->Add("Cannot get access to SeripSpy device driver...");
}
Info->Font->Color = clBackground;
Info->Lines->Add("Loaded!");
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TVirtSeripMon::InstallClick(TObject */*Sender*/)
{
if (hDevice != INVALID_HANDLE_VALUE){ }
SC_HANDLE sc = OpenSCManager(NULL,SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
if (!sc)
{
Info->Lines->Add("!!! You must have administrative priviledges to install SeripSpy device driver !!!");
}
AnsiString s = GetCurrentDir();
s += "\\seripspy.sys";
Info->Lines->Add("Path : " + s);
SC_HANDLE hSrv = CreateService(sc,
"SeripSpy",
"SeripSpy",
SERVICE_ALL_ACCESS | GENERIC_EXECUTE | SERVICE_START | SERVICE_STOP,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE,
s.c_str(), NULL, NULL, NULL, NULL, NULL);
CloseServiceHandle(sc);
if (!hSrv)
{
Info->Lines->Add("Unexpected error. Cannot create service...");
if (!StartService(hSrv,0,NULL))
{
Info->Lines->Add("Cannot start device. SeripSpy.sys maybe not found!");
DeleteService(hSrv);
CloseServiceHandle(hSrv);
}
hDevice=CreateFile("\\\\.\\SeripSpy",
GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
SERVICE_STATUS ss;
ControlService(hSrv,SERVICE_CONTROL_STOP,&ss);
Info->Lines->Add("!!! SeripSpy ::: INVALID_HANDLE_VALUE !!!");
}
CloseServiceHandle(hSrv);
}
Info->Lines->Add("Serip Spy device driver successfully installed...");
}
//---------------------------------------------------------------------------
void __fastcall TVirtSeripMon::DeinstallClick(TObject */*Sender*/)
{
if (hDevice != INVALID_HANDLE_VALUE) {
CloseHandle(hDevice);
}
SC_HANDLE sc = OpenSCManager(NULL,SERVICES_ACTIVE_DATABASE,SC_MANAGER_ALL_ACCESS);
if (sc)
{
SC_HANDLE hSrv = OpenService(sc,"SeripSpy",SERVICE_START | SERVICE_STOP | DELETE);
CloseServiceHandle(sc);
if (hSrv)
{
SERVICE_STATUS ss;
ControlService(hSrv,SERVICE_CONTROL_STOP,&ss);
DeleteService(hSrv);
CloseServiceHandle(hSrv);
hDevice = INVALID_HANDLE_VALUE;
} else {
Application->MessageBox("Cannot remove Serip Spy device driver", "ERROR", MB_OK | MB_ICONERROR);
}
}
}
//---------------------------------------------------------------------------
| |
|
Gedeon |
Отправлено: 25.08.2004, 11:29 |
|
Ветеран
Группа: Модератор
Сообщений: 1742
|
А как вы его запускаете F9 что ли?
Нужно запустить экзешник с параметром /install тогда сервис появится в списке, а там уж запускайте.
|
|
|