i try execute command to CMD, but it don't work
Includes:
#include <Windows.h>
#include <processthreadsapi.h>
#include <shellapi.h>
#include <stdio.h>
#include <iostream>
How i try open notepad:
ShellExecute(NULL, (LPCWSTR)"open", (LPCWSTR)"cmd", (LPCWSTR)"/c notepad.exe", NULL, SW_NORMAL);
This works
ShellExecute(NULL, L"open", L"cmd", L"/c notepad.exe", NULL, SW_NORMAL);
Don't use casts to remove compiler errors. The errors are telling you that you are using the wrong types, use the right types instead.
Related
I am trying to get all the system paths of windows. When reading this it says to use KNOWNFOLDERID. So I followed the example from here. When try to use that example I get a compilation error.
Test.cpp:
#include <tchar.h>
#include <sysinfoapi.h>
#include <Shlobj.h>
#include <combaseapi.h>
#include <WTypesbase.h>
#include <winnt.h>
int main() {
IKnownFolderManager *pManager;
HRESULT hr = CoCreateInstance(
CLSID_KnownFolderManager,
NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pManager)
);
}
This is what I have so far. The error I get is
error:
invalid static_cast from type 'IKnownFolderManager*' to type
'IUnknown*'
static_cast<IUnknown *> (*pp);
I am compiling from command line in windows 10 as: g++ test.cpp
IKnownFolderManager requires <Shobjidl.h>. Without that include, the compiler doesn't know how to cast IKnownFolderManager to IUnknown.
Here's the code:
AnsiString path = "BrowserBot.exe";
ShellExecute(0, TEXT("open"), path.c_str(), TEXT("-parametr"), 0, SW_SHOW);
Writes an error that the AnsiString identifier is not defined. I don't know what the problem is.
All connected libraries:
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <fstream>
#include <sstream>
AnsiString is a string class that is specific to the C++Builder compiler. If you are using that compiler, make sure you are compiling your project with C++Builder's VCL (Visual Component Library) or FMX (FireMonkey) framework enabled, and that you have a corresponding #include <vcl.h> or #include <fmx.h> statement in your C++ code.
Otherwise, if you are using any other compiler, you should use the standard C++ std::string class instead (which can also be used in C++Builder), eg:
#include <string>
std::string path = "BrowserBot.exe";
ShellExecuteA(0, "open", path.c_str(), "-parametr", 0, SW_SHOW);
How can I execute an EXE file in the appdata folder without knowing the username of the path c:\users\username ?
#include <stdio.h> // C library to perform Input/Output operations
#include <tchar.h>
#include <stddef.h> // C Standard definitions
#include <iostream> // Input/Output
#include <fstream>
#include <cstdlib>
#include <windows.h>
int main()
{
ShellExecute(NULL, "Open", "C:\\Users\\%USERNAME%\\AppData\\Roaming\\Microsoft\\mcv.exe", NULL, NULL, SW_HIDE);
}
You can use the Windows environment variable %APPDATA%, which resolves to "C:\Users\UserName\AppData\Roaming" on Windows 10.
More info on Windows variables here :
https://www.microsoft.com/en-us/wdsi/help/folder-variables
I've included the TlHelp32.h header properly though I keep getting the message:
"Error: identifier "CreateToolhelp32Snapshot" is undefined"
when attempting to use CreateToolhelp32Snapshot. When I used the "peek definition" feature in VS I found that there are errors within this header where in certain areas it says:
"Error expected a ';'"
Any ideas how to fix this?
#include "stdafx.h"
#include <TlHelp32.h>
#include <Windows.h>
#include <iostream>
using namespace std;
class Functions{
public:
void playerHealthPrinter(){
HANDLE hProcess;
DWORD dwPID, dwProtection, dwCaveAddress;
BOOL bPOn, bIOn, bProt;
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
Never include Win32 headers before <windows.h>. The following should work, instead:
#include <Windows.h>
#include <TlHelp32.h> // <-- include *after* windows.h
If it still doesn't work then please post an MCVE including the relevant headers and version of VS.
For some reason I am totally lost on this issues and been looking for an hour without any help.
in dev c++ I keep getting this error and it points to the line in [strong]bold[/strong]:
"18 H:\Projects\Classic Lockdown\main.cpp expected constructor, destructor, or type conversion before '(' token"
#define INFO_BUFFER_SIZE 32767
#include "iostream"
using namespace std;
#include <windows.h>
#include <gdiplus.h>
//#include <GdiPlusGetEncoderClsid.h>
#include <stdio.h>
HINSTANCE G_HINS_hInstance = 0;
#include "sstream"
#include "..\PWS_DEV\PWS_DEV.h"
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
//GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput,NULL);
Bitmap *gdiBitmap = 0;
#include "procedures.h"
why is it doing this?
I also wanted to see if I tried this instead
...
Gdiplus::GdiplusStartup = "";
...
and then I get this error instead:
"18 H:\Projects\Classic Lockdown\main.cpp expected constructor, destructor, or type conversion before '=' token"
not matter what I used with GdiplusStartup it just keeps saying that over and over. Its like it doesn't want anything to do with GdiplusStartup
I am very stuck on this. Can some one please help me out with this?
if you need any more info about this or the project i'm working on, please let me know.
Thank you
A couple of things jump out:
You have &m_gdiplusToken instead of &gdiplusToken (variable names don't match).
I assume the call to GdiplusStartup is in a function, right?
If I rearrange like this, it compiles fine with: cl.exe /EHsc so_test.cpp
Note I commented out headers I don't have. If it's still failing for you, you probalby have bad code in a header or you're not showing us everything.
#define INFO_BUFFER_SIZE 32767
#include "iostream"
using namespace std;
#include <windows.h>
#include <gdiplus.h>
//#include <GdiPlusGetEncoderClsid.h>
#include <stdio.h>
HINSTANCE G_HINS_hInstance = 0;
#include "sstream"
// #include "..\PWS_DEV\PWS_DEV.h"
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
//#include "procedures.h"
int main()
{
//GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,NULL);
Bitmap *gdiBitmap = 0;
return 0;
}