Jump to content

how to separate a path and the commands Line from a file Full path


Recommended Posts

Hello
I have an inquiry from you
I have a file path  with commands line
Is there a way to separate the path from the commands line?
I want the result in an array
for example
$path = '"c:\NVDA\NVDA slav Portable 1\NVDA.exe" -r -m -path="d:\NVDA Path\Portable"'
there are any method to separate this text?
i want the result to be as that
$array[1] = "c:\NVDA\NVDA slav Portable 1\NVDA.exe"
$array[2] = '-r -m -path="d:\NVDA Path\Portable"'
Thanks in advance
am Waiting for your answers

Link to comment
Share on other sites

Where is this command line coming from? If it’s hard coded by you in your script then why can’t you parse it?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

What is the result of that function? What does it look like and how is it returned, string or array?

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Then isn’t it already separated? Give us some clue as to what you’re working with, you’re giving us it in tiny pieces.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

A lot would depend upon the command line for example:

  • Would the first path always be in quotes?
  • Would the command always include .exe?
  • Does the file exist on the local machine or are you reading the commands from another PCs log/registry etc...

Here is a basic example, which someone could probably do with RegEx (but not my forte).

#include <Array.au3>
Local $path = '"c:\NVDA\NVDA slav Portable 1\NVDA.exe" -r -m -path="d:\NVDA Path\Portable"'
Local $iCount = StringInStr($path, '.exe"', 0, 1)
Local $aArray[3] = [2, StringTrimRight($path, $iCount), StringRight($path, $iCount)]
_ArrayDisplay($aArray)

 

Link to comment
Share on other sites

it return a array
but not separated
for example if the program is running multiple times
$array[0] = number found
$array[1] = first path and commands line
$array[2] = second file path and commands line
...
can i edit it?
to be for example
$array[1][0] = first path
$array[1][1] = first path command line
I am waiting for your help

Link to comment
Share on other sites

Not really sure what you mean "but not separated", the code above returns the following array as you wanted in your original post?

$aArray[0] = 2
$aArray[1] = "c:\NVDA\NVDA slav Portable 1\NVDA.exe"
$aArray[2] = -r -m -path="d:\NVDA Path\Portable"

Link to comment
Share on other sites

Have a look at the example in the Help File for _WinAPI_GetProcessCommandLine and ProcessList.  It should give you a starting point.  Also, have a look at the _WinAPI_CommandLineToArgv function.

_WinAPI_GetProcessCommandLine()
ProcessList()
_WinAPI_CommandLineToArgv()

 

Adam

 

Link to comment
Share on other sites

i found this function

can any one tell me how to use it too to get the command line please?

this is the function

i copyed it from the include file

 

Func _WinAPI_GetProcessCommandLine($iPID = 0)
    If Not $iPID Then $iPID = @AutoItPID

    Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', (($__WINVER < 0x0600) ? 0x00000410 : 0x00001010), _
            'bool', 0, 'dword', $iPID)
    If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, '')

    $hProcess = $hProcess[0]

    Local $tPBI = DllStructCreate('ulong_ptr ExitStatus;ptr PebBaseAddress;ulong_ptr AffinityMask;ulong_ptr BasePriority;ulong_ptr UniqueProcessId;ulong_ptr InheritedFromUniqueProcessId')
    Local $tPEB = DllStructCreate('byte InheritedAddressSpace;byte ReadImageFileExecOptions;byte BeingDebugged;byte Spare;ptr Mutant;ptr ImageBaseAddress;ptr LoaderData;ptr ProcessParameters;ptr SubSystemData;ptr ProcessHeap;ptr FastPebLock;ptr FastPebLockRoutine;ptr FastPebUnlockRoutine;ulong EnvironmentUpdateCount;ptr KernelCallbackTable;ptr EventLogSection;ptr EventLog;ptr FreeList;ulong TlsExpansionCounter;ptr TlsBitmap;ulong TlsBitmapBits[2];ptr ReadOnlySharedMemoryBase;ptr ReadOnlySharedMemoryHeap;ptr ReadOnlyStaticServerData;ptr AnsiCodePageData;ptr OemCodePageData;ptr UnicodeCaseTableData;ulong NumberOfProcessors;ulong NtGlobalFlag;byte Spare2[4];int64 CriticalSectionTimeout;ulong HeapSegmentReserve;ulong HeapSegmentCommit;ulong HeapDeCommitTotalFreeThreshold;ulong HeapDeCommitFreeBlockThreshold;ulong NumberOfHeaps;ulong MaximumNumberOfHeaps;ptr ProcessHeaps;ptr GdiSharedHandleTable;ptr ProcessStarterHelper;ptr GdiDCAttributeList;ptr LoaderLock;ulong OSMajorVersion;ulong OSMinorVersion;ulong OSBuildNumber;ulong OSPlatformId;ulong ImageSubSystem;ulong ImageSubSystemMajorVersion;ulong ImageSubSystemMinorVersion;ulong GdiHandleBuffer[34];ulong PostProcessInitRoutine;ulong TlsExpansionBitmap;byte TlsExpansionBitmapBits[128];ulong SessionId')
    Local $tUPP = DllStructCreate('ulong AllocationSize;ulong ActualSize;ulong Flags;ulong Unknown1;ushort LengthUnknown2;ushort MaxLengthUnknown2;ptr Unknown2;ptr InputHandle;ptr OutputHandle;ptr ErrorHandle;ushort LengthCurrentDirectory;ushort MaxLengthCurrentDirectory;ptr CurrentDirectory;ptr CurrentDirectoryHandle;ushort LengthSearchPaths;ushort MaxLengthSearchPaths;ptr SearchPaths;ushort LengthApplicationName;ushort MaxLengthApplicationName;ptr ApplicationName;ushort LengthCommandLine;ushort MaxLengthCommandLine;ptr CommandLine;ptr EnvironmentBlock;ulong Unknown[9];ushort LengthUnknown3;ushort MaxLengthUnknown3;ptr Unknown3;ushort LengthUnknown4;ushort MaxLengthUnknown4;ptr Unknown4;ushort LengthUnknown5;ushort MaxLengthUnknown5;ptr Unknown5')
    Local $tCMD

    Local $aRet, $iError = 0
    Do
        $aRet = DllCall('ntdll.dll', 'long', 'NtQueryInformationProcess', 'handle', $hProcess, 'ulong', 0, 'struct*', $tPBI, _
                'ulong', DllStructGetSize($tPBI), 'ulong*', 0)
        If @error Or $aRet[0] Then
            $iError = @error + 30
            ExitLoop
        EndIf
        $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _
                'ptr', DllStructGetData($tPBI, 'PebBaseAddress'), 'struct*', $tPEB, _
                'ulong_ptr', DllStructGetSize($tPEB), 'ulong_ptr*', 0)
        If @error Or Not $aRet[0] Or (Not $aRet[5]) Then
            $iError = @error + 40
            ExitLoop
        EndIf
        $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _
                'ptr', DllStructGetData($tPEB, 'ProcessParameters'), 'struct*', $tUPP, _
                'ulong_ptr', DllStructGetSize($tUPP), 'ulong_ptr*', 0)
        If @error Or Not $aRet[0] Or (Not $aRet[5]) Then
            $iError = @error + 50
            ExitLoop
        EndIf
        $tCMD = DllStructCreate('byte[' & DllStructGetData($tUPP, 'MaxLengthCommandLine') & ']')
        If @error Then
            $iError = @error + 60
            ExitLoop
        EndIf
        $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, _
                'ptr', DllStructGetData($tUPP, 'CommandLine'), 'struct*', $tCMD, _
                'ulong_ptr', DllStructGetSize($tCMD), 'ulong_ptr*', 0)
        If @error Or Not $aRet[0] Or (Not $aRet[5]) Then
            $iError = @error + 70
            ExitLoop
        EndIf
    Until 1
    DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess)
    If $iError Then Return SetError($iError, 0, '')

    Return StringStripWS(_WinAPI_PathGetArgs(_WinAPI_GetString(DllStructGetPtr($tCMD, 1))), $STR_STRIPLEADING + $STR_STRIPTRAILING)
EndFunc   ;==>_WinAPI_GetProcessCommandLine

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...