Jump to content

Script to open Device Manager?


Recommended Posts

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

Awesome. Thanks.

I just have a question, I did up this script, as per my usu. preferences:

;
; AutoIt v3.0
;
#NoTrayIcon     ; AutoIt's icon doesn't show in systray

AutoItSetOption("WinTitleMatchMode", 2)     ;  this allows partial window titles to be valid!

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)
Beep(750,175)
Sleep(3500)
Beep(1000,75)
Beep(500,175)
WinWaitActive("Device Manager")
WinSetState ("Device Manager", "", @SW_MAXIMIZE)

Exit     ; finished
But I ran into a bit of snag. Granted, this file I wouldn't usu. need on a computer at the office where there are restrictions, but I still think that I should be able to bypass an error box that comes up. Never know when I'd just need to compare what something looks like on another computer (as I did the other day) so it would be neat to have this work even on restricted computers. I like my windows to be maximized after opening, but here the error box is what got maximized. I added in a little workaround above by adding the lines with sleep prompted by beeps, but this is an inelegant, cumbersome workaround with a time limit.

The error box I get is this:

You do not have sufficient security privileges to uninstall devices or to change device properties or device drivers.  Please contact your site administrator, or logout and log in again as an administrator and try again.
Yeah, but I wouldn't be making any changes to work computer anyway. So is there a way to have error handling so that the WinWaitActive and WinSetState are activated only once the user has pressed OK on an error box, _if_ an error box is even an issue? In other words, _if_ an error box were to come up as here, that the script not continue till user presses OK; yet if there is no such error that the scripts continues on as normal on to the "Win" commands?

That would make this code neat and tidy and efficient.

Thanks! :)

Link to comment
Share on other sites

Beep(750,175)

Sleep(3500)

Beep(1000,75)

Beep(500,175)

you dont need that

just go for something like this:

CODE

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

$functionerror = 0

while 1

Sleep(100)

$state = WinGetState("Device Manager")

$errorstate = WinGetText("ERRORBOX")

If StringinStr($errorstate,"You do not have sufficient security privileges") then

$functionerror = 1

exitloop

Endif

if $state = 15 then ;the windows is active and ther should be no error; wasnt able to test this

$functionerror = 0

exitloop

Endif

Wend

if not $functionerror then

DoSomething()

endif

Edited by Kademlia
Link to comment
Share on other sites

Beep(750,175)

Sleep(3500)

Beep(1000,75)

Beep(500,175)

you dont need that

Yes, when there is no error box, I wouldn't need this, you're right. But here at the office I _do_ get the error box. And that window is what is getting maximized, not the Device Manager one. That's why I put this cumbersome workaround in there to at least give some time for me to get rid of the error box. The beeps are just for prompting purposes. Like I said ... clunky and cumbersome, but it works.

just go for something like this:

CODE

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

$functionerror = 0

while 1

Sleep(100)

$state = WinGetState("Device Manager")

$errorstate = WinGetText("ERRORBOX")

If StringinStr($errorstate,"You do not have sufficient security privileges") then

$functionerror = 1

exitloop

Endif

if $state = 15 then ;the windows is active and ther should be no error; wasnt able to test this

$functionerror = 0

exitloop

Endif

Wend

if not $functionerror then

DoSomething()

endif

Thanks for this but I'm not sure what's wrong. I'm no expert of course, but something tells me this script is not quite there yet. Don't know how to fix, though.

I "translated" it to my preferred format, so this is what I now have, since I needed to replace the "DoSomething()" anyway <g>:

;
; AutoIt v3.0
;
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
AutoItSetOption("WinTitleMatchMode", 2)     ;  this allows partial window titles to be valid!


$state = WinGetState("Device Manager")
$errorstate = WinGetText("ERRORBOX")
If StringinStr($errorstate,"Although you do not have sufficient security privileges to make changes, press OK to continue to the Device Manager.") then
$functionerror = 1
exitloop
Endif
if $state = 15 then     ; The window is active and there should be no error.
$functionerror = 0
exitloop
Endif
Wend

if not $functionerror then
Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)
WinWaitActive("Device Manager")
WinSetState ("Device Manager", "", @SW_MAXIMIZE)
endif

Exit     ; finished
The script doesn't work and I get this msg:
Error:  "ExitLoop/ContinueLoop" statements only valid from inside a For/Do/While loop."

Did I put the code in wrong, or is it something to do with the syntax?

Thanks! :)

Link to comment
Share on other sites

uhm, you miss some basics here...

the "Wend" indicates the end of a loop.

it goes from

"While 1" to "Wend" (you missed to copy the while 1)

The loop will go on to do whats inside until someting/someone calls the "exitloop".

I don´t think the code will work if you get this right, i just didn´t know enough about the errorbox you get. If it works your realy lucky (btw $errorstate = WinGetText("ERRORBOX") will not work....use Au3Info.exe to geht the real name).

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