- // Try to open a named pipe; wait for it, if necessary
- while (1)
- {
- hPipe = CreateFileW(
- lpszPipeName, // pipe name
- dwDesiredAccess,
- 0, // no sharing
- NULL, // no security attributes
- OPEN_EXISTING, // opens existing pipe
- 0, // default attributes
- NULL); // no template file
-
- // Break if the pipe handle is valid
-
- if (hPipe != INVALID_HANDLE_VALUE)
- break;
-
- // Exit if an error other than ERROR_PIPE_BUSY occurs
-
- if (GetLastError() != ERROR_PIPE_BUSY)
- {
- return(NULL);
- }
-
- // All pipe instances are busy, so wait for 20 seconds
-
- if (!WaitNamedPipeW(lpszPipeName, 20000))
- {
- return(NULL);
- }
- }
-
- // The pipe connected; change to message-read mode
-
- dwMode = PIPE_READMODE_MESSAGE;
- fSuccess = SetNamedPipeHandleState(
- hPipe, // pipe handle
- &dwMode, // new pipe mode
- NULL, // don't set maximum bytes
- NULL); // don't set maximum time
- if (!fSuccess)
- {
- CloseHandle(hPipe);
- return(NULL);
- }
+ if(lpMachineName == NULL || wcslen(lpMachineName) == 0)
+ {
+ if(lpDatabaseName != NULL && wcscmp(lpDatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
+ { return(NULL); }
+
+ // Only connect to scm when event "SvcctrlStartEvent_A3725DX" is signaled
+ hStartEvent = OpenEvent(SYNCHRONIZE, FALSE, _T("SvcctrlStartEvent_A3725DX"));
+ if(hStartEvent == NULL)
+ {
+ SetLastError(ERROR_DATABASE_DOES_NOT_EXIST);
+ return (NULL);
+ }
+ dwWait = WaitForSingleObject(hStartEvent, INFINITE);
+ if(dwWait == WAIT_FAILED)
+ {
+ SetLastError(ERROR_ACCESS_DENIED);
+ return (NULL);
+ }
+ CloseHandle(hStartEvent);
+
+ // Try to open a named pipe; wait for it, if necessary
+ while(1)
+ {
+ hPipe = CreateFileW(lpszPipeName, // pipe name
+ dwDesiredAccess,
+ 0, // no sharing
+ NULL, // no security attributes
+ OPEN_EXISTING, // opens existing pipe
+ 0, // default attributes
+ NULL); // no template file
+
+ // Break if the pipe handle is valid
+ if(hPipe != INVALID_HANDLE_VALUE)
+ break;
+
+ // Exit if an error other than ERROR_PIPE_BUSY occurs
+ if(GetLastError()!= ERROR_PIPE_BUSY)
+ { return(NULL); }
+
+ // All pipe instances are busy, so wait for 20 seconds
+ if(!WaitNamedPipeW(lpszPipeName, 20000))
+ { return(NULL); }
+ }
+
+ // The pipe connected; change to message-read mode
+ dwMode = PIPE_READMODE_MESSAGE;
+ fSuccess = SetNamedPipeHandleState(
+ hPipe, // pipe handle
+ &dwMode, // new pipe mode
+ NULL, // don't set maximum bytes
+ NULL); // don't set maximum time
+ if(!fSuccess)
+ {
+ CloseHandle(hPipe);
+ return(NULL);
+ }