Jump to content

#RequireAdmin as a option in a script?


YTSJim
 Share

Recommended Posts

Hi All,

Its my first post under this username (can't remember my old email address that i used before), so be gentle :graduated:

History:

i created (updated) a small autoit application called SCPrompt for remote support providers, which allows them to quickly connect to a clients computer regardless of where they are at that point (or their IP, as it just asked for the address to connect to).

This application has grown over the years to allow massive customisation.

Problem:

Win7 & Vista play havic with VNC, so its best to install them as a Service, which then behaves better.

Using iexpress, to package the application, meant that end users have to right mouse click on the app, and run as admin to get full admin access.

Using 7zip, to package the application, meant that end users without admin access, needed to enter admin passwords in order to allow access to the app.

So i found NSIS, which has a way of choosing whether to run as admin or as a user. this is great, and solves my problem, but i want to try to do this within the AutoIt Script itself. NSIS uses a plugin DLL to give elevated access, and i was hoping someone much smarter than me, might be able to create a way of allowing the programmer to choose to elevate a program to admin, or run as user ...

Links:

NSIS UAC_plug-in explaination page (download the attached file, and look at the code in the example scripts, don't look at the page.

Code:

This is my example code, which highlights the way that i would 'LIKE' to be able to run as admin ... i realise that #RequireAdmin actually changes the way the application is built, but its a example of how i would like applications be be able to behave ...

If $cmdline[0] = 0 Then
    MsgBox(0, "", "No commandline",5)
Else
    _cmdline()
EndIf

Func _cmdline()
    Local $Local_loop = 0
    Do
        ConsoleWrite("$cmdline[0] = " & $cmdline[0] & "$local_loop = " & $Local_loop & @CRLF)
        $Local_loop = $Local_loop + 1
        Switch StringLower($cmdline[$Local_loop])
            Case "admin", "-admin", "/admin"
                #RequireAdmin
                MsgBox(0, "", "Admin commandline",5)
            Case Else
                MsgBox(0, "", "No recognised commandline",5)
        EndSwitch
        Sleep(100)
    Until $Local_loop = $cmdline[0]
EndFunc   ;==>_cmdline
Edited by YTSJim
Link to comment
Share on other sites

Well, it can't be done that way.

Yep ... i realise the code cannot work ... but the DLL that is in the linked page, allows NSIS to elevate from being a user, to being a ADMIN ...

A workaround might be: use a RunAs instead of #RequireAdmin and make it launch the real application - current script will be only the launcher.

I have found the work around i need ... but i think that this would be something that would likely help others into the future ...

personally, i would like to know if it is possible ...

im not sure if the DLL will be useful within autoit ... this is something that more talented than myself will need to work out ... :graduated:

Link to comment
Share on other sites

There are like a hundred examples posted here on AutoIt forums. Myself like five times. Again:

If Not IsAdmin() Then
    Switch @OSVersion
        Case "Vista", "2008", "2008R2", "WIN_7"
            If @Compiled Then
                ShellExecute(@AutoItExe, "", "", "runas")
                Exit
            Else
                ShellExecute(@AutoItExe, ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '"', "", "runas")
                Exit
            EndIf
    EndSwitch
EndIf

MsgBox(64, "", IsAdmin())

That code will run as administrator for listed systems. For all others it will run with users privileges.

Any other condition can be set.

♡♡♡

.

eMyvnE

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...