Mejor en C
En lugar de CMD, que sea en C.
This commit is contained in:
73
ejecutar_politicas.c
Normal file
73
ejecutar_politicas.c
Normal file
@@ -0,0 +1,73 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
@echo off
|
||||
setlocal enableextensions enabledelayedexpansion
|
||||
|
||||
:: ============================
|
||||
:: Verifica privilegios de administrador
|
||||
:: ============================
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
echo 🔐 Requiere privilegios de administrador. Elevando...
|
||||
powershell -Command "Start-Process '%~f0' -Verb runAs"
|
||||
exit /b
|
||||
)
|
||||
|
||||
echo ================================
|
||||
echo 🚀 Ejecutando scripts en carpeta "Políticas"
|
||||
echo ================================
|
||||
|
||||
:: ============================
|
||||
:: Copiar imagen institucional a C:\Shared
|
||||
:: ============================
|
||||
set "ORIGEN_IMG=img0.jpg"
|
||||
set "DESTINO_IMG=C:\Shared\img0.jpg"
|
||||
|
||||
if exist "%ORIGEN_IMG%" (
|
||||
echo 🖼️ Copiando imagen institucional a %DESTINO_IMG%...
|
||||
if not exist "C:\Shared" (
|
||||
mkdir "C:\Shared"
|
||||
)
|
||||
copy /Y "%ORIGEN_IMG%" "%DESTINO_IMG%" >nul
|
||||
echo ✅ Imagen copiada correctamente.
|
||||
) else (
|
||||
echo ⚠️ No se encontró "%ORIGEN_IMG%". Verifica que esté en la misma carpeta que este script.
|
||||
)
|
||||
|
||||
:: ============================
|
||||
:: Ejecutar scripts .cmd y .bat en /Políticas
|
||||
:: ============================
|
||||
set "CARPETA=Políticas"
|
||||
|
||||
if not exist "%CARPETA%" (
|
||||
echo ❌ La carpeta "%CARPETA%" no existe.
|
||||
pause
|
||||
exit /b
|
||||
)
|
||||
|
||||
for %%F in ("%CARPETA%\*.cmd" "%CARPETA%\*.bat") do (
|
||||
echo ----------------------------------------
|
||||
echo ▶ Ejecutando: %%~nxF
|
||||
call "%%F"
|
||||
)
|
||||
|
||||
echo ✅ Todos los scripts han sido ejecutados.
|
||||
pause
|
||||
Reference in New Issue
Block a user