How to use C program to open a text file using Notepad?
-
Can someone help to give some tips? Why I compiled the program without error, yet it cannot open the notepad to see my text file : testedit.txt in the file folder c:\AHome. Thanks. #include #include void main() { system("cd C:\\Windows\\System32\notepad.exe c:\\AHome\testedit.txt "); return 0; }
Goh Kak Ng wrote:
...yet it cannot open the notepad to see my text file :
Aside from a few missing backslashes in the string literal, what's the problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Goh Kak Ng wrote:
...yet it cannot open the notepad to see my text file :
Aside from a few missing backslashes in the string literal, what's the problem?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
He also seems to have a spurious "cd..." at the start of his string. I'd guess that's what's causing his grief but my crystal ball is foggy :)
Mircea
-
Try:
system("C:\\Windows\\System32\\notepad.exe c:\\AHome\\testedit.txt ");
Mircea
Thanks for your reply ... I have try ...
system("C:\\Windows\\System32\notepad.exe c:\\AHome\testedit.text ");
The error massage is : 'C:\Windows\System32' is not recognized as Internal or External Command, Operable Program or Batch file.
-
He also seems to have a spurious "cd..." at the start of his string. I'd guess that's what's causing his grief but my crystal ball is foggy :)
Mircea
Thanks for your reply ... cd is " change of directory " to C:\Windows\System32 where notepad.exe is located.
-
Thanks for your reply ... I have try ...
system("C:\\Windows\\System32\notepad.exe c:\\AHome\testedit.text ");
The error massage is : 'C:\Windows\System32' is not recognized as Internal or External Command, Operable Program or Batch file.
You missed a backslash just before notepad.exe. You don't even really need the entire path to Notepad. This will work just fine:
system("notepad C:\\\\AHome\\\\testedit.text");
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Thanks for your reply ... cd is " change of directory " to C:\Windows\System32 where notepad.exe is located.
Quote:
cd is " change of directory "
I know, and it shouldn't be there.
Mircea
-
Thanks for your reply ... I have try ...
system("C:\\Windows\\System32\notepad.exe c:\\AHome\testedit.text ");
The error massage is : 'C:\Windows\System32' is not recognized as Internal or External Command, Operable Program or Batch file.
Goh Kak Ng wrote:
system("C:\\Windows\\System32\notepad.exe c:\\AHome\testedit.text ");
You missed one backslash in the path. It must be:
system("C:\\Windows\\System32\**\notepad.exe c:\\AHome\\**testedit.text ");
-
Goh Kak Ng wrote:
system("C:\\Windows\\System32\notepad.exe c:\\AHome\testedit.text ");
You missed one backslash in the path. It must be:
system("C:\\Windows\\System32\**\notepad.exe c:\\AHome\\**testedit.text ");
Yes. You are right! Try this work ...
system("C:\\Windows\\System32\\notepad.exe c:\\AHome\\testedit ");
Note that the test file name must be " testedit " and not " testedit.txt ". Otherwise, this file will not be found. Thanks!
-
Quote:
cd is " change of directory "
I know, and it shouldn't be there.
Mircea
Yes. you are right. cd should not be there. This is the right one ...
system("C:\\Windows\\System32\\notepad.exe c:\\A Home\\testedit ");
Thanks.
-
You missed a backslash just before notepad.exe. You don't even really need the entire path to Notepad. This will work just fine:
system("notepad C:\\\\AHome\\\\testedit.text");
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakMake sure you're not doing that from an elevated process. :) It's not quite DLL hijacking, but if an attacker could write a rogue
notepad.exe
into the%PATH%
somewhere, they could then get your process to launch it with elevated privileges.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Make sure you're not doing that from an elevated process. :) It's not quite DLL hijacking, but if an attacker could write a rogue
notepad.exe
into the%PATH%
somewhere, they could then get your process to launch it with elevated privileges.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
True :laugh:
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Make sure you're not doing that from an elevated process. :) It's not quite DLL hijacking, but if an attacker could write a rogue
notepad.exe
into the%PATH%
somewhere, they could then get your process to launch it with elevated privileges.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Could you help me to understand what do you mean by " elevated process "?
-
Could you help me to understand what do you mean by " elevated process "?
User Account Control (Windows 10) - Microsoft 365 Security | Microsoft Docs[^] How User Account Control works (Windows 10) - Microsoft 365 Security | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer