Pchar com ReadString na hora de mapear
Ola pessoal, fiquei um tempo sumido mas to de volta :)
Bom criei um exe pequeno para poder mapear a rede aqui, onde cada maquina tem um arquivo .ini onde tem as informações do mapeamento, letra e senha
o problema esta na hora de passar do pchar para o ReadString, vou colocar o fonte para entenderem melhor e explicar :)
[i:5b46596cff]Var
INIScript: TINIFile;
ERR : DWord;
PServerP, PSenhaP, PLetraP : PChar;
Begin
INIScript := TIniFile.Create(ExtractFilePath(ParamStr(0))+ ´\arquivo.ini´);
PServerP := INIScript.ReadString(´MAP´,´PServerP´,´´) + #0;
// esta dando problema aqui, onde fala que é incompativel string com pchar
PLetraP := INIScript.ReadString(´MAP´,´PSenhaP´,´´);
PSenhaP := INIScript.ReadString(´MAP´,´PLetraP´,´´);
//eu ainda nem cheguei aqui
//tirar o mapeamento
ERR := WNetCancelConnection2 ( PLetraP, CONNECT_UPDATE_PROFILE, True );
//mapear
ERR := WNetAddConnection ( PServerP , PSenhaP , PLetraP );[/i:5b46596cff]
Meu arquivo .ini ta assim
[MAP]
PServerP=\\corcos\alexandre
PSenhaP=
PLetraP=P:
Bom o que eu preciso é que na hora de mapear ele olhe o .ini e faça isso passando os parametros.
Obrigado
Bom criei um exe pequeno para poder mapear a rede aqui, onde cada maquina tem um arquivo .ini onde tem as informações do mapeamento, letra e senha
o problema esta na hora de passar do pchar para o ReadString, vou colocar o fonte para entenderem melhor e explicar :)
[i:5b46596cff]Var
INIScript: TINIFile;
ERR : DWord;
PServerP, PSenhaP, PLetraP : PChar;
Begin
INIScript := TIniFile.Create(ExtractFilePath(ParamStr(0))+ ´\arquivo.ini´);
PServerP := INIScript.ReadString(´MAP´,´PServerP´,´´) + #0;
// esta dando problema aqui, onde fala que é incompativel string com pchar
PLetraP := INIScript.ReadString(´MAP´,´PSenhaP´,´´);
PSenhaP := INIScript.ReadString(´MAP´,´PLetraP´,´´);
//eu ainda nem cheguei aqui
//tirar o mapeamento
ERR := WNetCancelConnection2 ( PLetraP, CONNECT_UPDATE_PROFILE, True );
//mapear
ERR := WNetAddConnection ( PServerP , PSenhaP , PLetraP );[/i:5b46596cff]
Meu arquivo .ini ta assim
[MAP]
PServerP=\\corcos\alexandre
PSenhaP=
PLetraP=P:
Bom o que eu preciso é que na hora de mapear ele olhe o .ini e faça isso passando os parametros.
Obrigado
Corcos
Curtidas 0
Respostas
Massuda
24/10/2007
PChar é só um ponteiro, não tem ´bytes´ para receber o texto da string. Faça assim...
Var INIScript: TINIFile; ERR : DWord; Server, Senha, Letra : string; Begin INIScript := TIniFile.Create(ExtractFilePath(ParamStr(0))+ ´\arquivo.ini´); Server := INIScript.ReadString(´MAP´,´PServerP´,´´); Letra := INIScript.ReadString(´MAP´,´PSenhaP´,´´); Senha := INIScript.ReadString(´MAP´,´PLetraP´,´´); //AQUI VOCÊ DEVE PASSAR O PONTEIRO PARA A STRING ERR := WNetCancelConnection2 ( PChar(Letra), CONNECT_UPDATE_PROFILE, True ); ERR := WNetAddConnection ( PChar(Server) , PChar(Senha) , PChar(Letra) );
GOSTEI 0
Corcos
24/10/2007
obrigado Massuda
Uma outra dúvida, como eu capturo o usuario que logou no windows 98 e no xp? ele guarda em algum arquivo ou no regedit?
Uma outra dúvida, como eu capturo o usuario que logou no windows 98 e no xp? ele guarda em algum arquivo ou no regedit?
GOSTEI 0
Corcos
24/10/2007
achei esse topico aqui... vou fazer uns testes, valeu :)
http://forum.clubedelphi.net/viewtopic.php?p=255033&sid=687b247d0cb7ab1a40c99775177fcaf2
http://forum.clubedelphi.net/viewtopic.php?p=255033&sid=687b247d0cb7ab1a40c99775177fcaf2
GOSTEI 0
Corcos
24/10/2007
Vou por aqui a parte do codigo para aqueles que precisam, acho super importante aqueles que conseguem resolver o problema postar como ficou a solução e etc..
O que eu estava precisando era fazer uma tela de splash para alterar o horario de verão (que ele busca do nosso data center no rio) e mapear no meu servidor de arquivos 3 pastas (publico, pasta particular e pasta do setor)
Então na tela de cadastro de funcionario eu tenho
Caminho, letra e senha, onde o caminho é o \\server\publico a letra é um combobox com as letras e a senha se tiver
na tela de splash segue o codigo, que fiz em cima de um gauge que vai carregando e passando as infos do que esta ocorrendo para o usuario
// var global
var
ERR : DWord;
PServerP, PSenhaP, PLetraP : String;
// no on show do form
var
szBuffer: PChar;
iSize: DWORD;
begin
szBuffer := nil;
iSize := 0;
GetUserName(szBuffer, iSize);
szBuffer := StrAlloc(iSize);
try
GetUserName(szBuffer, iSize);
lblUsuario.Caption := PChar(szBuffer);
finally
StrDispose(szBuffer);
end;
// no timer agora
if Gauge1.Progress > 100 then
Gauge1.Progress := 1;
Gauge1.Progress := Gauge1.Progress + 1;
// ----- PROCESSO DO GAUGE --------- //
if Gauge1.Progress = 10 then
Begin
Label1.Visible:= true;
Label1.Caption:= ´sincronizando horário´;
WinExec(´net time \\192.168.106.1 /set /yes´,SW_HIDE);
end;
if Gauge1.Progress = 40 then
Begin
Label2.Visible:= true;
Label2.Caption:= ´mapeando unidades de rede´;
// ----- TIRANDO O MAPEAMENTO E MAPEANDO --------- //
PServerP := QryLogadoPSERVERP.Value;
PLetraP := QryLogadoPLETRAP.Value;
PSenhaP := QryLogadoPSENHAP.Value;
WNetCancelConnection2( PChar(PLetraP) , CONNECT_UPDATE_PROFILE, True); // TIRAR O MAPEAMENTO ANTES DE MAPEAR
ERR := WNetAddConnection ( PChar(PServerP) , PChar(PSenhaP) , PChar(PLetraP) );
// ----- FIM -- TIRANDO O MAPEAMENTO E MAPEANDO --------- //
end;
if Gauge1.Progress = 80 then
Begin
Label5.Visible:= true;
Label5.Caption:= ´Finalizando processo´;
end;
if Gauge1.Progress = 95 then
Begin
Label5.Caption:= ´Concluído, fechando aplicativo´;
end;
if Gauge1.Progress = 100 then
Begin
Application.Terminate;
end;
// fim eventos
end;
É mais ou menos isso se alguem tiver alguma duvida ou quiser mais detalhes so falar... :)
O que eu estava precisando era fazer uma tela de splash para alterar o horario de verão (que ele busca do nosso data center no rio) e mapear no meu servidor de arquivos 3 pastas (publico, pasta particular e pasta do setor)
Então na tela de cadastro de funcionario eu tenho
Caminho, letra e senha, onde o caminho é o \\server\publico a letra é um combobox com as letras e a senha se tiver
na tela de splash segue o codigo, que fiz em cima de um gauge que vai carregando e passando as infos do que esta ocorrendo para o usuario
// var global
var
ERR : DWord;
PServerP, PSenhaP, PLetraP : String;
// no on show do form
var
szBuffer: PChar;
iSize: DWORD;
begin
szBuffer := nil;
iSize := 0;
GetUserName(szBuffer, iSize);
szBuffer := StrAlloc(iSize);
try
GetUserName(szBuffer, iSize);
lblUsuario.Caption := PChar(szBuffer);
finally
StrDispose(szBuffer);
end;
// no timer agora
if Gauge1.Progress > 100 then
Gauge1.Progress := 1;
Gauge1.Progress := Gauge1.Progress + 1;
// ----- PROCESSO DO GAUGE --------- //
if Gauge1.Progress = 10 then
Begin
Label1.Visible:= true;
Label1.Caption:= ´sincronizando horário´;
WinExec(´net time \\192.168.106.1 /set /yes´,SW_HIDE);
end;
if Gauge1.Progress = 40 then
Begin
Label2.Visible:= true;
Label2.Caption:= ´mapeando unidades de rede´;
// ----- TIRANDO O MAPEAMENTO E MAPEANDO --------- //
PServerP := QryLogadoPSERVERP.Value;
PLetraP := QryLogadoPLETRAP.Value;
PSenhaP := QryLogadoPSENHAP.Value;
WNetCancelConnection2( PChar(PLetraP) , CONNECT_UPDATE_PROFILE, True); // TIRAR O MAPEAMENTO ANTES DE MAPEAR
ERR := WNetAddConnection ( PChar(PServerP) , PChar(PSenhaP) , PChar(PLetraP) );
// ----- FIM -- TIRANDO O MAPEAMENTO E MAPEANDO --------- //
end;
if Gauge1.Progress = 80 then
Begin
Label5.Visible:= true;
Label5.Caption:= ´Finalizando processo´;
end;
if Gauge1.Progress = 95 then
Begin
Label5.Caption:= ´Concluído, fechando aplicativo´;
end;
if Gauge1.Progress = 100 then
Begin
Application.Terminate;
end;
// fim eventos
end;
É mais ou menos isso se alguem tiver alguma duvida ou quiser mais detalhes so falar... :)
GOSTEI 0