Italia
Foro

Current Directory circa API ändern

 
Hallo alle zusammen...

Ich suche possibile viele Möglichkeiten, circa die Windows API das aktuelle Verzeichnis eines Prozesses zu ändern. Wer hat Ideen? Auch Ausgefallenes erwünscht...
 
25.08.2006  
 



Das aktuelle Verzeichnis gilt per alle Prozesse und kann man so setzen:
KompilierenMarkierenSeparieren
Oder meinst Du was anderes?
 
25.08.2006  
 



Ja, so was, bloß laut WIN32.HLP:
Each process has a single current directory made up of two parts:
Es wäre sehr schlimm, wenn alle Prozesse die gleiche Current Direktory hätten, denn bei LoadLibrary steht:
If a path is not specified and the filename extension is omitted, the default library extension .DLL is appended. However, the filename string can include a trailing point character (.) to indicate that the module name has no extension. When no path is specified, the function searches for the file in the following sequence:

1.The directory from which the application loaded.
2.The current directory.
3.Windows 95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32.

4.Windows NT only: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM.
5.The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6.The directories that are listed in the PATH environment variable.

Ich brauche possibile viele Möglichkeiten, den aktuellen Pfad zu ändern - hab was bestimmtes vor und suche was passendes - bzw. etwas was ich mir passend machen kann...
 
25.08.2006  
 



Jepp, wie gesagt - wenn dem so wäre, wäre das fatal...
 
25.08.2006  
 



Haste Recht, aber dabei ist zu bedenken, das der Pfad bei Aufruf circa Shell oder Verknüpfung, in der der Pfad nicht eingetragen wurde, dem zuletzt vom System verwendeten entspricht!
Das CurrentDirectory wird also nicht immer autom. auf den Pfad der Exe gesetzt, sondern nur bei Doppelclick, wenn Ausführen in im Link angegeben ist oder der Pfad bei ShellExecute mit angegeben wurde.
 
25.08.2006  
 



So, ich muß wohl doch sagen, wozu ich das brauche:
Ich möchte einen fremden Prozess dazu bringen - ohne Schreibrechte auf diesen Prozess zu besitzen - eine DLL zu laden.
Das geht nur, wenn ich die Current Directory dieses Prozesses ändere. Dafür benötige ich possibile eine API (evtl. einen Dialog), der als ersten Parameter ein Fensterhandle hat...
 
25.08.2006  
 




Frank
Abbing
Hab was gefunden, vielleicht bringt es dir was.
Testen werde ich morgen wieder per dich. Heute ist mir was dazwischen gekommen: Bin heute Onkel geworden


- Microsoft Win32 Software Development Kit (SDK) for Windows NT,
versions 3.1 and 3.5

SUMMARY

To find the filename of the program that created a given window under
Windows, you would use GetWindowLong(hWnd, GWL_HINSTANCE) to find the
module handle and then GetModuleFileName() to find the filename. This
method cannot be used under Windows NT because instance handles are not
global, but are unique to the address space in which the application is
running.

If the application that created the window is a Windows-based application,
the name returned is ntvdm. To get the actual filename, you need to spawn

a Win16 application that will call GetModuleFileName() and pass the
filename back to your application using some form of interprocess
communication (IPC).

MORE INFORMATION

To find the filename of an application once you have its window handle,
first use GetWindowThreadProcessId() to find the process ID (PID) of the
process that created the window. Using the PID, query the registry for the
performance data associated with the process. To do this, you have to
enumerate all processes in the system, comparing each PID to the PID of the
process that you are looking for, until the data for that process is found.
(This data includes the name of the process.)

The following sample code demonstrates how to find the filename of the
Program Manager, PROGMAN.EXE, after obtaining its window handle:

Sample Code
-----------

#include
#include
#include

#define Key SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Perflib\009

void GetIndex( char *, char * );
void DisplayFilename( DWORD );

/********************************************************************

* Function: void main( ) *
* *
* Purpose : Application entry point *
* *

void main( )
{
HWND hWnd;
DWORD dwActiveProcessId;

// Get window handle of Program Managers main window.

hWnd = FindWindow( Progman, NULL );

// Get PID of Program Manager.

GetWindowThreadProcessId( hWnd, &dwActiveProcessId );

// Display name of Program Managers executable file.

printf( Searching for filename of Program Manager...
);
DisplayFilename( dwActiveProcessId );
}

/********************************************************************
* Function: void DisplayFilename( DWORD ) *

* *
* Purpose : Display executable filename of the process whose PID *
* is passed in as a parameter. *
* *
* Comment : The information is retrieved from the performance *
* data in the registry. *
* *

void DisplayFilename( DWORD dwProcessId )
{
DWORD CurrentProcessId;
BOOL bContinue = TRUE;
char szIndex[256] = ;
DWORD dwBytes = 12000;
DWORD dwProcessIdOffset;
int i;

PPERF_DATA_BLOCK pdb;
PPERF_OBJECT_TYPE pot;
PPERF_INSTANCE_DEFINITION pid;
PPERF_COUNTER_BLOCK pcb;

PPERF_COUNTER_DEFINITION pcd;

// Get the index for the PROCESS object.
GetIndex( Process, szIndex );

// Get memory for PPERF_DATA_BLOCK.
pdb = (PPERF_DATA_BLOCK) HeapAlloc( GetProcessHeap(),
HEAP_ZERO_MEMORY,
dwBytes);

// Get performance data.
while( RegQueryValueEx(HKEY_PERFORMANCE_DATA, (LPTSTR)szIndex, NULL,
NULL, (LPBYTE)pdb, &dwBytes) ==

ERROR_MORE_DATA )
{
// Increase memory.
dwBytes += 1000;

// Allocated memory is too small; reallocate new memory.
pdb = (PPERF_DATA_BLOCK) HeapReAlloc( GetProcessHeap(),
HEAP_ZERO_MEMORY,
(LPVOID)pdb,
dwBytes);
}

// Get PERF_OBJECT_TYPE.
pot = (PPERF_OBJECT_TYPE)((PBYTE)pdb + pdb->HeaderLength);

// Get the first counter definition.
pcd = (PPERF_COUNTER_DEFINITION)((PBYTE)pot + pot->HeaderLength);

// Get index value for ID_PROCESS.
szIndex[0] = ;
GetIndex( ID Process, szIndex );

for( i=0; i< (int)pot->NumCounters; i++ )
{
if (pcd->CounterNameTitleIndex == (DWORD)atoi(szIndex))
{
dwProcessIdOffset = pcd->CounterOffset;
break;
}

pcd = ((PPERF_COUNTER_DEFINITION)((PBYTE)pcd + pcd->ByteLength));

}

// Get the first instance of the object.
pid = (PPERF_INSTANCE_DEFINITION)((PBYTE)pot + pot-
>DefinitionLength);

// Get the name of the first process.
pcb = (PPERF_COUNTER_BLOCK) ((PBYTE)pid + pid->ByteLength );
CurrentProcessId = *((DWORD *) ((PBYTE)pcb + dwProcessIdOffset));

// Find the process object for PID passed in, then print its
// filename.

for( i = 1; i < pot->NumInstances && bContinue; i++ )

{
if( CurrentProcessId == dwProcessId )
{
printf( The filename is %ls.exe.
,
(char *) ((PBYTE)pid + pid->NameOffset) );
bContinue = FALSE;
}
else
{
pid = (PPERF_INSTANCE_DEFINITION) ((PBYTE)pcb + pcb-
>ByteLength);
pcb = (PPERF_COUNTER_BLOCK) ((PBYTE)pid + pid->ByteLength);
CurrentProcessId = *((DWORD *)((PBYTE)pcb +
dwProcessIdOffset));

}
}
if( bContinue == TRUE )
printf( Not found. );

// Free the allocated memory.
if( !HeapFree(GetProcessHeap(), 0, (LPVOID)pdb) )
printf( HeapFree failed in main.
);

// Close handle to the key.
RegCloseKey( HKEY_PERFORMANCE_DATA );
}

/********************************************************************
* Function: void GetIndex( char *, char * ) *
* *

* Purpose : Get the index for the given counter *
* *
* Comment : The index is returned in the parameter szIndex *
* *

void GetIndex( char *pszCounter, char *szIndex )
{
char* pszBuffer;
char* pszTemp;
char szObject[256] = ;
DWORD dwBytes;
HANDLE hKeyIndex;

int i = 0;
int j = 0;

// Open the key.
RegOpenKeyEx( HKEY_LOCAL_MACHINE,
Key,
0, KEY_READ,
&hKeyIndex );

// Get the size of the counter.
RegQueryValueEx( hKeyIndex,
Counters,
NULL, NULL, NULL,
&dwBytes );

// Allocate memory for the buffer.
pszBuffer = (char *) HeapAlloc( GetProcessHeap(),

HEAP_ZERO_MEMORY,
dwBytes );

// Get the titles and counters.
RegQueryValueEx( hKeyIndex,
Counters,
NULL, NULL,
(LPBYTE)pszBuffer,
&dwBytes );

// Find the index value for PROCESS.
pszTemp = pszBuffer;

while( i != (int)dwBytes )
{
while (*(pszTemp+i) != )

{
szIndex[j] = *(pszTemp+i);
i++;
j++;
}
szIndex[j] = ;
i++;
j = 0;
while (*(pszTemp+i) != )
{
szObject[j] = *(pszTemp+i);
i++;
j++;
}
szObject[j] = ;
i++;
j = 0;
if( *(pszTemp+i) == )
i++;
if( strcmp(szObject, pszCounter) == 0 )
break;

}

// Deallocate the memory.
HeapFree( GetProcessHeap(), 0, (LPVOID)pszBuffer );

// Close the key.
RegCloseKey( hKeyIndex );
}

REFERENCES

For more information on working with the performance data, please see one
or all of the following references:

- The Win32 Programmers Reference.

- The Windows NT Resource Kit, volume 3.

- The source code for PView that is included in the Win32 SDK.

- The Windows/MS-DOS Developers Journal, April 1994.

Additional reference words: 3.10 3.50 file name
KBCategory: kbprg
KBSubcategory: BseMisc
 
25.08.2006  
 



Herzlichen Glückwunsch!
 
25.08.2006  
 




Frank
Abbing
Danke und Gute Nacht!
 
25.08.2006  
 



Answer


Topictitle, max. 100 characters.
 

Systemprofile:

Kein Systemprofil angelegt. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Bitte anmelden um einen Beitrag zu verfassen.
 

Topic-Options

1.475 Views

Untitledvor 0 min.
Gary1234513.06.2013
Andre Rohland13.03.2013

Themeninformationen

Dieses Thema hat 2 subscriber:

unbekannt (7x)
Frank Abbing (2x)


Admins  |  AGB  |  Applications  |  Autori  |  Chat  |  Informativa sulla privacy  |  Download  |  Entrance  |  Aiuto  |  Merchantportal  |  Impronta  |  Mart  |  Interfaces  |  SDK  |  Services  |  Giochi  |  Cerca  |  Support

Ein Projekt aller XProfaner, die es gibt!


Il mio XProfan
Private Notizie
Eigenes Ablageforum
Argomenti-Merkliste
Eigene Beiträge
Eigene Argomenti
Zwischenablage
Annullare
 Deutsch English Français Español Italia
Traduzioni

Informativa sulla privacy


Wir verwenden Cookies nur als Session-Cookies wegen der technischen Notwendigkeit und bei uns gibt es keine Cookies von Drittanbietern.

Wenn du hier auf unsere Webseite klickst oder navigierst, stimmst du unserer Erfassung von Informationen in unseren Cookies auf XProfan.Net zu.

Weitere Informationen zu unseren Cookies und dazu, wie du die Kontrolle darüber behältst, findest du in unserer nachfolgenden Datenschutzerklärung.


einverstandenDatenschutzerklärung
Ich möchte keinen Cookie