Jump to content
Sign in to follow this  
Kerros

#RequireAdmin Windows8

Recommended Posts

Kerros

Hello

I'm working with Windows 8 and have an issue that is causing my eye to twitch.

When debugging scripts I use the console write within SciTE (Full Version) to output a fair number of parameters so the script doesn't have to stop working. This functionality seems to be non-working within Windows 8, everything works as expected under Windows 7 and XP.

When I run this example script,

#include<Constants.au3>
;#AutoIt3Wrapper_Res_requestedExecutionLevel=RequireAdministrator
;#RequireAdmin

Local $DriveHandle = OpenDrive(0)

ConsoleWrite($DriveHandle & @CRLF)
MsgBox(64, 'Return From OpenDrive', $DriveHandle)
CloseDrive($DriveHandle)


Func OpenDrive($driveNum)
Local $vDrive
;Get handle to drive
$vDrive = DllCall( _
"kernel32.dll", "hwnd", _
"CreateFile", _
"str", "\\.\PhysicalDrive" & String($driveNum), _
"dword", BitOR($GENERIC_READ, $GENERIC_WRITE), _
"dword", BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), _
"ptr", 0, _
"dword", $OPEN_EXISTING, _
"dword", 0, _
"ptr", 0 _
)
If @error <> 0 Then
MsgBox(1, "EXITING...", "CreateFile DLLCall failed!")
Exit
EndIf

Return $vDrive[0]
EndFunc ;==>OpenDrive

Func CloseDrive($vDrive)
Local $rVal = DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $vDrive)
If @error Then Return SetError(-1, -1, 0)
Return $rVal[0]
EndFunc ;==>CloseDrive

It will return 0xFFFFFFFF, an invalid handle. If I uncomment #RequireAdmin I will get a valid handle, but I get no text written to the console. Using #AutoIt3Wrapper_Res_requestedExecutionLevel=RequireAdministrator results in an invalid handle as well.

I had also tried running the _WINAPI_CreateFile function, but it is resulting in the same issue.

Is there a fix, or workaround that would allow me to use the #RequreAdmin systemcall but still get output to the console?

Thank you,

Kerros


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
BrewManNH

When you run your script using #RequireAdmin it closes the script and reopens it under the Administrator's credentials. You'll notice in the Scite console that the script will end very quickly and then you get nothing further in Scite because of this. There's no work around that I've seen other than maybe starting Scite as an admin first, haven't tried it in a while so I'm not sure if it will work.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Kerros

Thanks for the tip, it was the case that I needed to open SciTE with admin. That will work for me,

Thanks

Kerros


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

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  

×