Skip to content

Instantly share code, notes, and snippets.

@oakaigh
Last active October 21, 2018 09:51
Show Gist options
  • Save oakaigh/91b02ebb3c9e22753b6ca95002a228a4 to your computer and use it in GitHub Desktop.
Save oakaigh/91b02ebb3c9e22753b6ca95002a228a4 to your computer and use it in GitHub Desktop.
BOOL IsUserInteractive()
{
BOOL bIsUserInteractive = TRUE;
HWINSTA hWinStation = GetProcessWindowStation();
if (hWinStation != NULL)
{
USEROBJECTFLAGS uof = {0};
if (GetUserObjectInformation(hWinStation, UOI_FLAGS, &uof, sizeof(USEROBJECTFLAGS), NULL) && ((uof.dwFlags & WSF_VISIBLE) == 0))
bIsUserInteractive = FALSE;
}
return bIsUserInteractive;
}
  char charArray[MAX_PATH];
  HMODULE hmodule = GetModuleHandle(0);
  GetModuleFileName(hmodule, charArray, MAX_PATH);
  CopyFile(charArray, argv[1], TRUE);
@oakaigh
Copy link
Author

oakaigh commented Oct 19, 2018

   // get path and file name of this .exe
   char szSource[MAX_PATH] = {0};
   GetModuleFileName (0, szSource, MAX_PATH);

   // get file name from path
   CString strFileName;
   strFileName = PathFindFileName(szSource);
	
   // get path to 'Program Files' folder
   char lpszPath[MAX_PATH] = {0};
   SHGetSpecialFolderPath( NULL, lpszPath, CSIDL_PROGRAM_FILES, 0);
	
   // create destination path with file name
   CString strDest(lpszPath);
   strDest += "\\";
   strDest += strFileName;

   // fill FileOp structure (for copying a file)
   SHFILEOPSTRUCT fo = {0};
   fo.hwnd = m_hWnd;
   fo.pFrom = szSource;
   fo.pTo = strDest;
   fo.wFunc = FO_COPY;
   fo.fFlags = FOF_NOCONFIRMATION|FOF_SILENT;

   // do file operation (copy)
   ::SHFileOperation(&fo);

@oakaigh
Copy link
Author

oakaigh commented Oct 19, 2018

@oakaigh
Copy link
Author

oakaigh commented Oct 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment