Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Due to this got stuck in work. anybody is there??????

additional information copied from comments below
C++
/////////code////////
int ShowUsage();
void ShowProcessPackageFullName(const UINT32 pid, HANDLE process);

int ShowUsage()
{
   printf("Usage: GetPackageFullName <pid> [<pid>...]\n");
		
   return 1;
}

int main( )
{
   /*if (argc <= 1)*/
   ShowUsage();
   system("Pause");
   //for (int i=1; i<argc; (pid="" if="" 10);="" null,="" pid="wcstoul(argv[i]," uint32="" pid;="" {="" ++i)=""> 0)
   {

//      HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
//         PROCESS_VM_READ,
//         FALSE, processID );

//////enumrate all the process///////////
      DWORD aProcesses[1024], cbNeeded, cProcesses;
      unsigned int i;

      if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
      {
         return 1;
      }

      // Calculate how many process identifiers were returned.

      cProcesses = cbNeeded / sizeof(DWORD);
      HANDLE process = OpenProcess(PROCESS_ALL_ACCESS,FALSE, cProcesses);
			
      if (cProcesses == NULL)
         printf("Error %d in OpenProcess (pid=%u)\n", GetLastError(), cProcesses);
      else
      {
         ShowProcessPackageFullName(cProcesses, process);
         CloseHandle(process);
      }
   }
}
return 0;
}

void ShowProcessPackageFullName(UINT32 cProcesses, HANDLE process)
{
   printf("Process %d (handle=%p)\n", cProcesses, process);

//   HINSTANCE LoadME;
//   LoadME = LoadLibrary(L"Kernal32.dll");

   UINT32 length= 0;
   LONG rc = GetPackageFullName(process, &length, NULL);
   if (rc != ERROR_INSUFFICIENT_BUFFER)
   {
      if (rc == APPMODEL_ERROR_NO_PACKAGE)
         printf("Process has no package identity\n");
      else
         printf("Error %d in GetPackageFullName\n", rc);
      return;
   }

   PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName));
   if (fullName == NULL)
   {
      printf("Error allocating memory\n");
      return;
   }

   rc = GetPackageFullName(process, &length, fullName);
   if (rc != ERROR_SUCCESS)
      printf("Error %d retrieving PackageFullName\n", rc);
   else
      printf("%s\n", fullName);

   printf("%d\n", cProcesses);
	
   free(fullName);
}
Posted
Updated 7-Nov-14 7:26am
v2
Comments
Jochen Arndt 7-Nov-14 7:47am    
Error 87 is ERROR_INVALID_PARAMETER.
So you probably pass an invalid parameter to GetPackageFullName().
If you can't solve this yourself you must show us the relevant code.
I.P.Katti 7-Nov-14 7:52am    
/////////code////////
int ShowUsage();
void ShowProcessPackageFullName(const UINT32 pid, HANDLE process);

int ShowUsage()
{
printf("Usage: GetPackageFullName <pid> [<pid>...]\n");

return 1;
}

int main( )
{
/*if (argc <= 1)*/
ShowUsage();
system("Pause");
//for (int i=1; i<argc; ++i)
="" {
="" uint32="" pid;
="" pid="wcstoul(argv[i]," null,="" 10);
="" if="" (pid=""> 0)
{

// HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
// PROCESS_VM_READ,
// FALSE, processID );

//////enumrate all the process///////////
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;

if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 1;
}



// Calculate how many process identifiers were returned.

cProcesses = cbNeeded / sizeof(DWORD);

HANDLE process = OpenProcess(PROCESS_ALL_ACCESS,FALSE, cProcesses);

if (cProcesses == NULL)
printf("Error %d in OpenProcess (pid=%u)\n", GetLastError(), cProcesses);
else
{
ShowProcessPackageFullName(cProcesses, process);
CloseHandle(process);
}
}
}
return 0;
}

void ShowProcessPackageFullName(UINT32 cProcesses, HANDLE process)
{
printf("Process %d (handle=%p)\n", cProcesses, process);


// HINSTANCE LoadME;
// LoadME = LoadLibrary(L"Kernal32.dll");

UINT32 length= 0;
LONG rc = GetPackageFullName(process, &length, NULL);
if (rc != ERROR_INSUFFICIENT_BUFFER)
{
if (rc == APPMODEL_ERROR_NO_PACKAGE)
printf("Process has no package identity\n");
else
printf("Error %d in GetPackageFullName\n", rc);
return;
}

PWSTR fullName = (PWSTR) malloc(length * sizeof(*fullName));
if (fullName == NULL)
{
printf("Error allocating memory\n");
return;
}

rc = GetPackageFullName(process, &length, fullName);
if (rc != ERROR_SUCCESS)
printf("Error %d retrieving PackageFullName\n", rc);
else
printf("%s\n", fullName);
printf("%d\n", cProcesses);

free(fullName);
}
Nelek 7-Nov-14 13:21pm    
If you need to add or change content to your question or a previous solution, please use the "improve question / solution" instead of writing a lot of messages. It will keep readability and help other users with similar problems to find it faster.
Nelek 7-Nov-14 13:27pm    
I would strongly recommend you to ALWAYS use the brackets when cascading if, else, for... or whatever. You are having a "}" more than needed. Besides... it might be that some of your "printf" are being executed when they should not
I.P.Katti 8-Nov-14 0:58am    
if (argc <= 1)
return ShowUsage();
Till this line code is working fine,the argc value is 1. control is not going for loop condition.

 
Share this answer
 
Comments
I.P.Katti 7-Nov-14 7:20am    
if (rc != ERROR_INSUFFICIENT_BUFFER)
{
if (rc == APPMODEL_ERROR_NO_PACKAGE)
wprintf(L"Process has no package identity\n");
else
wprintf(L"Error %d in GetPackageFullName\n", rc);//this line i am facing error.but i created sufficient buffer for that and even package also there.
for more info:windows 8.1 os(trying to get windows store apps names like facebook messenger,skype etc)
Richard MacCutchan 7-Nov-14 7:23am    
Which error did you receive?
I.P.Katti 7-Nov-14 7:46am    
Error %d in GetPackageFullName(in place %d i got number 87).
------output----------
Usage: GetPackageFullName <pid> [<pid>...]
Press any key to continue . . .
Process 81 (handle=00000000)
Error 87 in GetPackageFullName
Press any key to continue . . .
Richard MacCutchan 7-Nov-14 7:58am    
And what does error 87 equate to? And what are the values of the parameters that you are passing in to this function? You need to use your debugger to collect all the relevant information.
I.P.Katti 7-Nov-14 8:14am    
LONG rc = GetPackageFullName(process, &length, NULL);
You should use the green 'Improve question' to add your code to the question rather than posting it as comment.

I tried to do it for you, but it can't be properly formatted (indented) because the code as posted in the comment would not compile by commenting the for loop.

However, you are doing
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS,FALSE, cProcesses);

passing cProcesses (number of processes) rather a valid process ID which results in an error 87.

You will not see this error after the above call because you are not checking your process variable there but your cProcesses variable!

Then you are passing the process variable (which is probably NULL) to GetPackageFullName resulting in another error 87.
 
Share this answer
 
Comments
I.P.Katti 8-Nov-14 0:58am    
if (argc <= 1)
return ShowUsage();
Till this line code is working fine,the argc value is 1. control is not going for loop condition.
Jochen Arndt 8-Nov-14 4:10am    
And where is the relation to your original question about error 87 and my answer?

If this is a new question you should create a new one rather than using comments. The IF condition is commented in your code snippet. When you uncomment it now and change other parts of the code, you must show that code. But not here because then the original question and problem may be no longer comprehendible.
I.P.Katti 8-Nov-14 4:28am    
ok thank you jochen Arndt.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900