Run section of vbscript code with elevated privilages

Posted on 2006-04-12
Last Modified: 2010-05-18
Hope this is in the right topic area, couldn't see one dedicated to vbscript.  I've been asked to add the following code to our logon script to disable microsoft firewall on all clients.

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
objPolicy.FirewallEnabled = FALSE

This code runs fine as an administrator but users unsuprisingly get a permission denied error.  My question is this, can I run these 3 lines of code as an administrator?  I want all other code in the script to run as the logged in user.  

Many Thanks
Question by:bon3s
    LVL 6

    Accepted Solution

    Maybe you can make these three lines as another script and run it as a startup script instead of a logon script.  Check this for push in the right direction:

    Hope this helps!


    Author Comment

    Thanks Taconvino, although this doesn't directly answer my question (I assume it cannot be done?), your solution is actually a far better way to do this.  Much better than having administrator username and password hard coded in the script.  I would have encrypted it, but still they're easy enough to unencrypt so it would have been a concern.

    Much appreciated.
    LVL 6

    Expert Comment

    You are very much welcome!  

    I'm not sure if this can be done or not... using RunAs is not an option, and I can't think of any other way.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now