Sign in to follow this  
Followers 0
orion156

Username before #requireadmin

7 posts in this topic

I can't get the loginname with @Username, when I use #requireadmin in an AutoIt-script.

In stead it shows the admin-username that I used to allow the execution.

How can I get the first/original loginname?

Share this post


Link to post
Share on other sites



I can't get the loginname with @Username, when I use #requireadmin in an AutoIt-script.

In stead it shows the admin-username that I used to allow the execution.

How can I get the first/original loginname?

There is no built-in way to do it, but you could use _ProcessListProperties() to search through processes to find out who's logged onto the machine.

Dim $array

$array = _ProcessListProperties()
For $i = 1 To $array[0][0]
    If Not StringInStr($array[$i][3], "Administrator") And Not StringInStr($array[$i][3], "SYSTEM") And _
        Not StringInStr($array[$i][3], "Local Service") And Not StringInStr($array[$i][3], "Network Service") And _
        $array[$i][3] <> "" Then
        MsgBox(0,"First username logged on",$array[$i][3])
    EndIf
Next

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

Airwolf: In my case the #requireadmin username and loginname could be different from time to time

AdmiralAlkex: Is get an error when i use CoProc.au3. For instance when i run "Example_Golbals.au3" i get this message:

CoProc_Send_Username_to_Real_script\CoProc.au3(49,47) :

ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

$iOldRunErrorsFatal = Opt("RunErrorsFatal", 0)

Do you or anybody know what's wrong?

Share this post


Link to post
Share on other sites

I have to assume I am wrong on this and I do not have a machine to test this on, but couldn't you grab @Username and set it in a variable before you declare the #requireadmin keyword?


"Human kind cannot gain anything without first giving something in return, to obtain; something of equal value must be lost."The Help File is truly your friend.

Share this post


Link to post
Share on other sites

Airwolf: In my case the #requireadmin username and loginname could be different from time to time

AdmiralAlkex: Is get an error when i use CoProc.au3. For instance when i run "Example_Golbals.au3" i get this message:

CoProc_Send_Username_to_Real_script\CoProc.au3(49,47) :

ERROR: Opt() called with illegal argument 1: "RunErrorsFatal"

$iOldRunErrorsFatal = Opt("RunErrorsFatal", 0)

Do you or anybody know what's wrong?

CoProc.au3 was written for an earlier version of AutoIt. The latest version don't have "RunErrorsFatal" so comment/remove that line.

If the CoProc stuff is bothering you, you may want to read about "Command Line Parameters" in the helpfile and build one script that launches the other with @UserName as a command line parameter.

I have to assume I am wrong on this and I do not have a machine to test this on, but couldn't you grab @Username and set it in a variable before you declare the #requireadmin keyword?

Jos explained this in a good way a couple of days ago.

#RequireAdmin is a directive not a function. Thus it is set at program start time.

Jos

Share this post


Link to post
Share on other sites

CoProc.au3 was written for an earlier version of AutoIt. The latest version don't have "RunErrorsFatal" so comment/remove that line.

If the CoProc stuff is bothering you, you may want to read about "Command Line Parameters" in the helpfile and build one script that launches the other with @UserName as a command line parameter.

Jos explained this in a good way a couple of days ago.

Thanx :P

I used the command:

Run( "script2.exe " & @UserName )

in script1.au3/.exe and the command

$MyUsername = $CmdLine[1]

in script2.au3/.exe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0