74 lines
2.3 KiB
C
74 lines
2.3 KiB
C
#include <windows.h>
|
|
#include <stdio.h>
|
|
|
|
void copiarImagen() {
|
|
const char* origen = "img0.jpg";
|
|
const char* destinoDir = "C:\\Shared";
|
|
const char* destino = "C:\\Shared\\img0.jpg";
|
|
|
|
DWORD attr = GetFileAttributesA(origen);
|
|
if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
printf("🖼️ Copiando imagen institucional a %s...\n", destino);
|
|
CreateDirectoryA(destinoDir, NULL);
|
|
if (CopyFileA(origen, destino, FALSE)) {
|
|
printf("✅ Imagen copiada correctamente.\n");
|
|
} else {
|
|
printf("❌ Error al copiar la imagen.\n");
|
|
}
|
|
} else {
|
|
printf("⚠️ No se encontró \"%s\". Verifica que esté en la misma carpeta que este programa.\n", origen);
|
|
}
|
|
}
|
|
|
|
void ejecutarScripts(const char* extension) {
|
|
WIN32_FIND_DATAA findData;
|
|
HANDLE hFind;
|
|
char patron[MAX_PATH];
|
|
snprintf(patron, MAX_PATH, "Políticas\\*.%s", extension);
|
|
|
|
hFind = FindFirstFileA(patron, &findData);
|
|
if (hFind == INVALID_HANDLE_VALUE) return;
|
|
|
|
do {
|
|
char comando[MAX_PATH];
|
|
snprintf(comando, MAX_PATH, "cmd /c Políticas\\%s", findData.cFileName);
|
|
printf("----------------------------------------\n");
|
|
printf("▶ Ejecutando: %s\n", findData.cFileName);
|
|
system(comando);
|
|
} while (FindNextFileA(hFind, &findData));
|
|
|
|
FindClose(hFind);
|
|
}
|
|
|
|
int main() {
|
|
BOOL esAdmin = FALSE;
|
|
HANDLE hToken;
|
|
TOKEN_ELEVATION elevation;
|
|
DWORD size;
|
|
|
|
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
|
|
if (GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &size)) {
|
|
esAdmin = elevation.TokenIsElevated;
|
|
}
|
|
CloseHandle(hToken);
|
|
}
|
|
|
|
if (!esAdmin) {
|
|
printf("🔐 Requiere privilegios de administrador. Elevando...\n");
|
|
ShellExecuteA(NULL, "runas", GetCommandLineA(), NULL, NULL, SW_SHOWNORMAL);
|
|
return 0;
|
|
}
|
|
|
|
printf("================================\n");
|
|
printf("🚀 Ejecutando scripts en carpeta \"Políticas\"\n");
|
|
printf("================================\n\n");
|
|
|
|
copiarImagen();
|
|
ejecutarScripts("cmd");
|
|
ejecutarScripts("bat");
|
|
|
|
printf("\n✅ Todos los scripts han sido ejecutados.\n");
|
|
system("pause");
|
|
return 0;
|
|
}
|