codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  finding the status of a service in windows  suresh_rtp at 05:23 on Tuesday, May 26, 2009
 

hi,
this is the that i was written for gettign the service status.i have some problem in this code.i am not able to getting the staus of the service.anybody have idea plaese help me.


DWORD ServiceGetStatus(char *sService)
{
SC_HANDLE schm;
SC_HANDLE schs;
LPSERVICE_STATUS TServiceStatus = NULL;
DWORD dwStat = -1;
//dwStat = -1;
// connect to the service control manager
//schm = OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
schm = OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
if(schm > 0)
{
schs = OpenService(schm,sService,SERVICE_QUERY_STATUS);

if(schs > 0)
{
if(QueryServiceStatus(schs,TServiceStatus))
{
dwStat = TServiceStatus->dwCurrentState;
CloseServiceHandle(schs);
CloseServiceHandle(schm);
}
std::cout<<"status is false"<<std::endl;
}
}
return dwStat;
}
int main()
{
DWORD status = 0;
const char machine[]="";
CHAR Service_Name[32];
strcpy(Service_Name,"Sundar_Service");
status = ServiceGetStatus(Service_Name);
if(status == 1)
std::cout<<"service stopped"<<std::endl;
if(status == 4)
std::cout<<"service is running"<<std::endl;
return 0;
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Javascript code please
•  Re: open excel file in html page
•  Help! Z-index problem with iframe and dropdown menu
•  Re: SQL Date
•  Bar chart not displayed mozilla but displayed in firefox while implemented dynamically in c#
•  issues with simplexml_load_string/SimpleXMLElement on PHP 5.1/Linux
•  Re: blank lines
•  Re: Help: Trouble with z-Index and SELECT lists
•  Need hosted_button_id value from PayPal generated code


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009