static void Shutdown() { CloseHandle(hAken); hAken = INVALID_HANDLE_VALUE; UninstallDriver(); }
BOOL PacketStopDriver60() { BOOL result; result = (BOOL) UninstallDriver(); return result; }
static void StartDriver(const OsPath& driverPathname) { const SC_HANDLE hSCM = OpenServiceControlManager(); if(!hSCM) { ENSURE(GetLastError() == ERROR_ACCESS_DENIED); SetLastError(0); return; } SC_HANDLE hService = OpenServiceW(hSCM, AKEN_NAME, SERVICE_ALL_ACCESS); // during development, we want to ensure the newest build is used, so // unload and re-create the service if it's running/installed. // as of 2008-03-24 no further changes to Aken are pending, so this is // disabled (thus also avoiding trouble when running multiple instances) #if 0 if(hService) { BOOL ok = CloseServiceHandle(hService); WARN_IF_FALSE(ok); hService = 0; UninstallDriver(); } #endif // create service (note: this just enters the service into SCM's DB; // no error is raised if the driver binary doesn't exist etc.) if(!hService) { LPCWSTR startName = 0; // LocalSystem // NB: Windows 7 seems to insist upon backslashes (i.e. external_file_string) hService = CreateServiceW(hSCM, AKEN_NAME, AKEN_NAME, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, OsString(driverPathname).c_str(), 0, 0, 0, startName, 0); ENSURE(hService != 0); } // start service { DWORD numArgs = 0; BOOL ok = StartService(hService, numArgs, 0); if(!ok) { if(GetLastError() != ERROR_SERVICE_ALREADY_RUNNING) { // starting failed. don't raise a warning because this // always happens on least-permission user accounts. //DEBUG_WARN_ERR(ERR::LOGIC); } } } CloseServiceHandle(hService); CloseServiceHandle(hSCM); }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { InstallDriver(); StartDriver(); hInst = hInstance; DialogBoxParam( hInstance, MAKEINTRESOURCE( IDD_MAIN ), NULL, DlgProc, WM_INITDIALOG ); UninstallDriver(); return 0; }
SERVICE_MANAGER_CONTEXT::~SERVICE_MANAGER_CONTEXT() { if (TRUE == Running) { StopDriverService(this); } _ASSERTE(TRUE != Running); if (TRUE == Installed) { UninstallDriver(this); } _ASSERTE(TRUE != Installed); DriverPath=L""; DriverServiceName=L""; DriverServiceDisplayName=L""; }
int main() { int action = 0; const char* prompt = "\nPlease enter action:\n" "0: Install driver\n" "1: Read data\n" "2: Write data\n" "3: IoControl driver\n" "4: Uninstall driver"; puts(prompt); const TCHAR* drv_name = _T("ObjNameGetter"); while (EOF != scanf("%d", &action)) { switch (action) { case Install: InstallDriver(drv_name); break; case Read: ReadDriver(); break; case Write: WriteDriver(); break; case Uninstall: UninstallDriver(drv_name); break; case IoControl: IoControlDriver(); break; default: ; } puts(prompt); } return 0; }
LONG __cdecl main(ULONG argc, CHAR *argv[]) { PCHAR command; int temp_n, temp_k; if(argc == 1) { PrintHelp(); return 0; } command = argv[1]; if(argc > 2) Args = argv + 2; else Args = NULL; ArgNum = argc - 2; if(!strcmp(command, "encode")) { temp_n = atoi(Args[0]); temp_k = atoi(Args[1]); if(temp_n < 1 || temp_n > 255 || temp_k < 1 || temp_k > 255) { printf("Parameters <n> and <k> must be positive integers between 1 and 255.\n"); return 1; } if(temp_n <= temp_k) { printf("<n> must be greater then <k>.\n"); return 1; } if(ArgNum == 2) { printf("Please specify the name of file to encode.\n"); return 1; } if(ArgNum == 3) { printf("Please specify the name of resulting file.\n"); return 1; } return CreateImage(Args[2], Args[3], (UCHAR)temp_n, (UCHAR)temp_k); } if(!strcmp(command, "test")) { temp_n = atoi(Args[0]); temp_k = atoi(Args[1]); printf("Testing %s with n = %d, k = %d\n", Args[2], temp_n, temp_k); return TestImage(Args[2], (UCHAR)temp_n, (UCHAR)temp_k); } if(!strcmp(command, "install")) return InstallDriver(); if(!strcmp(command, "uninstall")) return UninstallDriver(); printf("%s: unknown command. Read help:\n\n", command); PrintHelp(); return 0; }