dizi 0 Posted February 9, 2011 (edited) hi, i'm having trouble using AutoIT to get the name of the current user. Let me explain ... We use a package deployment solution named OCS ( http://www.ocsinventory-ng.org/ ). It's the OCS client, installed on all our computers, who launch our AutoIT packages. The OCS agent is launch automatically by the service manager. In one of our package, we need to know who is the current user, so we used the @Username macro. When manually launched the result is OK, it's the name of the current user. But when launched via the OCS agent, the result is "SYSTEM". So we tried with @UserProfileDir: ok when launched manually, but with OCS the result is "C:\Documents and Settings\LocalService". We also tried to get the result of the DOS command "echo %USERNAME%" ... same conclusion : it worked well manually, but it returns "SYSTEM" with the OCS agent ... By chance, any idea ? Any help will be grealty appreciated :] Edited February 9, 2011 by dizi Share this post Link to post Share on other sites
saywell 3 Posted February 9, 2011 hi, i'm having trouble using AutoIT to get the name of the current user. Let me explain ... We use a package deployment solution named OCS ( http://www.ocsinventory-ng.org/ ). It's the OCS client, installed on all our computers, who launch our AutoIT packages. The OCS agent is launch automatically by the service manager. In one of our package, we need to know who is the current user, so we used the @Username macro. When manually launched the result is OK, it's the name of the current user. But when launched via the OCS agent, the result is "SYSTEM". So we tried with @UserProfileDir: ok when launched manually, but with OCS the result is "C:\Documents and Settings\LocalService". We also tried to get the result of the DOS command "echo %USERNAME%" ... same conclusion : it worked well manually, but it returns "SYSTEM" with the OCS agent ... By chance, any idea ? Any help will be grealty appreciate :] This is what I use: Global $LastName = EnvGet("NWLASTNAME") Global $FirstName = EnvGet("NWFIRSTNAME") Global $username = EnvGet("NWUSERNAME") Global $computername = EnvGet("COMPUTERNAME") Global $computerlocation = EnvGet("PCLocation") The NW ones come from Novell log-in. If you type 'SET' in a dos box you'll see what's available to you. William Share this post Link to post Share on other sites
dizi 0 Posted February 9, 2011 thanks for the tip as always it worked well when the autoit exe is launched manually. But when it's launched whith the OCS agent, this time with EnvGet the result is null ... i'm lost $computername = EnvGet("USERNAME") MsgBox(4096, "Test", $computername, 10) Share this post Link to post Share on other sites
dizi 0 Posted February 9, 2011 found ! $username="" $objWMIService = Objget("winmgmts:\\localhost\root\cimv2") $colComputer = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem") ; If IsObj($colComputer) Then For $objComputer In $colComputer $username &= "username = "&$objComputer.UserName&@CRLF Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_ComputerSystem") EndIf MsgBox(1, "username", $username) twisted but it worked Share this post Link to post Share on other sites