函数参考


_WinAPI_GetProcessWorkingDirectory

Retrieves the current working directory for the specified process.

#Include <WinAPIEx.au3>
_WinAPI_GetProcessWorkingDirectory ( [$PID] )

参数

$PID [可选参数] The PID of the process. Default (0) is the current process.

返回值

Success The path to the working directory.
Failure Empty string and sets the @error flag to non-zero.

注意/说明

This function uses undocumented API functions and may stop working properly in future versions of Windows.

Using this function for some processes may require full access rights. Use _WinAPI_AdjustTokenPrivileges()
function to enable "SeDebugPrivilege" privilege before calling this function.

相关

详情参考

None

示例/演示


#RequireAdmin

#Include <APIConstants.au3>
#Include <Array.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hToken, $aAdjust, $aList = 0

; 为获取对其他进程的完全访问权限而启用 "SeDebugPrivilege" 特权
$hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))
_WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)

; 为系统上所有进程获取工作目录
If Not (@error Or @extended) Then
    $aList = ProcessList()
    For $i = 1 To $aList[0][0]
        $aList[$i][1] = _WinAPI_GetProcessWorkingDirectory($aList[$i][1])
    Next
EndIf

; 默认情况下启用 SeDebugPrivilege 特权
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)

_ArrayDisplay($aList, '_WinAPI_GetProcessCommandLine')