Isso é mais uma medida paliativa do que uma solução, então não vou marcar isso como uma solução.
Atualmente, estou resolvendo esse problema fazendo com que um programa gere e execute um arquivo vbs para inserir o nome de usuário e a senha do usuário. Então eu tenho outro programa que verifica o arquivo de preferências do Chrome para ver se ele foi configurado com sucesso. Se não foi o script é executado novamente.
chromeConf.vbs (escrevi outro programa que gerou automaticamente este arquivo e o executou em cada computador):
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "^{ESCAPE}" 'start menue
WScript.Sleep 1000 'wait for it to load
oShell.SendKeys "chrome.exe" 'chrome
WScript.Sleep 1000
oShell.SendKeys "{ENTER}"
return = oShell.Run("waitForFocus.exe Chrome", 0, true)'wait for Chrome to open
oShell.SendKeys "%{F4}" 'go! be gone!
'Chrome has to be started twice to ensure the same start state on all computers
oShell.SendKeys "^{ESCAPE}" 'start menue
WScript.Sleep 1000 'wait for it to load
oShell.SendKeys "chrome.exe" 'chrome
WScript.Sleep 1000
oShell.SendKeys "{ENTER}"
return = oShell.Run("waitForFocus.exe Chrome", 0, true)
oShell.SendKeys "chrome://settings" 'settings
oShell.SendKeys "{ENTER}"
WScript.Sleep 5000
oShell.SendKeys "{TAB}{TAB}" 'select log in
oShell.SendKeys "{ENTER}"
WScript.Sleep 8000
oShell.SendKeys "{TAB}{TAB}" 'log in
oShell.SendKeys "[email protected]"
oShell.SendKeys "{TAB}"
oShell.SendKeys "{ENTER}"
WScript.Sleep 4000
oShell.SendKeys "password"
oShell.SendKeys "{TAB}"
oShell.SendKeys "{ENTER}"
WScript.Sleep 4000
oShell.SendKeys "{TAB}" 'link data
oShell.SendKeys "{TAB}"
oShell.SendKeys "{TAB}"
oShell.SendKeys "{TAB}"
oShell.SendKeys "{ENTER}"
WScript.Sleep 4000
oShell.SendKeys "{ESCAPE}" 'get rid of pesky user dialog
oShell.SendKeys "%{F4}" 'go! be gone!
fonte waitForFocus.exe:
// waitForFocus.cpp : This program waits for a window of a specified name to load
//
#include "stdafx.h"
#include <string.h>
#include <atlstr.h>
#include <iostream>
using namespace std;
LPWSTR pszMem;
BOOL CALLBACK FindWindowBySubstr(HWND hwnd, LPARAM substring)
{
const DWORD TITLE_SIZE = 1024;
TCHAR windowTitle[TITLE_SIZE];
if (GetWindowText(hwnd, windowTitle, TITLE_SIZE))
{
string fstr = CW2A(windowTitle);//convert window title to string
if (fstr.find(LPCSTR(substring)) != string::npos && !(fstr.find("waitForFocus.exe") != string::npos)) { //is it what we want
cout << "Found window!" << endl;
_tprintf(TEXT("%s\n"), windowTitle);
SwitchToThisWindow(hwnd, true);//The true enables alt tab emulation which prevents the transparent window bug
return false;
}
}
return true;
}
int main(int argc, char* argv[])
{
if (argc > 2) {
cout << "This program takes 1 argument" << endl;
cout << "The argument should be part of the name of the window you want to wait for" << endl;
}
else if (argc == 2) {
if (string(argv[1]) == "/h" || string(argv[1]) == "-h" || string(argv[1]) == "/?" || string(argv[1]) == "-?"){
cout << "This program takes one input, part of the window name, and waits for that window to load" << endl;
}
else {
bool nfound = true;
while (nfound) {
HWND windowHandle = FindWindowA(0, argv[1]); //check if there is a window exactly matching what we want
if (windowHandle == NULL) {//no
HWND WINAPI GetForegroundWindow(void);//is the window already up (If so I dont have to look for it)
pszMem = (LPWSTR)VirtualAlloc((LPVOID)NULL,
(DWORD)(80), MEM_COMMIT,
PAGE_READWRITE);
GetWindowText(GetForegroundWindow(), pszMem,
80);
cout << GetForegroundWindow() << ", ";
string resstr = CW2A(pszMem);
wcout << pszMem << endl;
if (resstr.find(string(argv[1])) != string::npos && !(resstr.find(string("waitForFocus.exe")) != string::npos)) {
cout << "found!" << endl;//It was already up
nfound = false;
}
else {//it wasn't
if (!EnumWindows(FindWindowBySubstr, (LPARAM)argv[1])) {//loop through every single window
nfound = false;
}
else {
Sleep(1000);
}
}
}
else {
cout << "found absolute result" << endl;
SwitchToThisWindow(windowHandle, true);//switch to the located window
nfound = false;
}
}
}
}
else if (argc == 1) {
cout << "This program takes one input, part of the window name, and waits for that window to load" << endl;
}
else {
cout << "How did you manage to pass a negative number of flags?" << endl;
}
return 0;
}
validateGoogleChrome.exe source (esse programa verifica se o Chrome foi configurado. Ele presume que o nome de usuário do computador é igual ao nome de usuário da conta do Google Apps. Ele também deve ser executado em %LOCALAPPDATA%\Google\Chrome\User Data\Default\Preferences
):
// validateGoogleChrome.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <sstream>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <lm.h>
using namespace std;
string gUname() {
char username[UNLEN + 1];
DWORD size = UNLEN + 1;
GetUserNameA(username, &size);
stringstream conv;
string uname = "";
conv << username;
conv >> uname;
cout << "username:" << uname << endl;
return uname;
}
int main()
{
string line;
string query = gUname();
ifstream file("Preferences");
if (file.is_open()) {
while (getline(file, line, '\n')) {
if (line.find(query) != string::npos) {
cout << "passed" << endl;
return 0;
}
else {
cout << "fail" << endl;
return 1;
}
}
}
else {
cout << "ERROR: Chrome preferences file not found" << endl;
return 2;
}
}
Espero que este código tenha horrorizado você com uma solução melhor.