In the application i've also got string name;
and that all works, i just don't know how to get it to take what is saved in that string and use it for the rule name & path.
i tried using %name% but it just comes up with the error, and without either % it just calls it name.
i basically want the user to be able to input the name of the firewall rule.
string a, specific, path, name;
std:string NAME = name;
std::string PATH = path;
What it gives as an error
error C2664: 'UINT WinExec(LPCSTR,UINT)': cannot convert argument 1 from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'LPCSTR'
message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
i've tried getenv() but i have no idea how to use it, tried something like. WinExec("netsh advfirewall firewall add rule name=" + getenv(name) + "enable=no action=block dir=in", SW_HIDE);
error C2664: 'UINT WinExec(LPCSTR,UINT)': cannot convert argument 1 from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'LPCSTR'
friend, you misread my example code :)
what you need is to call c_str() at the end, see my example again.
basically, you construct a string inside paranteses and then call c_str(), like the following working code:
1 2 3 4
string a, specific, path, name;
std:string NAME = name;
std::string PATH = path;
WinExec((std::string("netsh advfirewall firewall add rule name=") + name + "program=" + path + "enable=no action=block dir=in").c_str(), SW_HIDE);
note that variables need to have valid path names, not empty strings.
for example (note the escape \ character): string path = "C:\\path_to_my\\dir"
also, you will need to use, std::wstring for UNICODE strings