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
Related
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);
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.
trying to compile a file for class, using the mingw compiler on windows 10. Compiling with g++ gives me an error stating
\projectFile.o
mingw32-g++.exe -o D:\GitHub\GitRepo\projectFile.exe D:\GitHub\GitRepo\projectFile.o
D:\GitRepo\projectFile.cpp:16:20: fatal error: sys/uio.h: No such file or directory
compilation terminated.
From what ive read this header file
#include <sys/uio.h>
is a unix header and is generally included with most unix build environments. I am working on Windows 10 build and have been unsuccessful in trying to get this to work. Is there a work around for windows using different headers? Is there a while to install this file somehow?
The project is a generalized XML parser that as a student my job is to extract functions from the main file so that they can be reused (OOP design space)
#include <iostream>
#include <iterator>
#include <string>
#include <cstring>
#include <sys/types.h>
#include <sys/io.h>
#include <unistd.h>
#include <errno.h>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include "XMLParser.hpp"
Built on Windows 10 (lastest build) with Mingw-64 (lastest version)
This will not compile for me
This fixed my problem creating this uio.h file in sys directory of mingw64
#ifndef SYS_UIO_H
#define SYS_UIO_H
#include <inttypes.h>
#include <unistd.h>
struct iovec
{
void *iov_base; /* Base address of a memory region for input or output */
size_t iov_len; /* The size of the memory pointed to by iov_base */
};
ssize_t readv(int fildes, const struct iovec *iov, int iovcnt);
ssize_t writev(int fildes, const struct iovec *iov, int iovcnt);
#endif /* SYS_UIO_H */
In my case, I needed to call a powershell script from a c or c++ code source, found few links which were pretty clumsy and not good with c++, I simply want a roadmap if its possible invoking a powershell script which lists directory contents from a code snippet written in c or c++
C++ code :
#include<iostream>
#include <io.h> // For access().
#include <sys/types.h> // For stat().
#include <sys/stat.h> // For stat().
#include <string>
using namespace std;
void main()
{
string strPath = "d:\\callPowerShell.ps1";
//access function:
//The function returns 0 if the file has the given mode.
//The function returns –1 if the named file does not exist or does not have the given mode
if(access(strPath.c_str(),0) == 0)
{
system("start powershell.exe Set-ExecutionPolicy RemoteSigned \n");
system("start powershell.exe d:\\callPowerShell.ps1");
system("cls");
}
else
{
system("cls");
cout << "File is not exist";
system("pause");
}
}
First error :
#include <io.h> // For access().
access is in this lib:
#include <cstdlib>
Next :
error: 'system' was not declared in this scope
#include <unistd.h>
And finally :
The caractere '\' is a special caractere for C/C++ then you have to add another '\' like :
system("start powershell.exe C:\\users\\sqtk-mal\\script1.ps1");
In C++
#include <cstdlib>
std::system("command");
In c
#include <stdlib.h>
system("command");
I'm working on implementing DirectSound into a program, but it requires dsound.h which requires sal.h, and for whatever reason I'm having trouble getting g++ to recognize the fact that I have sal.h and it is in the path file and I can even type in the direct command sal.h and command prompt will open sal.h. But when I compile with
g++-3 World.cpp -c
I get
dsound.h:13:17: sal.h: No such file or directory.
followed by thousands of errors from dsound.h resulting from the lack of sal.h. I'm just using notepad, g++, and command prompt, do I need to be in VC++ for sal.h to work? Is there any way to use DirectSound without it?
Here's the opening to the code I'm compiling, just in case:
#include "WorldEntity.h"
#include "MBox.h"
#include <D3D9.h>
#include <d3dx9.h>
#include <string>
#include <sstream>
#define _USE_MATH_DEFINES
#include <math.h>
#define KEYDOWN(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code)((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
using namespace std;
World::World()
{
//Etc
Here is the beginning of WorldEntity.h, the included file that includes dsound.h:
#ifndef WORLDENTITY_H
#define WORLDENTITY_H
class Entity;
class HUD;
#include "Enums.h"
#include "Object.h"
#include "Inventory.h"
#include "AI.h"
#include "Item.h"
#include "Sector.h"
#include "MBox.h"
#include "Particle.h"
#include "Sprite.h"
#include <windows.h>
#include <windows.h>
#include <mmsystem.h>
#include <mmreg.h>
#include <dsound.h>
#include <string>
#include <D3D9.h>
#include <d3dx9.h>
#include <cstdlib>
#include <ctime>
using namespace std;
enum FontIndex
{
//Etc
The command path is not the same as the include path. You have to add the -I flag to GCC to tell it where to find header files:
g++-3 -IC:\some\path World.cpp -c