?? ntenumpci.h
字號:
BOOL DeleteDriver(CString ServiceName)
{
SC_HANDLE hSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if( hSCManager==NULL)
{
AfxMessageBox("Could not open Service Control Manager");
return 0;
}
/////////////////////////////////////////////////////////////////////////
// Driver isn't there
SC_HANDLE hDriver = OpenService(hSCManager,ServiceName ,SERVICE_ALL_ACCESS);
/* if( hDriver!=NULL)
{
SERVICE_STATUS ss;
ControlService(hDriver,SERVICE_CONTROL_INTERROGATE,&ss);
{
if( ss.dwCurrentState!=SERVICE_STOPPED)
{
if( !ControlService(hDriver,SERVICE_CONTROL_STOP,&ss))
{
AfxMessageBox("Could not stop driver");
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return 0;
}
// Give it 10 seconds to stop
BOOL Stopped = FALSE;
for(int seconds=0;seconds<10;seconds++)
{
if( ControlService(hDriver,SERVICE_CONTROL_INTERROGATE,&ss) &&
ss.dwCurrentState==SERVICE_STOPPED)
{
Stopped = TRUE;
break;
}
Sleep(1000);
}
if( !Stopped)
{
AfxMessageBox("Could not stop driver");
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return 0;
}
}
}
}*/
if(!DeleteService(hDriver))
{
AfxMessageBox("Could not delete driver");
return 0;
}
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return 1;
}
char* CString_To_Pchar(CString str)
{
char* lpb=new char[str.GetLength()+1];
for(int i=0;i<str.GetLength();i++)
lpb[i]=str[i];
lpb[str.GetLength()]=0;
return lpb;
}
BOOL CreateDriver( CString ServiceName, CString DriverPath)
{
/////////////////////////////////////////////////////////////////////////
// Open service control manager
SC_HANDLE hSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if( hSCManager==NULL)
{
AfxMessageBox("Could not open Service Control Manager");
return FALSE;
}
/////////////////////////////////////////////////////////////////////////
// If driver is running, stop it
SC_HANDLE hDriver = OpenService(hSCManager,ServiceName,SERVICE_ALL_ACCESS);
/* if( hDriver!=NULL)
{
SERVICE_STATUS ss;
ControlService(hDriver,SERVICE_CONTROL_INTERROGATE,&ss);
{
if( ss.dwCurrentState!=SERVICE_STOPPED)
{
ControlService(hDriver,SERVICE_CONTROL_STOP,&ss);
// Give it 10 seconds to stop
BOOL Stopped = FALSE;
for(int seconds=0;seconds<10;seconds++)
{
Sleep(1000);
ControlService(hDriver,SERVICE_CONTROL_INTERROGATE,&ss);
if(ss.dwCurrentState==SERVICE_STOPPED)
{
Stopped = TRUE;
break;
}
}
if( !Stopped)
{
AfxMessageBox("Could not stop driver");
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return FALSE;
}
}
CloseServiceHandle(hDriver);
}
return TRUE;
}*/
/////////////////////////////////////////////////////////////////////////
// Create driver service
hDriver = CreateService(hSCManager,ServiceName,ServiceName,SERVICE_ALL_ACCESS,
SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,
DriverPath,NULL,NULL,NULL,NULL,NULL);
if( hDriver==NULL)
{
AfxMessageBox("Could not install driver with Service Control Manager");
CloseServiceHandle(hSCManager);
return FALSE;
}
/////////////////////////////////////////////////////////////////////////
CloseServiceHandle(hDriver);
CloseServiceHandle(hSCManager);
return TRUE;
}
BOOL StartDriver(CString ServiceName)
{
/////////////////////////////////////////////////////////////////////////
// Open service control manager
SC_HANDLE hSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if( hSCManager==NULL)
{
AfxMessageBox("Could not open Service Control Manager");
return FALSE;
}
/////////////////////////////////////////////////////////////////////////
// Driver isn't there
SC_HANDLE hDriver = OpenService(hSCManager,ServiceName,SERVICE_ALL_ACCESS);
if( hDriver==NULL)
{
AfxMessageBox("Could not open driver service");
CloseServiceHandle(hSCManager);
return FALSE;
}
SERVICE_STATUS ss;
ControlService(hDriver,SERVICE_CONTROL_INTERROGATE,&ss);
if(ss.dwCurrentState!=SERVICE_STOPPED)
{
AfxMessageBox("Could not interrogate driver service");
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return FALSE;
}
if( !StartService(hDriver,0,NULL))
{
AfxMessageBox("Could not start driver");
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return FALSE;
}
// Give it 10 seconds to start
BOOL Started = FALSE;
for(int seconds=0;seconds<10;seconds++)
{
if(ControlService(hDriver,SERVICE_CONTROL_INTERROGATE,&ss) &&
ss.dwCurrentState==SERVICE_RUNNING)
{
Started = TRUE;
break;
}
Sleep(1000);
}
if( !Started)
{
AfxMessageBox("Could not start driver");
CloseServiceHandle(hSCManager);
CloseServiceHandle(hDriver);
return FALSE;
}
CloseServiceHandle(hDriver);
CloseServiceHandle(hSCManager);
return TRUE;
}
BOOL GetDriverPath(CString& DriverPath)
{
TCHAR CurrentDirectory[MAX_PATH];
::GetCurrentDirectory(MAX_PATH,CurrentDirectory);
DriverPath.Format("%s\\Resource\\ENUMPCI.sys",CurrentDirectory);
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -