primeiro commit
This commit is contained in:
commit
fcefbbdc92
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
*.exe
|
||||||
|
var.h
|
||||||
|
*.txt
|
5
README.MD
Normal file
5
README.MD
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
funções do sistema:
|
||||||
|
- configurar pc com senhas de adm e conexão wi-fi
|
||||||
|
- backup/restore de drivers
|
||||||
|
- colocar no domínio
|
||||||
|
- instalar impressoras
|
209
config.cpp
Normal file
209
config.cpp
Normal file
|
@ -0,0 +1,209 @@
|
||||||
|
#include "var.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
//Cor verde
|
||||||
|
system("color a");
|
||||||
|
|
||||||
|
//strings do nome do computador
|
||||||
|
string patri = "";
|
||||||
|
string buffer = "";
|
||||||
|
|
||||||
|
//dados do arquivo de configuracao do wifi
|
||||||
|
string file_wifi_adm_data = "";
|
||||||
|
file_wifi_adm_data = "<WLANProfile xmlns='http://www.microsoft.com/networking/WLAN/profile/v1'><name>"+SSID_WIFI_ADM+"</name><SSIDConfig><SSID><hex>49464D532D50502D4D4151</hex><name>"+SSID_WIFI_ADM+"</name></SSID><nonBroadcast>true</nonBroadcast></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>"+PASSWORD_WIFI_ADM+"</keyMaterial></sharedKey></security></MSM><MacRandomization xmlns='http://www.microsoft.com/networking/WLAN/profile/v3'><enableRandomization>false</enableRandomization><randomizationSeed>3251268096</randomizationSeed></MacRandomization></WLANProfile>";
|
||||||
|
string file_wifi_acad_data = "";
|
||||||
|
file_wifi_acad_data = "<WLANProfile xmlns='http://www.microsoft.com/networking/WLAN/profile/v1'><name>"+SSID_WIFI_ACAD+"</name><SSIDConfig><SSID><hex>49464D532D50502D41434144454D49434F</hex><name>"+SSID_WIFI_ACAD+"</name></SSID><nonBroadcast>true</nonBroadcast></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>"+PASSWORD_WIFI_ACAD+"</keyMaterial></sharedKey></security></MSM><MacRandomization xmlns='http://www.microsoft.com/networking/WLAN/profile/v3'><enableRandomization>false</enableRandomization><randomizationSeed>879094211</randomizationSeed></MacRandomization></WLANProfile>";
|
||||||
|
|
||||||
|
//variavel que armazena o diretorio temp
|
||||||
|
const string path_temp = getenv("TEMP");
|
||||||
|
|
||||||
|
//caminho do arquivo de configuracao do wifi adm
|
||||||
|
string path_wifi_adm = path_temp;
|
||||||
|
path_wifi_adm += "\\IFMS-PP-MAQ.xml";
|
||||||
|
|
||||||
|
//caminho do arquivo de configuracao do wifi acad
|
||||||
|
string path_wifi_acad = path_temp;
|
||||||
|
path_wifi_acad += "\\IFMS-PP-ACADEMICO.xml";
|
||||||
|
|
||||||
|
//caminho do script
|
||||||
|
string path_ps1 = path_temp;
|
||||||
|
path_ps1 += "\\joinDomain.ps1";
|
||||||
|
|
||||||
|
int opt, cont;
|
||||||
|
|
||||||
|
int connect = 0;
|
||||||
|
int ping = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//ativando e alterando a senha dos usuarios locais
|
||||||
|
printf("Ativando o usuario ADMINISTRADOR!\n");
|
||||||
|
string str_user_adm_local_active = "";
|
||||||
|
str_user_adm_local_active = "cmd /c net user "+USER_ADM_LOCAL+" /active:yes";
|
||||||
|
system(str_user_adm_local_active.c_str());
|
||||||
|
|
||||||
|
printf("Alterando a senha do usuario ADMINISTRADOR!\n");
|
||||||
|
string str_pw_adm_local_set = "";
|
||||||
|
str_pw_adm_local_set = "cmd /c net user "+USER_ADM_LOCAL+" "+PASSWORD_ADM_LOCAL;
|
||||||
|
system(str_pw_adm_local_set.c_str());
|
||||||
|
|
||||||
|
printf("Alterando a senha do usuario SERTI!\n");
|
||||||
|
string str_pw_serti_local_set = "";
|
||||||
|
str_pw_serti_local_set = "cmd /c net user "+USER_SERTI_LOCAL+" "+PASSWORD_SERTI_LOCAL;
|
||||||
|
system(str_pw_serti_local_set.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nDeseja ingressar o PC em qual Dominio?\n1-ADMINISTRATIVO\n2-ACADEMICO\n0-NENHUM\nOpcao: ");
|
||||||
|
scanf("%d", &opt);
|
||||||
|
|
||||||
|
if(opt == 1){
|
||||||
|
printf("Adicionando a rede WI-FI %s\n", SSID_WIFI_ADM.c_str());
|
||||||
|
|
||||||
|
//cria o arquivo perfil xml
|
||||||
|
ofstream outfile (path_wifi_adm.c_str());
|
||||||
|
outfile << file_wifi_adm_data << endl;
|
||||||
|
outfile.close();
|
||||||
|
|
||||||
|
//conecta na rede wifi
|
||||||
|
string str_wifi_adm = "";
|
||||||
|
str_wifi_adm = "cmd /c netsh wlan add profile filename="+path_wifi_adm+" user=all";
|
||||||
|
system(str_wifi_adm.c_str());
|
||||||
|
|
||||||
|
//tenta conectar e testa a conexao com o ping
|
||||||
|
cont = 0;
|
||||||
|
string str_connect = "";
|
||||||
|
string str_ping = "";
|
||||||
|
do{
|
||||||
|
str_connect = "cmd /c netsh wlan connect "+SSID_WIFI_ADM;
|
||||||
|
connect = system(str_connect.c_str());
|
||||||
|
str_ping = "cmd /c ping -n 1 "+PING_ADM;
|
||||||
|
ping = system(str_ping.c_str());
|
||||||
|
if(cont > 0){
|
||||||
|
printf("\nTentativa %d de 5", cont+1);
|
||||||
|
Sleep(3000);
|
||||||
|
}else if(cont == 4){
|
||||||
|
printf("\nNAO FOI POSSIVEL SE CONECTAR!\n");
|
||||||
|
system("pause");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cont++;
|
||||||
|
}while(connect != 0 && ping != 0);
|
||||||
|
|
||||||
|
//exclui o arquivo xml
|
||||||
|
remove(path_wifi_adm.c_str());
|
||||||
|
|
||||||
|
//solicita ao usuario o numero de patrimonio
|
||||||
|
printf("\nAdicione o Numero do Patrimonio (Sem os 0s A ESQUERDA) ou Nome do Computador: ");
|
||||||
|
do{
|
||||||
|
cin >> buffer;
|
||||||
|
|
||||||
|
//verifica o tamanho do numero de patrimonio para completar
|
||||||
|
if(buffer.length() > 8){
|
||||||
|
printf("\nNo Maximo 8 digitos!!!\n");
|
||||||
|
}else{
|
||||||
|
patri = "PP-";
|
||||||
|
for(int i=0; i < 8-buffer.length(); i++){
|
||||||
|
patri += "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while(buffer.length() > 8);
|
||||||
|
patri += buffer;
|
||||||
|
|
||||||
|
//ativa script powershell
|
||||||
|
system("powershell Set-ExecutionPolicy RemoteSigned");
|
||||||
|
|
||||||
|
//cria o script powershell adm
|
||||||
|
string str_ps_adm = "";
|
||||||
|
str_ps_adm = "$usr = '"+USER_AD_ADM+"@"+DOMAIN_AD_ADM+"'\n$pw = '"+PASSWORD_AD_ADM+"' | ConvertTo-SecureString -asPlainText -Force\n$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName "+DOMAIN_AD_ADM+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=PP-Administrativo,OU=PP-Computadores,OU=PP-Outros,OU=IFMS-Outros,DC=ifms,DC=edu,DC=br'\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName "+DOMAIN_AD_ADM+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=PP-Administrativo,OU=PP-Computadores,OU=PP-Outros,OU=IFMS-Outros,DC=ifms,DC=edu,DC=br'}";
|
||||||
|
|
||||||
|
//cria arquivo powershell
|
||||||
|
ofstream outfile1 (path_ps1.c_str());
|
||||||
|
outfile1 << str_ps_adm << endl;
|
||||||
|
outfile1.close();
|
||||||
|
|
||||||
|
//executa powershell
|
||||||
|
// string execPs = "powershell " + path_ps1;
|
||||||
|
// system(execPs.c_str());
|
||||||
|
|
||||||
|
//deleta arquivo powershell
|
||||||
|
// remove(path_ps1.c_str());
|
||||||
|
|
||||||
|
}else if(opt == 2){
|
||||||
|
printf("Adicionando a rede WI-FI %s\n", SSID_WIFI_ACAD.c_str());
|
||||||
|
|
||||||
|
//cria o arquivo perfil xml
|
||||||
|
ofstream outfile (path_wifi_acad.c_str());
|
||||||
|
outfile << file_wifi_acad_data << endl;
|
||||||
|
outfile.close();
|
||||||
|
|
||||||
|
//conecta na rede wifi
|
||||||
|
string str_wifi_acad = "";
|
||||||
|
str_wifi_acad = "cmd /c netsh wlan add profile filename="+path_wifi_acad+" user=all";
|
||||||
|
system(str_wifi_acad.c_str());
|
||||||
|
|
||||||
|
//tenta conectar e testa a conexao com o ping
|
||||||
|
cont = 0;
|
||||||
|
string str_connect = "";
|
||||||
|
string str_ping = "";
|
||||||
|
do{
|
||||||
|
str_connect = "cmd /c netsh wlan connect "+SSID_WIFI_ACAD;
|
||||||
|
connect = system(str_connect.c_str());
|
||||||
|
str_ping = "cmd /c ping -n 1 "+PING_ACAD;
|
||||||
|
ping = system(str_ping.c_str());
|
||||||
|
if(cont > 0){
|
||||||
|
printf("\nTentativa %d de 5", cont+1);
|
||||||
|
Sleep(3000);
|
||||||
|
}else if(cont == 4){
|
||||||
|
printf("\nNAO FOI POSSIVEL SE CONECTAR!\n");
|
||||||
|
system("pause");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cont++;
|
||||||
|
}while(connect != 0 && ping != 0);
|
||||||
|
|
||||||
|
//exclui o arquivo xml
|
||||||
|
remove(path_wifi_acad.c_str());
|
||||||
|
|
||||||
|
//solicita ao usuario o numero de patrimonio
|
||||||
|
printf("\nAdicione o Numero do Patrimonio (SEM OS 0s A ESQUERDA e COM NO MAXIMO 8 DIGITOS): ");
|
||||||
|
do{
|
||||||
|
cin >> buffer;
|
||||||
|
|
||||||
|
//verifica o tamanho do numero de patrimonio para completar
|
||||||
|
if(buffer.length() > 8){
|
||||||
|
printf("\nNo Maximo 8 digitos!!!\n");
|
||||||
|
}else{
|
||||||
|
patri = "PP-";
|
||||||
|
for(int i=0; i < 8-buffer.length(); i++){
|
||||||
|
patri += "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while(buffer.length() > 8);
|
||||||
|
patri += buffer;
|
||||||
|
|
||||||
|
//ativa script powershell
|
||||||
|
system("powershell Set-ExecutionPolicy RemoteSigned");
|
||||||
|
|
||||||
|
//cria o script powershell adm
|
||||||
|
string str_ps_acad = "";
|
||||||
|
str_ps_acad = "$hostname = hostname\n$usr = '"+USER_AD_ACAD+"@"+DOMAIN_AD_ACAD+"'\n$pw = '"+PASSWORD_AD_ACAD+"' | ConvertTo-SecureString -asPlainText -Force\n$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName "+DOMAIN_AD_ACAD+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=Computadores,OU=IFMS-PP,DC=acad,DC=pp,DC=ifms,DC=edu,DC=br'\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName "+DOMAIN_AD_ACAD+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=Computadores,OU=IFMS-PP,DC=acad,DC=pp,DC=ifms,DC=edu,DC=br'}";
|
||||||
|
|
||||||
|
|
||||||
|
//cria arquivo powershell
|
||||||
|
ofstream outfile1 (path_ps1.c_str());
|
||||||
|
outfile1 << str_ps_acad << endl;
|
||||||
|
outfile1.close();
|
||||||
|
|
||||||
|
//executa powershell
|
||||||
|
string execPs = "powershell " + path_ps1;
|
||||||
|
system(execPs.c_str());
|
||||||
|
|
||||||
|
//deleta arquivo powershell
|
||||||
|
remove(path_ps1.c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
system("pause");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
225
configPC-Estag.cpp
Normal file
225
configPC-Estag.cpp
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
#include "var.h"
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
//Cor verde
|
||||||
|
system("color a");
|
||||||
|
|
||||||
|
//strings do nome do computador
|
||||||
|
string patri = "";
|
||||||
|
string buffer = "";
|
||||||
|
|
||||||
|
//dados do arquivo de configuracao do wifi
|
||||||
|
string file_wifi_adm_data = "";
|
||||||
|
file_wifi_adm_data = "<WLANProfile xmlns='http://www.microsoft.com/networking/WLAN/profile/v1'><name>"+SSID_WIFI_ADM+"</name><SSIDConfig><SSID><hex>49464D532D50502D4D4151</hex><name>"+SSID_WIFI_ADM+"</name></SSID><nonBroadcast>true</nonBroadcast></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>"+PASSWORD_WIFI_ADM+"</keyMaterial></sharedKey></security></MSM><MacRandomization xmlns='http://www.microsoft.com/networking/WLAN/profile/v3'><enableRandomization>false</enableRandomization><randomizationSeed>3251268096</randomizationSeed></MacRandomization></WLANProfile>";
|
||||||
|
string file_wifi_acad_data = "";
|
||||||
|
file_wifi_acad_data = "<WLANProfile xmlns='http://www.microsoft.com/networking/WLAN/profile/v1'><name>"+SSID_WIFI_ACAD+"</name><SSIDConfig><SSID><hex>49464D532D50502D4D4151</hex><name>"+SSID_WIFI_ACAD+"</name></SSID><nonBroadcast>true</nonBroadcast></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>"+PASSWORD_WIFI_ACAD+"</keyMaterial></sharedKey></security></MSM><MacRandomization xmlns='http://www.microsoft.com/networking/WLAN/profile/v3'><enableRandomization>false</enableRandomization><randomizationSeed>879094211</randomizationSeed></MacRandomization></WLANProfile>";
|
||||||
|
|
||||||
|
//variavel que armazena o diretorio temp
|
||||||
|
const string path_temp = getenv("TEMP");
|
||||||
|
|
||||||
|
//caminho do arquivo de configuracao do wifi adm
|
||||||
|
string path_wifi_adm = path_temp;
|
||||||
|
path_wifi_adm += "\\IFMS-PP-MAQ.xml";
|
||||||
|
|
||||||
|
//caminho do arquivo de configuracao do wifi acad
|
||||||
|
string path_wifi_acad = path_temp;
|
||||||
|
path_wifi_acad += "\\IFMS-PP-ACADEMICO.xml";
|
||||||
|
|
||||||
|
//caminho do script
|
||||||
|
string path_ps1 = path_temp;
|
||||||
|
path_ps1 += "\\joinDomain.ps1";
|
||||||
|
|
||||||
|
int opt, cont;
|
||||||
|
|
||||||
|
int connect = 0;
|
||||||
|
int ping = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//ativando e alterando a senha dos usuarios locais
|
||||||
|
printf("Ativando o usuario ADMINISTRADOR!\n");
|
||||||
|
string str_user_adm_local_active = "";
|
||||||
|
str_user_adm_local_active = "cmd /c net user "+USER_ADM_LOCAL+" /active:yes";
|
||||||
|
system(str_user_adm_local_active.c_str());
|
||||||
|
|
||||||
|
printf("Alterando a senha do usuario ADMINISTRADOR!\n");
|
||||||
|
string str_pw_adm_local_set = "";
|
||||||
|
str_pw_adm_local_set = "cmd /c net user "+USER_ADM_LOCAL+" "+PASSWORD_ADM_LOCAL;
|
||||||
|
system(str_pw_adm_local_set.c_str());
|
||||||
|
|
||||||
|
printf("Alterando a senha do usuario SERTI!\n");
|
||||||
|
string str_pw_serti_local_set = "";
|
||||||
|
str_pw_serti_local_set = "cmd /c net user "+USER_SERTI_LOCAL+" "+PASSWORD_SERTI_LOCAL;
|
||||||
|
system(str_pw_serti_local_set.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nDeseja ingressar o PC em qual Dominio?\n1-ADMINISTRATIVO\n2-ACADEMICO\n0-NENHUM\nOpcao: ");
|
||||||
|
scanf("%d", &opt);
|
||||||
|
|
||||||
|
if(opt == 1){
|
||||||
|
printf("Adicionando a rede WI-FI %s\n", SSID_WIFI_ADM.c_str());
|
||||||
|
|
||||||
|
//cria o arquivo perfil xml
|
||||||
|
ofstream outfile (path_wifi_adm.c_str());
|
||||||
|
outfile << file_wifi_adm_data << endl;
|
||||||
|
outfile.close();
|
||||||
|
|
||||||
|
//conecta na rede wifi
|
||||||
|
string str_wifi_adm = "";
|
||||||
|
str_wifi_adm = "cmd /c netsh wlan add profile filename="+path_wifi_adm+" user=all";
|
||||||
|
system(str_wifi_adm.c_str());
|
||||||
|
|
||||||
|
//tenta conectar e testa a conexao com o ping
|
||||||
|
cont = 0;
|
||||||
|
string str_connect = "";
|
||||||
|
string str_ping = "";
|
||||||
|
do{
|
||||||
|
str_connect = "cmd /c netsh wlan connect "+SSID_WIFI_ADM;
|
||||||
|
connect = system(str_connect.c_str());
|
||||||
|
str_ping = "cmd /c ping -n 1 "+PING_ADM;
|
||||||
|
ping = system(str_ping.c_str());
|
||||||
|
|
||||||
|
printf("\nTentativa %d de 5", cont+1);
|
||||||
|
Sleep(3000);
|
||||||
|
if(cont == 4){
|
||||||
|
printf("\nNAO FOI POSSIVEL SE CONECTAR!\n");
|
||||||
|
system("pause");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cont++;
|
||||||
|
}while(connect != 0 && ping != 0);
|
||||||
|
|
||||||
|
//exclui o arquivo xml
|
||||||
|
remove(path_wifi_adm.c_str());
|
||||||
|
|
||||||
|
printf("\nConectado com sucesso! Abra o navegador e acesse cp.pp.ifms.edu.br para autenticar!");
|
||||||
|
|
||||||
|
printf("\nAdicione ao domínio MANUALMENTE!");
|
||||||
|
|
||||||
|
//solicita ao usuario o numero de patrimonio
|
||||||
|
/*printf("\nAdicione o Numero do Patrimonio (Sem os 0s A ESQUERDA) ou Nome do Computador: ");
|
||||||
|
do{
|
||||||
|
cin >> buffer;
|
||||||
|
|
||||||
|
//verifica o tamanho do numero de patrimonio para completar
|
||||||
|
if(buffer.length() > 8){
|
||||||
|
printf("\nNo Maximo 8 digitos!!!\n");
|
||||||
|
}else{
|
||||||
|
patri = "PP-";
|
||||||
|
for(int i=0; i < 8-buffer.length(); i++){
|
||||||
|
patri += "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while(buffer.length() > 8);
|
||||||
|
patri += buffer;
|
||||||
|
|
||||||
|
//ativa script powershell
|
||||||
|
system("powershell Set-ExecutionPolicy RemoteSigned");
|
||||||
|
|
||||||
|
//cria o script powershell adm
|
||||||
|
string str_ps_adm = "";
|
||||||
|
str_ps_adm = "$usr = '"+USER_AD_ADM+"@"+DOMAIN_AD_ADM+"'\n$pw = '"+PASSWORD_AD_ADM+"' | ConvertTo-SecureString -asPlainText -Force\n$creds = New-Object System.Management.Automation.PSCredential($usr,$pw)\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName "+DOMAIN_AD_ADM+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=PP-Administrativo,OU=PP-Computadores,OU=PP-Outros,OU=IFMS-Outros,DC=ifms,DC=edu,DC=br'\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName "+DOMAIN_AD_ADM+" -Credential $creds -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=PP-Administrativo,OU=PP-Computadores,OU=PP-Outros,OU=IFMS-Outros,DC=ifms,DC=edu,DC=br'}";
|
||||||
|
|
||||||
|
//cria arquivo powershell
|
||||||
|
ofstream outfile1 (path_ps1.c_str());
|
||||||
|
outfile1 << str_ps_adm << endl;
|
||||||
|
outfile1.close();
|
||||||
|
|
||||||
|
//executa powershell
|
||||||
|
// string execPs = "powershell " + path_ps1;
|
||||||
|
// system(execPs.c_str());
|
||||||
|
|
||||||
|
//deleta arquivo powershell
|
||||||
|
// remove(path_ps1.c_str());
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
}else if(opt == 2){
|
||||||
|
printf("Adicionando a rede WI-FI %s\n", SSID_WIFI_ACAD.c_str());
|
||||||
|
|
||||||
|
//cria o arquivo perfil xml
|
||||||
|
ofstream outfile (path_wifi_acad.c_str());
|
||||||
|
outfile << file_wifi_acad_data << endl;
|
||||||
|
outfile.close();
|
||||||
|
|
||||||
|
//conecta na rede wifi
|
||||||
|
string str_wifi_acad = "";
|
||||||
|
str_wifi_acad = "cmd /c netsh wlan add profile filename="+path_wifi_acad+" user=all";
|
||||||
|
system(str_wifi_acad.c_str());
|
||||||
|
|
||||||
|
//tenta conectar e testa a conexao com o ping
|
||||||
|
cont = 0;
|
||||||
|
string str_connect = "";
|
||||||
|
string str_ping = "";
|
||||||
|
do{
|
||||||
|
str_connect = "cmd /c netsh wlan connect "+SSID_WIFI_ACAD;
|
||||||
|
connect = system(str_connect.c_str());
|
||||||
|
str_ping = "cmd /c ping -n 1 "+PING_ACAD;
|
||||||
|
ping = system(str_ping.c_str());
|
||||||
|
|
||||||
|
printf("\nTentativa %d de 5", cont+1);
|
||||||
|
Sleep(3000);
|
||||||
|
|
||||||
|
if(cont == 4){
|
||||||
|
printf("\nNAO FOI POSSIVEL SE CONECTAR!\n");
|
||||||
|
system("pause");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cont++;
|
||||||
|
}while(connect != 0 && ping != 0);
|
||||||
|
|
||||||
|
printf("\nConectado com sucesso! Abra o navegador e acesse pa.pp.ifms.edu.br para autenticar!");
|
||||||
|
|
||||||
|
//exclui o arquivo xml
|
||||||
|
remove(path_wifi_acad.c_str());
|
||||||
|
|
||||||
|
//solicita ao usuario o numero de patrimonio
|
||||||
|
printf("\nAdicione o Numero do Patrimonio ou Numero de Serie (SEM OS 0s A ESQUERDA e COM NO MAXIMO 8 DIGITOS): ");
|
||||||
|
do{
|
||||||
|
cin >> buffer;
|
||||||
|
|
||||||
|
//verifica o tamanho do numero de patrimonio para completar
|
||||||
|
if(buffer.length() > 8){
|
||||||
|
printf("\nNo Maximo 8 digitos!!!\n");
|
||||||
|
}else{
|
||||||
|
patri = "PP-";
|
||||||
|
for(int i=0; i < 8-buffer.length(); i++){
|
||||||
|
patri += "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while(buffer.length() > 8);
|
||||||
|
patri += buffer;
|
||||||
|
cout << "\nNovo nome do computador: " << patri << endl;
|
||||||
|
|
||||||
|
//ativa script powershell
|
||||||
|
system("powershell Set-ExecutionPolicy RemoteSigned");
|
||||||
|
|
||||||
|
//cria o script powershell acad
|
||||||
|
string str_ps_acad = "";
|
||||||
|
str_ps_acad = "$computerName = '" + patri+ "'\n$hostname = hostname \n$domain = '"+DOMAIN_AD_ACAD+"' \n$username = \"$domain"+ "\\" +USER_AD_ACAD+"\"\n$password = '"+PASSWORD_AD_ACAD+"' \n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)\n$ldapConn = New-Object DirectoryServices.DirectoryEntry (\"LDAP://$domain\", $username, $password)\n$searcher = New-Object DirectoryServices.DirectorySearcher\n$searcher.SearchRoot = $ldapConn\n$searcher.Filter = \"(&(objectCategory=computer)(cn=$computerName))\"\n$result = $searcher.FindOne()\nif ($result) {\n$computerObject = $result.GetDirectoryEntry()\ntry {\n$computerObject.DeleteTree()\n$computerObject.CommitChanges()\n Write-Host 'Computador '$computerName' deletado com sucesso.'\n} catch {\nWrite-Host 'Erro ao deletar o computador: $_'\n}\n}\nelse{\nWrite-Host 'Computador '$computerName' não encontrado.'\n}\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName $domain -Credential $credential -Force\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName $domain -Credential $credential -Force}";
|
||||||
|
|
||||||
|
//str_ps_acad = "$hostname = hostname \n$domain = '"+DOMAIN_AD_ACAD+"' \n$username = '$domain"+ "\\" +USER_AD_ACAD+"'\n$password = '"+PASSWORD_AD_ACAD+"' \n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)\nif ( $hostname -eq '"+patri+"' ){\nAdd-Computer -DomainName $domain -Credential $credential -Force -OUPath 'OU=Computadores,OU=IFMS-PP,DC=acad,DC=pp,DC=ifms,DC=edu,DC=br'\n}else {\nRename-Computer -NewName '"+patri+"'\nSleep 5\nAdd-Computer -DomainName $domain -Credential $credential -Force -Options JoinWithNewName,AccountCreate -OUPath 'OU=Computadores,OU=IFMS-PP,DC=acad,DC=pp,DC=ifms,DC=edu,DC=br'}";
|
||||||
|
//str_ps_acad = "Rename-Computer -NewName "+ patri +"\n$domain = '"+DOMAIN_AD_ACAD+"'\n$username = '$domain"+ "\\" +USER_AD_ACAD+"'\n$password = '"+PASSWORD_AD_ACAD+"'\n$securePassword = ConvertTo-SecureString $password -AsPlainText -Force\n$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)\nAdd-Computer -DomainName $domain -Credential $credential -Force -Restart";
|
||||||
|
|
||||||
|
//cria arquivo powershell
|
||||||
|
ofstream outfile1 (path_ps1.c_str());
|
||||||
|
outfile1 << str_ps_acad << endl;
|
||||||
|
outfile1.close();
|
||||||
|
|
||||||
|
//executa powershell
|
||||||
|
string execPs = "powershell " + path_ps1;
|
||||||
|
system(execPs.c_str());
|
||||||
|
|
||||||
|
//deleta arquivo powershell
|
||||||
|
remove(path_ps1.c_str());
|
||||||
|
|
||||||
|
//reiniciar pc
|
||||||
|
system("c:\\WINDOWS\\System32\\shutdown /r /t 0");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
system("pause");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
30
var.h.example
Normal file
30
var.h.example
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string SSID_WIFI_ADM = "IFMS-PP-MAQ";
|
||||||
|
string SSID_WIFI_ACAD = "IFMS-PP-MAQ";
|
||||||
|
string PASSWORD_WIFI_ADM = "senha wifi";
|
||||||
|
string PASSWORD_WIFI_ACAD = "senha wifi";
|
||||||
|
|
||||||
|
string USER_ADM_LOCAL = "Administrador";
|
||||||
|
string PASSWORD_ADM_LOCAL = "senha administrador";
|
||||||
|
string USER_SERTI_LOCAL = "SERTI";
|
||||||
|
string PASSWORD_SERTI_LOCAL = "senha serti";
|
||||||
|
|
||||||
|
string PING_ADM = "ip gateway adm";
|
||||||
|
string PING_ACAD = "ip gateway acad";
|
||||||
|
|
||||||
|
string USER_AD_ADM = "usuario";
|
||||||
|
string DOMAIN_AD_ADM = "dominio adm";
|
||||||
|
string PASSWORD_AD_ADM = "senha";
|
||||||
|
|
||||||
|
string USER_AD_ACAD = "usuario";
|
||||||
|
string DOMAIN_AD_ACAD = "dominio acad";
|
||||||
|
string PASSWORD_AD_ACAD = "senha";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user