yym吧 关注:14贴子:297
  • 3回复贴,共1

乔爷笑嘻嘻

只看楼主收藏回复

FBXLRM50ZPT7TZN8HCXKAWW7UYJPIVFR


1楼2011-02-27 23:45回复
    #define _WIN32_WINNT 0x0501                      /*Windows API版本*/
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <winbase.h>
    #include <Wincon.h>
    #include <tlhelp32.h>
    #include <malloc.h>
    #include <string.h>
    #include <direct.h>
    #include "WinShell.h"
    void ftime(FILETIME filetime)
    {
         SYSTEMTIME systemtime;
         if (filetime.dwLowDateTime==-1)
         {
             wprintf(L"Never Expires");
         }
         else
         {
             if (FileTimeToLocalFileTime(&filetime,&filetime)!=0)
             {
                 if (FileTimeToSystemTime(&filetime,&systemtime)!=0)
                 {
                     char str[50];
                     wsprintf(str,"%d-%02d-%02d %02d:%02d",systemtime.wYear,systemtime.wMonth,systemtime.wDay,systemtime.wHour,systemtime.wMinute);
                     printf("%s",str);
                 }
                 else
                 {
                     wprintf(L"FileTimeToSystemTime failed");
                 }
             }
             else
             {
                 wprintf(L"FileTimeToLocalFileTime failed");
             }
         }
    }
    void GetProcessList()
    {
         HANDLE hProcessSnap=NULL;
         PROCESSENTRY32 pe32={0};
         hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
         if (hProcessSnap==INVALID_HANDLE_VALUE)
             printf("\nCreateToolhelp32Snapshot() failed:%d",GetLastError());
         pe32.dwSize=sizeof(PROCESSENTRY32);
         if (Process32First(hProcessSnap,&pe32))
         {
    


    2楼2011-03-20 17:27
    回复
               DWORD dwPriorityClass;
               printf("\n优先级\t\t进程ID\t\t线程\t\t进程名\n");
               do{
                   HANDLE hProcess;
                   hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,pe32.th32ProcessID);
                   dwPriorityClass=GetPriorityClass(hProcess);
                   CloseHandle(hProcess);
                   printf("%d\t",pe32.pcPriClassBase);
                   printf("\t%d\t",pe32.th32ProcessID);
                   printf("\t%d\t",pe32.cntThreads);
                   printf("\t%s\n",pe32.szExeFile);
               }
               while (Process32Next(hProcessSnap,&pe32));
           }
           else
               printf("\nProcess32first() failed:%d",GetLastError());
           CloseHandle(hProcessSnap);
      }
      void add_history(char *inputcmd)
      {
           envhis.end=(envhis.end+1)%HISNUM;
           if (envhis.end==envhis.start)
           {
               envhis.start=(envhis.start+1)%HISNUM;
           }
           strcpy(envhis.his_cmd[envhis.end],inputcmd);
      }
      void history_cmd()
      {
           int i,j=1;
           if (envhis.start==envhis.end);
           else if (envhis.start<envhis.end)
           {
               for (i=envhis.start+1;i<=envhis.end;i++)
               {
                   printf("%d\t%s\n",j,envhis.his_cmd[i]);
                   j++;
               }
           }
           else
           {
               for (i=envhis.start+1;i<HISNUM;i++)
               {
                   printf("%d\t%s\n",j,envhis.his_cmd[i]);
                   j++;
               }
               for (i=0;i<=envhis.end+1;i++)
      


      3楼2011-03-20 17:27
      回复
                 {
                     printf("%d\t%s\n",j,envhis.his_cmd[i]);
                     j++;
                 }
             }
        }
        HANDLE process(int bg,char appName[])
        {
             STARTUPINFO si;
             PROCESS_INFORMATION pi;
             si.cb=sizeof(si);
             GetStartupInfo(&si);
             ZeroMemory(&pi,sizeof(pi));
             if (bg==0)
             {
                 if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
                 {
                     printf("Unable to install handler!\n");
                     return NULL;
                 }
                 CreateProcess(NULL,appName,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
                 return pi.hProcess;
             }
             else
             {
                 si.dwFlags=STARTF_USESHOWWINDOW;
                 si.wShowWindow=SW_HIDE;
                 CreateProcess(NULL,appName,NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
                 return NULL;
             }
        }
        BOOL killProcess(char *pid)
        {
             int id,i;
             DWORD dwExitStatus;
             HANDLE hprocess;
             id=atoi(pid);
             hprocess=OpenProcess(PROCESS_TERMINATE,FALSE,id);
             GetExitCodeProcess(hprocess,&dwExitStatus);
             if (i=TerminateProcess(hprocess,dwExitStatus))
                 return TRUE;
             else
                 return FALSE;
        }
        BOOL WINAPI ConsoleHandler(DWORD CEvent)
        {
             switch(CEvent)
             {
             case CTRL_C_EVENT:
                 break;
             case CTRL_BREAK_EVENT:
                 break;
             case CTRL_CLOSE_EVENT:
                 break;
             case CTRL_LOGOFF_EVENT:
                 break;
             case CTRL_SHUTDOWN_EVENT:
                 break;
             }
             return TRUE;
             }
        }


        4楼2011-03-20 17:27
        回复