InstDrv.cpp
资源名称:winio源码.zip [点击查看]
上传用户:ason123
上传日期:2010-03-31
资源大小:177k
文件大小:3k
源码类别:
并口编程
开发平台:
C++ Builder
- // ---------------------------------------------------- //
- // WinIo v2.0 //
- // Direct Hardware Access Under Windows 9x/NT/2000/XP //
- // Copyright 1998-2002 Yariv Kaplan //
- // http://www.internals.com //
- // ---------------------------------------------------- //
- #include <windows.h>
- #include "winio.h"
- bool _stdcall InstallWinIoDriver(PSTR pszWinIoDriverPath, bool IsDemandLoaded)
- {
- SC_HANDLE hSCManager;
- SC_HANDLE hService;
- // Remove any previous instance of the driver
- RemoveWinIoDriver();
- hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hSCManager)
- {
- // Install the driver
- hService = CreateService(hSCManager,
- "WINIO",
- "WINIO",
- SERVICE_ALL_ACCESS,
- SERVICE_KERNEL_DRIVER,
- (IsDemandLoaded == true) ? SERVICE_DEMAND_START : SERVICE_SYSTEM_START,
- SERVICE_ERROR_NORMAL,
- pszWinIoDriverPath,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- CloseServiceHandle(hSCManager);
- if (hService == NULL)
- return false;
- }
- else
- return false;
- CloseServiceHandle(hService);
- return true;
- }
- bool _stdcall RemoveWinIoDriver()
- {
- SC_HANDLE hSCManager;
- SC_HANDLE hService;
- bool bResult;
- StopWinIoDriver();
- hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hSCManager)
- {
- hService = OpenService(hSCManager, "WINIO", SERVICE_ALL_ACCESS);
- CloseServiceHandle(hSCManager);
- if (hService)
- {
- bResult = DeleteService(hService);
- CloseServiceHandle(hService);
- }
- else
- return false;
- }
- else
- return false;
- return bResult;
- }
- bool _stdcall StartWinIoDriver()
- {
- SC_HANDLE hSCManager;
- SC_HANDLE hService;
- bool bResult;
- hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hSCManager)
- {
- hService = OpenService(hSCManager, "WINIO", SERVICE_ALL_ACCESS);
- CloseServiceHandle(hSCManager);
- if (hService)
- {
- bResult = StartService(hService, 0, NULL) || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING;
- CloseServiceHandle(hService);
- }
- else
- return false;
- }
- else
- return false;
- return bResult;
- }
- bool _stdcall StopWinIoDriver()
- {
- SC_HANDLE hSCManager;
- SC_HANDLE hService;
- SERVICE_STATUS ServiceStatus;
- bool bResult;
- hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hSCManager)
- {
- hService = OpenService(hSCManager, "WINIO", SERVICE_ALL_ACCESS);
- CloseServiceHandle(hSCManager);
- if (hService)
- {
- bResult = ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus);
- CloseServiceHandle(hService);
- }
- else
- return false;
- }
- else
- return false;
- return bResult;
- }