The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => The Orphanage => Topic started by: sinsi on August 27, 2009, 08:22:08 AM

Title: Elevated privileges and vista/win7
Post by: sinsi on August 27, 2009, 08:22:08 AM
Using 'net stop wlansvc' works from a command prompt - as long as you pick 'run as administrator'.
I want to do it the hard way (instead of a batch file) which means using the SCM, which means elevation.

What is the best way to do it? I have seen code adjusting token privileges, using a manifest...

Background:
A game I play (NFS Undercover) connects to the internet to download ads (these are textures for the various billboards in the game).
The only trouble is that it can take up to 5 minutes for the game to start, since that's one of the first things it does.
If I remember, I disable my net connection before I start the game, but sometimes (well, quite often) I forget.
I even put a special rule in windows firewall (this is win7), it is 'block all' for incoming and outgoing, but still goes through.

Title: Re: Elevated privileges and vista/win7
Post by: Tedd on August 27, 2009, 04:27:35 PM
try sticking

Quoterunas /user:Administrator net stop wlansvc

in a batch file (untested; you might need to fiddle with the syntax) - it will request the password, and then run the command as the given user.
Title: Re: Elevated privileges and vista/win7
Post by: dedndave on August 27, 2009, 05:56:44 PM
i'd get the url for the ads and put it my hosts file
127.0.0.1  www. ad_url. com   (remove the spaces from the url)
Title: Re: Elevated privileges and vista/win7
Post by: GregL on August 28, 2009, 02:08:28 AM
sinsi,

Here is some stuff I wrote as an example of how to run a program or a task "elevated" in Windows Vista (works with Windows 7 too).

Run Elevated (http://www.masm32.com/board/index.php?topic=9422.0)

Title: Re: Elevated privileges and vista/win7
Post by: sinsi on August 28, 2009, 06:43:02 AM
Tedd: batch file doesn't work properly - when the game ends the batch console window is gone but cmd.exe is still there (possibly because the damned game has a console window too). Another PITA is having to type the password twice for runas...

dave: can you recommend a program to let me see that url?

Greg: That's what I was referring to in my original post. This is twice now I have needed it but couldn't remember the thread (and I posted to it!). Bookmarked now.

If I start another process from my elevated one, is the new one elevated as well?
Title: Re: Elevated privileges and vista/win7
Post by: sinsi on August 28, 2009, 07:18:50 AM
OK, I've gone with my code and Greg's manifest - works perfectly.

step one: OpenSCManager/OpenService/ControlService/CloseServiceHandle to stop
step two: CreateProcess/WaitForSingleObject until it finishes
step three: OpenSCManager/OpenService/StartService/CloseServiceHandle to restart

Thanks for the input fellas.
Title: Re: Elevated privileges and vista/win7
Post by: dedndave on August 28, 2009, 10:00:14 AM
i think there is a console mode program that lets you see what urls are hit
i was playing with this at one time, to get rid of ads from yahoo messenger
with the last 10 or so versions of messenger, i have had to patch the exe file instead
so, i have forgotten how to get the info
one thing you can do is look in your temporary internet files
in the Content.IE5 folder, the urls are given
start by cleaning out the temp int files using internet options
then go in and physically clean it out - many non-indexed files get left behind
leave the favicons alone - they are desirable
then, fire up the game wait for it to load - and exit
go back into Content.IE5 and see which urls the ads came from
Title: Re: Elevated privileges and vista/win7
Post by: sinsi on August 28, 2009, 10:10:36 AM
Nah, the game connects to an ip (url or address, dunno) and downloads .png files - these are the 'ads' in the game world itself (billboards), not webpage ads.

The thing that pisses me off is that i specifically made rules in windows firewall that explicitly block the program - inbound and outbound. It still gets through.
What the f**k does 'DENY ALL' mean then? *grumble*
Title: Re: Elevated privileges and vista/win7
Post by: dedndave on August 28, 2009, 10:21:56 AM
lol
well - if you look in the temp internet files, you will see the png files
if you look specifically in Content.IE5 folder, you can see the urls
trust me - lol
Title: Re: Elevated privileges and vista/win7
Post by: sinsi on August 28, 2009, 10:46:08 AM
I thought if you used sockets it didn't touch the IE cache.

Anyway, in win7 I can't even get into my 'local settings' dir - SYSTEM owns it and ain't letting go of it  :bdg
No big deal.
Title: Re: Elevated privileges and vista/win7
Post by: dedndave on August 28, 2009, 03:00:29 PM
that would bug the shit out of me - lol
i would be finding a work-around real quick
otherwise, the left-overs in the temp-internet-files will suck up all your drive space
i would either find a way to log in as "System", or i would find the right button to mash that changes permission for that folder
Title: Re: Elevated privileges and vista/win7
Post by: Tedd on August 29, 2009, 11:40:14 AM
Presumably, the main program launches another app to do the actual downloading of billboard images. So, you're blocking the main app, but not the one that actually does the downloading - hence it doesn't get blocked.
You might have to do some digging, but if it's dynamically unpacked (randomly generated filename) then it won't be pretty.
Title: Re: Elevated privileges and vista/win7
Post by: BlackVortex on August 30, 2009, 02:25:03 AM
Having trouble with the firewall, huh ?

On my Win7 64bit I use Windows 7 Firewall Control :
http://www.sphinx-soft.com/Vista/order.html

Ultra light-weight !

Just set your rules and nothing goes through. The windows firewall doesn't fit my needs.
Title: Re: Elevated privileges and vista/win7
Post by: GregL on August 30, 2009, 03:13:54 AM
Quote from: sinsiIf I start another process from my elevated one, is the new one elevated as well?

I think so, but I'm not sure, it's been over a year since I worked with that UAC stuff.

The following is some good information about it:

  Inside Windows Vista User Account Control (http://technet.microsoft.com/en-us/magazine/2007.06.uac.aspx)

Title: Re: Elevated privileges and vista/win7
Post by: sinsi on August 30, 2009, 03:56:09 AM
BlackVortex: unfortunately, the game takes even longer to load :(
Greg: yes, the child inherits the parent user token.
Title: Re: Elevated privileges and vista/win7
Post by: dedndave on August 30, 2009, 07:42:10 AM
yah - i have a friend that uses vista 64-bit
we were working on a program together
he opened the console with "run as administrator"
then ran the console app - it ran as admin
Title: Re: Elevated privileges and vista/win7
Post by: FORTRANS on August 30, 2009, 01:22:28 PM
Hi,

   Probably a dumb question, but what happens if you
turn off the modem/router or unplug the cable?

Curious,

Steve N.
Title: Re: Elevated privileges and vista/win7
Post by: sinsi on August 30, 2009, 09:53:11 PM
No cable to unplug, I'm using wireless. If I turn the router off, the other 2 computers in the house won't have internet...