获得操作系统版本 r3


typedef enum tagWin32SysType{
 Windows32s,
 WindowsNT3,
 Windows95,
 Windows98,
 WindowsME,
 WindowsNT4,
 Windows2000,
 WindowsXP,
 WindowsVista,
 Windows7,
 Nothing
}Win32SysType;

 

HRESULT STDMETHODCALLTYPE
CVrvProtect::CqGetOsVerion()
{
 Win32SysType  ShellType = Nothing;
 DWORD winVer;
 OSVERSIONINFO *osvi;

 

 winVer = GetVersion();

 if( winVer < 0x80000000 )
 {/*NT */

  ShellType=WindowsNT3;
  osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));

  if( osvi != NULL )
  {
   memset(osvi,0,sizeof(OSVERSIONINFO));
   osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);

   if( FALSE == GetVersionEx(osvi) )
   {
    ShellType = Nothing;
    return ShellType;
   }

   if(osvi->dwMajorVersion==4L)ShellType = WindowsNT4;
   else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==0L)ShellType = Windows2000;
   else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==1L)ShellType = WindowsXP;
   else if(osvi->dwMajorVersion==6L&&osvi->dwMinorVersion==0L)ShellType = WindowsVista;
   else if(osvi->dwMajorVersion==6L&&osvi->dwMinorVersion==1L)ShellType = Windows7;

   free(osvi);
  }

 }
 else if( LOBYTE(LOWORD(winVer) ) < 4 )
 {
  ShellType = Windows32s;
 }

 else
 {

  ShellType = Windows95;

  osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));

  if (osvi!=NULL){

   memset(osvi,0,sizeof(OSVERSIONINFO));

   osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);

   if( FALSE == GetVersionEx(osvi) )
   {
    ShellType = Nothing;
    return ShellType;
   }

   if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==10L)ShellType = Windows98;

   else if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==90L)ShellType = WindowsME;

   free(osvi);

  }

 }

 return ShellType;
}

PB操作系统服务的简单例子,目前仅包含判断服务存在,取服务状态,停止和启动服务等 这个链接下,有功能较强的版本 http://download.csdn.net/source/3557823 FUNCTION ulong OpenSCManager(ref string lpMachineName,ref string lpDatabaseName,ulong dwDesiredAccess) LIBRARY "advapi32.dll" ALIAS FOR "OpenSCManagerA" FUNCTION ulong CreateService(ulong hSCManager,ref string lpServiceName,ref string lpDisplayName,ulong dwDesiredAccess,ulong dwServiceType,ulong dwStartType,ulong dwErrorControl,ref string lpBinaryPathName,ref string lpLoadOrderGroup,ref ulong lpdwTagId,ref string lpDependencies,ref string lp,ref string lpPassword) LIBRARY "advapi32.dll" ALIAS FOR "CreateServiceA" FUNCTION ulong DeleteService(ulong hService) LIBRARY "advapi32.dll" FUNCTION ulong CloseServiceHandle(ulong hSCObject) LIBRARY "advapi32.dll" FUNCTION ulong OpenService(ulong hSCManager,ref string lpServiceName,ulong dwDesiredAccess) LIBRARY "advapi32.dll" ALIAS FOR "OpenServiceA" FUNCTION ulong QueryServiceConfig(ulong hService,ref QUERY_SERVICE_CONFIG lpServiceConfig,ulong cbBufSize,ref ulong pcbBytesNeeded) LIBRARY "advapi32.dll" ALIAS FOR "QueryServiceConfigA" FUNCTION ulong QueryServiceConfig(ulong hService,ref query1 lpServiceConfig,ulong cbBufSize,ref ulong pcbBytesNeeded) LIBRARY "advapi32.dll" ALIAS FOR "QueryServiceConfigA" FUNCTION ulong QueryServiceStatus(ulong hService,ref SERVICE_STATUS lpServiceStatus) LIBRARY "advapi32.dll" FUNCTION ulong ControlService(ulong hService,ulong dwControl,ref SERVICE_STATUS lpServiceStatus) LIBRARY "advapi32.dll" FUNCTION ulong StartService(ulong hService,ulong dwNumServiceArgs,ulong lpServiceArgVectors) LIBRARY "advapi32.dll" ALIAS FOR "StartServiceA" FUNCTION ulong ChangeServiceConfig(ulong hService,ulong dwServiceType,ulong dwStartType,ulong dwErrorControl,ref string lpBinaryPathName,ref string lpLoadOrderGroup,ref ulong lpdwTagId,ref string lpDependencies,ref string lpServiceStartName,ref string lpPassword,ref string lpDisplayName) LIBRARY "advapi32.dll" ALIAS FOR "ChangeServiceConfigA" FUNCTION ulong EnumDepend
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值