su.exe, runas.exe device locking problems

From: Pete (pnbarber@hotmail.com)
Date: 06/28/02


From: pnbarber@hotmail.com (Pete)
Date: 27 Jun 2002 22:08:30 -0700


Hi guys,

I've written a Delphi app which enables/disables devices like the
floppy drive or CD Rom drive. It uses SetupDiChangeState and several
other similar functions to get the device, install params to disable
or enable the device and finalise the change. I tested this under an
admin user and under a normal user to find obvious results, that the
app would get access is denied when it didn't have authority and work
properly when logged in with authority.

Because I need this to be run by normal users, my next step was to run
my app using Su.exe under a standard user. I ran su sending the admin
details for user and password, and the app got access is denied still.
 I thought about how su works, and figured maybe I couldn't disable a
device while using su because of possible environment issues. I then
tried runas and found the same result, until trying to disable the
device a second time. Each instance of the app fails the first time
and succeeds every time afterwards. Trying su afterwards gave the
same result, it would fail the first click with access is denied, but
then succeed the second click.

I can work with this if I absolutely need to, but it's a very messy
way, and I'd really like to know why it doesn't work at first, but
then does work after.
I've searched hard for an answer, and studied my code several times
looking for a possible reason but have nothing. If anyone has any
clues can they help me out.

Thanks,

Pete.