Question

VB6: How to temporarily elevate to administrator privileges

Asked by: ttobin333

Dear Experts,

My VB6 program needs to access the internet to register its license when running in standard user mode. How can I get Windows Vista to ask for administrator approval with the standard dialog box for this operation and then return to standard user privileges right afterward?

Thanks!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-27 at 18:55:19ID24849534
Tags

VB6

,

administrator

,

privileges

Topic

Visual Basic Programming

Participating Experts
3
Points
500
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. VB6 application is not running on Vista
    Our VB6 application is not running on Vista. We believe we've localized the problem to 'DBGrid32.ocx' Microsoft claims they support 'DBGrid32.ocx' in Vista but do not install it. We are installing DBGrid32.OCX version 5.1.81.4 (514 MB, 6/26/1998). Our VB6 environment has...
  2. Is it possible to elevate a program once it is already running …
    Because of a 3rd party software we incorporate we need to write the Registration Code to unlock it to the HKEY_LOCAL_MACHINE portion of the registry so it's available for all users. And this needs to be done when the user is running after they purchase it as opposed to durin...
  3. VB6 application in Vista
    When I compile my VB6 program, will it run on a Windows Vista platform? Has anyone run into any problems?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BrianGEFF719Posted on 2009-10-28 at 03:12:57ID: 25681447

I believe that you have to take an action that requires administrator privileges and windows will issue the authentication request automatically.

 

by: ttobin333Posted on 2009-10-28 at 11:40:52ID: 25686732

Here's the problem: when the program tries to connect to the internet, Windows does not ask for admin approval, but the connection is blocked.  This is not a problem when logged in with admin privileges.  

 

by: egl1044Posted on 2009-11-01 at 10:37:10ID: 25714788

 

by: ttobin333Posted on 2009-11-05 at 19:34:19ID: 25756411

Thanks egl1044!  I'm going to give it a try.

 

by: egl1044Posted on 2009-11-05 at 19:49:44ID: 25756473

Uploaded the set of tools created to assist with elevations.
http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=7778

 

by: ttobin333Posted on 2009-11-09 at 06:23:24ID: 25776113

Thanks! Will test it out tonight!

 

by: ttobin333Posted on 2009-11-11 at 21:42:49ID: 25801789

Very sorry for delay--will complete testing within 1 day.

 

by: ttobin333Posted on 2009-11-12 at 22:05:18ID: 25811718

egl1044, this looks like exactly what I need, but I could use some guidance in putting it together.

Can I use any GUID value that the generator you supplied creates?

I have never used COM objects...can you provide some additional guidance for a beginner?

Thanks!

 

by: egl1044Posted on 2009-11-13 at 06:00:05ID: 25813887

Hi ttobin333,

Yes choose any GUID value but make sure you don't change it after you install the registry locations.

When you create ActiveX.dll it has some static information that won't change after compiling. I recommend that when you are ready for deployment make a (release) build by changing the compile options for the activex.dll to (binary compatability) after you compile use the COM dumper to get the CLSID,IID. It's important that these values will never change and will be the same on every system (binary compatability) makes sure this happens.

What you place within the activex.dll is your administrative tasks. This is anything that needs to be run as administrator to work.
The simplest example of this would be trying to create a file on the ROOT drive of C:\ etc..

To make things easier for you and not get to much into classes you can think of the class.cls as a module where some restrictions apply. The basic concept here is to know which operations you will perform that require administrative access and add these to that class instead of your main process.

The only mis-leading part about this whole elevation process is installing the registry locations during the install process. In VB6 by default you can't execute code when you register the activex.dll. However in C++ you can add code to the DllRegisterServer stub and whenver you register the C++ dll it will execute the code inside that stub. Because VB6 can't do this you have to make a workaround.

The best options:
1) Create a C++ MFC DLL that it's only purpose is to install these registry locations. You would first register the VB activex.dll then you would register the C++ MFC dll which will install the registry entries required for the VB activex dll.

2) You can create small program that runs as administrator as the final step of the install process that will install these registry locations. This can be as simple as a form that would indicate to the user "To help better your experience on windows Vista such and such application needs install additional information. Click OK to continue.
Keep in mind that the registry entries need to be installed "AFTER" you register the VB activex.dll.

3) You can create a registry script that installs this entries.

As you can see the only downside here is that VB6 can't execute code when the DLL is registered so you have to use one of the above options instead. This isn't to much of a problem if you take a proffesional approach for Option 2. Option 1 may be difficult but is probrably the best although it requires that you know how to call the registry API's in C++.

One thing I left out of the article and I think the project example is that before you actually elevate you should check that the process is running with standard user access token.


Now before we go any further it's prob a good idea to see what is failing on your side. It's possible you don't need to use any of this and that your download fails because you are being denied access to that folder location. For this purpose it's recommended that all files be placed in Application Data because even standard user can read/write at this location. It's only specific tasks that should really be put into place using this method on vista.


Remember that these entire steps are targeted towards working with UAC under vista and your application should be responsible for determine the OS version act accordingly. ex..
If XP OS use impersonations if user running as standard user.

The small example snippet attached is what it should really look like for application calls.

Dim MyTask As AdminTask
  
  '// Before you elevate first check if it's required!
  If VistaTasks.IsProcessRunningAsAdmin Then
  
    '// We don't need to elevate we can do the task!
    MyTask.CreateFileRoot
    
  Else
  
    '// We must elevate the process role is not administrator.
    
    If VistaTasks.CoCreateInstanceAsAdmin(Me.hWnd, _
        "{55CC8F68-356E-45E7-91EE-062C8D909E77}", _
        "{477D2A0F-3B5D-4AB2-937C-5E663BE66C57}", _
        MyTask) = 0 Then   '//S_OK
        
      '// run the admin task!
      MyTask.CreateFileRoot
      
    End If
    
    
  End If
  
  '// de-reference
  If Not MyTask Is Nothing Then
    Set MyTask = Nothing
  End If

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:

Select allOpen in new window

 

by: ttobin333Posted on 2009-11-13 at 21:58:49ID: 31646761

Thanks!

 

by: egl1044Posted on 2009-12-09 at 06:06:10ID: 26008270

ttobin333.

I would like to update you with a VB.NET version if you ever decide to move to VB.NET or already have done so for some projects.
http://www.experts-exchange.com/articles/Programming/Languages/.NET/Visual_Basic.NET/VB-NET-Vista-COM-Elevation.html

-egl

 

by: LukeBPosted on 2010-04-26 at 19:02:41ID: 32218033

HI egl1044

I need some help to implement this in Acc2007 on a Win7 box, can you assist? I can open another Q, I need step by step intrux on how to use your vistauac.zip for Acc2007.

The problem I am having is with CreateObject in Acc2007 VBA code:

Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")

I get the 'requested operation requires elevation' msg

 

by: LukeBPosted on 2010-04-27 at 16:07:16ID: 32318386

 

by: egl1044Posted on 2010-04-27 at 21:00:19ID: 32332196

Hi, LukeB

This won't work with what I think your trying to do.... It's for implementing COM elevation in your own COM/ActiveX dll's you compile. The reason it will fail is because there is strict requirments of registering the COM class for elevation something that you don't have control over with excel automation.

If you are using macros from within excel then I don't see a way around this unless you elevate the application itself using Run As Admin. However if you have access to VB6 where you can compile into an executable you "should" be able to elevate your process and use excel automation using early binding.

I recently removed all elevation articles for revision. I am in the process of re-working elevation into a toolkit for VB and .NET but there is no specific time frame when that will be finished.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...