Sign in to follow this  
Followers 0
TravisC

#requireadmin for Vista ONLY

12 posts in this topic

how can i make my script #requireadmin for vista only? I tried

If @OSVersion = "WIN_VISTA" Then
    #RequireAdmin
EndIf

but other os's still get prompted for an admin password. how can i make it where only vista users are prompted because of UAC and xp/2k can run on limited accounts?

Share this post


Link to post
Share on other sites



Hi.

how can i make my script #requireadmin for vista only? I tried

If @OSVersion = "WIN_VISTA" Then
    #RequireAdmin
EndIf

but other os's still get prompted for an admin password.

This should NOT be fact!

Put these lines on top of your code:

If @OSVersion = "WIN_VISTA" Then
    #RequireAdmin
Else
    MsgBox(64,"Not Vista","This isn't Vista, this is " & @OSVersion)
EndIf

Exit

If it works, remove the "exit". If it then again does nonsense, you'll propably have another #RequireAdmin somewhere in your code.

Regards, Rudi.


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

Share this post


Link to post
Share on other sites

Why not just put #RequireAdmin, because XP users don't get the prompt, only VISTA.

Share this post


Link to post
Share on other sites

This should NOT be fact!

Not sure, but isn't it so that directives starting with '#' will just be extracted from the code and executed directly at startup.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Why not just put #RequireAdmin, because XP users don't get the prompt, only VISTA.

No, it prompts for 2k and xp also.

"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)."

Share this post


Link to post
Share on other sites

If my above post was right the only way to fix this would be to have 3 scripts, one with the #RequireAdmin keyword and one without, then a third which ran the other scripts according to windows versions


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Hi.

This should NOT be fact!

Put these lines on top of your code:

If @OSVersion = "WIN_VISTA" Then
    #RequireAdmin
Else
    MsgBox(64,"Not Vista","This isn't Vista, this is " & @OSVersion)
EndIf

Exit

If it works, remove the "exit". If it then again does nonsense, you'll propably have another #RequireAdmin somewhere in your code.

Regards, Rudi.

How is that code any different from the code i already said i tried?

Share this post


Link to post
Share on other sites

how can i make my script #requireadmin for vista only? I tried

#RequireAdmin is a directive. It is read before the script starts execution so conditional runtime code has no effect on it.

Share this post


Link to post
Share on other sites

#RequireAdmin is a directive. It is read before the script starts execution so conditional runtime code has no effect on it.

so there is no way to define CONDITIONAL directives? :)

Regards, Rudi.


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

Share this post


Link to post
Share on other sites

It does seem that way.

Maybe an alternative would be a conditional self-runas command?

Share this post


Link to post
Share on other sites

It does seem that way.

Maybe an alternative would be a conditional self-runas command?

how would i do that?

Share this post


Link to post
Share on other sites

; This example will rerun itself with admin rights on using a local account

; Note on Vista this may not work as even though the user is admin it may

; not be elevated even after the RunAs call. In that case use #RequireAdmin

; at the top of the script.

; Are we already admin?

If Not IsAdmin() Then

RunAsSet('USER', @Computername, 'PASSWORD')

Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)

Exit

EndIf

MsgBox(0, 'Message', 'Now running with admin rights.')

i was never aware but from what the help file says basicly vista may or may not run a program with elevated permisions when using runasset, i cant think of anyway around this, but im very interested so im going to keep thinking.

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