Hello Very simple problem I have here. If network share is found, open it in explorer. Else open LocalFolder1. If LocalFolder1 isn't found, open LocalFolder2. Current code; Code: #include <windows.h> #include <tchar.h> #include <iostream> int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) { ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL); return 0; } Please tell me how to use Programming Controllers within the above code. Thanks in advance, Panarchy
ShellExecute should return something based on the data opened successfully or not found kind of thing
Refer this Example Code: if(ShellExecute('Your Sample Params Above') == ERROR_PATH_NOT_FOUND) { Do something } else { Do some other thing }
Thanks for replying. Do you think the following code would work?; Code: if(ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL); == ERROR_PATH_NOT_FOUND) { ShellExecute(NULL, "explore", "C:\\Backup\sony\\", NULL, NULL, SW_SHOWNORMAL); } else { ShellExecute(NULL, "explore", "D:\\Backup\\", NULL, NULL, SW_SHOWNORMAL); } Tell me if you think it would work. Thanks in advance, Panarchy PS: The reason I can't test it myself is because I don't have any shares on my network. EDIT: Just tried it, did not work. Here is my complete log file;
Run and see if it works because at times return value is not always TRUE / FALSE which needs to be tested.
Hello Still not working for me. Have simplified it as much as I can, here is my complete code; Code: #include <windows.h> #include <tchar.h> #include <iostream> int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) { { ShellExecute(NULL, "explore", "C:\\Backup\\sony\\", NULL, NULL, SW_SHOWNORMAL); } else { ShellExecute(NULL, "explore", "D:\\Backup\\", NULL, NULL, SW_SHOWNORMAL); } return 0; } Please tell me how to make it work, as it is still giving me the following errors (can't compile the program cause of them); Please tell me how to get the program to work! Thanks in advance, Panarchy
There are lots of error of basic programming and not related to shell execute and I would try to point some of them Code: if(ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL); == ERROR_PATH_NOT_FOUND) In if statement we should not have a ; In the last post you have else without an if.
Thanks for replying. However, I still don't understand. Here is my latest code; Code: #include <windows.h> #include <tchar.h> #include <iostream> int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) { if(ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL); == ERROR_PATH_NOT_FOUND); else { ShellExecute(NULL, "explore", "D:\\Backup\\", NULL, NULL, SW_SHOWNORMAL); } return 0; } Doesn't compile properly. Have also tried putting { a line before and } a line after, to no avail. Please tell me how to get my code to work! For the end result I am wishing, there is 1 network (UNC) path & 2 local paths. Please help me reach my goal! Thanks in advance, Panarchy
It would not Code: if(ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL); == ERROR_PATH_NOT_FOUND); Should be Code: if(ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL) == ERROR_PATH_NOT_FOUND); So I guess you need to first get around your coding debug before you can attempt the errors in ShellExecute return things
Aha! The colon was in the wrong place. I'll try it now, thanks for the pointer! EDIT: Just gave it a go, got the following; ||=== Release ===| main.cpp||In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':| main.cpp|8|error: ISO C++ forbids comparison between pointer and integer| ||=== Build finished: 1 errors, 0 warnings ===| Should I be using a different IDE/compiler? (using Code::Blocks with MinGW gcc)
Well, the code is pretty much complete now; Code: #include <windows.h> #include <tchar.h> #include <iostream> #ifdef UNICODE #define tcout wcout #else #define tcout cout #endif int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) { STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0}; TCHAR lpCmdLine[MAX_PATH] = {0}; ::ExpandEnvironmentStrings(_T("\"%ProgramFiles%\\Symantec\\LiveUpdate\\LUALL.exe\""), lpCmdLine, MAX_PATH); std::tcout << _T("Command line : ") << lpCmdLine << std::endl; BOOL bRet = ::CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi); ShellExecute(NULL, TEXT("open"), TEXT("explorer"), TEXT("\\Panarchy\\share"), NULL, SW_HIDE); ShellExecute(NULL, TEXT("open"), TEXT("control"), TEXT("schedtasks\0"), NULL, SW_HIDE); ShellExecute(NULL, TEXT("open"), TEXT("control"), TEXT("sysdm.cpl"), NULL, SW_HIDE); ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_HIDE); { if( reinterpret_cast<int>(ShellExecute(NULL, "explore", "\\\\panarchy\\share", NULL, NULL, SW_SHOWNORMAL)) <= 32) if( reinterpret_cast<int>(ShellExecute(NULL, "explore", "D:\\BackYouUp\\", NULL, NULL, SW_SHOWNORMAL)) <= 32) { ShellExecute(NULL, "explore", "C:\\Backups\\bac\\", NULL, NULL, SW_SHOWNORMAL); } } return 0; } The only caveat is that it takes a while for the program to process the ifs. If anyone knows a way around that, I'd appreciate it. If not, then the program is complete. Panarchy
Yes, that is exactly what I don't understand. Please give me an example of it, if possible, within my complete code. Thanks in advance, Panarchy
I would still suggest you see the MSDN and read more about threads because it can be quite troublesome when dealing with threads. If you think you still need a sample refe Worker Threads in MFC and codes there but I am sure writing codes for threads needs a good knowledge before even attempting it.
Are we speaking about converting my program to a multi-threaded one, which will launch everything at once?