
Saber Usuario Do Windows
Started By jacksto, 01/03/2007, 12:48
11 replies to this topic
#1
Posted 01/03/2007, 12:48
Gostaria de saber se alguém tem algum código para pegar o usuário do windows em php?
#2
Posted 01/03/2007, 13:03
<?php $nw = new COM("WScript.Network"); print "username0: " . $nw->username . "<br><br>"; $computername = $nw->computername; print "computername: $computername<br>"; $owmi = new COM("winmgmts:\\\\$computername\\root\\cimv2"); $comp = $owmi->get("win32_computersystem.name='$computername'"); print "username: " . $comp->username; ?>
Fonte: http://www.thescript...read514387.html
Felipe Pena
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29
#3
Posted 01/03/2007, 14:49
Não está dando certo.. ele está travando na 1 linha...
#4
Posted 01/03/2007, 16:11
Eu preciso (já az um tempinho...) da mesma coisa que o jacsto... Tive o mesmo erro na primeira linha do código
Alguém sabe como faço para pegar o usuário do domínio logado na máquina usando o PHP?
[] Rafael
Procurando no manual do PHP encontrei isto (nada de novo né? rs...):"Fatal error: Class 'com' not found in /var/www/testex.php on line 3"
COM functions are only available for the Windows version of PHP.Acontece que meu sistema PHP (para intranet, no caso) está rodando num servidor Linux... que por sinal é o LDAP_slave...
Alguém sabe como faço para pegar o usuário do domínio logado na máquina usando o PHP?
[] Rafael

#5
Posted 01/03/2007, 16:26
Só preciso que ele leia e me traga a chave que contém o nome do usuário.
Não está nem lendo o registro...
Não está nem lendo o registro...
#6
Posted 01/03/2007, 16:47
Jacksto, servidor linux ou windows?
[]
[]

#7
Posted 01/03/2007, 16:53
windows...
#8
Posted 01/03/2007, 17:08
Puts... tinha que funcionar! Qual é o erro?
[] rafael
[] rafael

#9
Posted 01/03/2007, 17:12
tentei este aqui também e nd
<?
$shell = new COM("WScript.Shell") or die("Requires Windows Scripting Host");
$key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\DefaultUserName";
$t = $shell->RegRead($key);
print "Login User:$t<br/>\n";
?>
Eu verifiquei no registro do windows e o nome do usuário está lá... e nada.
<?
$shell = new COM("WScript.Shell") or die("Requires Windows Scripting Host");
$key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon\DefaultUserName";
$t = $shell->RegRead($key);
print "Login User:$t<br/>\n";
?>
Eu verifiquei no registro do windows e o nome do usuário está lá... e nada.
#10
Posted 01/03/2007, 17:50
Cara tenho este código que pega em javascript e envia em um parametro pro php usar...
[codebox]<script type="text/jscript">
/* FUNÇÃO QUE PEGA O NOME DO USUARIO QUE ESTA LOGADO NO COMPUTADOR */
/********************************************
@author Luiz Felipe Barbieri
@version 0.1
@access public
********************************************
>> OBS: é necessario o servidor estar como pagina confiavel ou ativar os scripts ACTIVE X no IE
********************************************/
var objWshShell = new ActiveXObject("WScript.Shell");
var strUsername = objWshShell.ExpandEnvironmentStrings("%USERNAME%");
var http;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
// ******************* FUNÇÃO QUE ENVIA O NOME DO USUARIO QUE ESTA LOGADO NO COMPUTADOR ***********
function enviar() {
var url = "index_temp.php?login=" + strUsername; //ENDEREÇO DA PÁGINA ONDE SERÁ REDIRECIONADA + A VARIAVEL QUE SERÁ ENVIADA
http.open("POST", url, true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
http.setRequestHeader("Pragma", "no-cache");
http.onreadystatechange = funcao;
http.send("login=" + strUsername);
}
function funcao() {
if (http.readyState == 4) {
if (http.status == 200) {
var retorno = unescape(http.responseText.replace(/\+/g," "));
document.getElementById("conteudo").innerHTML = retorno;
} else {
alert('There was a problem with the request.');
}
}
}
</script>
<input type="button" onclick="enviar()" value="Click" /><br />
<div id="conteudo">aplicativo pega o usuario</div>
[/codebox]
[codebox]<script type="text/jscript">
/* FUNÇÃO QUE PEGA O NOME DO USUARIO QUE ESTA LOGADO NO COMPUTADOR */
/********************************************
@author Luiz Felipe Barbieri
@version 0.1
@access public
********************************************
>> OBS: é necessario o servidor estar como pagina confiavel ou ativar os scripts ACTIVE X no IE
********************************************/
var objWshShell = new ActiveXObject("WScript.Shell");
var strUsername = objWshShell.ExpandEnvironmentStrings("%USERNAME%");
var http;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
// ******************* FUNÇÃO QUE ENVIA O NOME DO USUARIO QUE ESTA LOGADO NO COMPUTADOR ***********
function enviar() {
var url = "index_temp.php?login=" + strUsername; //ENDEREÇO DA PÁGINA ONDE SERÁ REDIRECIONADA + A VARIAVEL QUE SERÁ ENVIADA
http.open("POST", url, true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
http.setRequestHeader("Pragma", "no-cache");
http.onreadystatechange = funcao;
http.send("login=" + strUsername);
}
function funcao() {
if (http.readyState == 4) {
if (http.status == 200) {
var retorno = unescape(http.responseText.replace(/\+/g," "));
document.getElementById("conteudo").innerHTML = retorno;
} else {
alert('There was a problem with the request.');
}
}
}
</script>
<input type="button" onclick="enviar()" value="Click" /><br />
<div id="conteudo">aplicativo pega o usuario</div>
[/codebox]
Felipe Barbieri
#11
Posted 02/03/2007, 22:45
Se alguém pudesse me mandar em php eu ficaria grato.
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)