Home > Back-end >  Is there any way to judge is by user double-click to open notepad, or point of TXT file open?
Is there any way to judge is by user double-click to open notepad, or point of TXT file open?

Time:10-03

As title, also have no a clue, do you have any good idea, thank you

CodePudding user response:

Know this have what use, some TXT open when parameters have a file name

CodePudding user response:

Access to the command line parameters, double-click the TXT file name parameters.
Shortcut to open no parameters

CodePudding user response:

If it is after. Double-click to open a TXT file to load. It is impossible to check out.

CodePudding user response:

By comparing the work directory and exe path, and can judge: not consistent, it must be opened by TXT, consistent by open notepad exe

CodePudding user response:

reference 1st floor tcmakebest response:
know this have what use, some TXT open when parameters have a file name

The key is how do I get other command line arguments of the program, thank you

CodePudding user response:

refer to the second floor wr960204 response:
command line parameters, double-click the TXT file name parameter.
Shortcut to open the no parameter

The key is how do I get other command line arguments of the program, master give some train of thought, thank you

CodePudding user response:

This function can get the other processes of command line arguments
//process Command line parameters, or False on failure, and returns an error in the Command information, 
//returns True on success, the process of the Command line and save parameter to the Command of
//For Win32 target process if it is 64 to failure
The function GetProcessCommandLine (dwPID: dwords. Var Command: String) : Boolean;
Var
D: DWORD;
HProcess, hThread: THandle;
PAddr: Pointer;
Buf: array [0.. MAX_PATH - 1] of WideChar;
The begin
Result:=False;
PAddr:=Windows. GetProcAddress call (Windows. GetModuleHandle (kernel32), 'GetCommandLineW');
If pAddr=NIL then begin
Command:=SysErrorMessage (GetLastError ());
exit;
end;
HProcess:=Windows. OpenProcess (PROCESS_CREATE_THREAD or PROCESS_VM_READ or PROCESS_QUERY_INFORMATION, False, dwPID);
If hProcess=0 then the begin
Command:=SysErrorMessage (GetLastError ());
exit;
end;
HThread:=Windows. CreateRemoteThread (hProcess, NIL, 0, pAddr, NIL, 0, D);
If hThread=0 then the begin
The CloseHandle (hProcess);
Command:=SysErrorMessage (GetLastError ());
exit;
end;
Windows. The WaitForSingleObject (hThread, 1000);
Windows. GetExitCodeThread (hThread, D);
FillChar (Buf, SizeOf (Buf), 0).
Windows. ReadProcessMemory (hProcess, Ptr (D), @ Buf, SizeOf (Buf), D);
Command:=Trim (Buf);
The CloseHandle (hProcess);
The CloseHandle (hThread);
end;

CodePudding user response:

 CloseHandle (hProcess); 
The CloseHandle (hThread);
Result:=True;//add the line
end;

CodePudding user response:

The Windows programming,

CodePudding user response:

This code returns refused to visit

The
reference 7 floor kiboisme response:
this function can be other processes of the command line parameter
//process Command line parameters, or False on failure, and returns an error in the Command information, 
//returns True on success, the process of the Command line and save parameter to the Command of
//For Win32 target process if it is 64 to failure
The function GetProcessCommandLine (dwPID: dwords. Var Command: String) : Boolean;
Var
D: DWORD;
HProcess, hThread: THandle;
PAddr: Pointer;
Buf: array [0.. MAX_PATH - 1] of WideChar;
The begin
Result:=False;
PAddr:=Windows. GetProcAddress call (Windows. GetModuleHandle (kernel32), 'GetCommandLineW');
If pAddr=NIL then begin
Command:=SysErrorMessage (GetLastError ());
exit;
end;
HProcess:=Windows. OpenProcess (PROCESS_CREATE_THREAD or PROCESS_VM_READ or PROCESS_QUERY_INFORMATION, False, dwPID);
If hProcess=0 then the begin
Command:=SysErrorMessage (GetLastError ());
exit;
end;
HThread:=Windows. CreateRemoteThread (hProcess, NIL, 0, pAddr, NIL, 0, D);
If hThread=0 then the begin
The CloseHandle (hProcess);
Command:=SysErrorMessage (GetLastError ());
exit;
end;
Windows. The WaitForSingleObject (hThread, 1000);
Windows. GetExitCodeThread (hThread, D);
FillChar (Buf, SizeOf (Buf), 0).
Windows. ReadProcessMemory (hProcess, Ptr (D), @ Buf, SizeOf (Buf), D);
Command:=Trim (Buf);
The CloseHandle (hProcess);
The CloseHandle (hThread);
end;

CodePudding user response:

reference 4 floor Avan_Lau response:
by comparing the work directory and exe path, can judge: inconsistencies must be opened by TXT, consistent by open notepad exe


Good idea
  • Related