Script Center > Scripting Forums > The Official Scripting Guys Forum! > How to run VBScript with local administrator permissions
Ask a questionAsk a question
 

AnswerHow to run VBScript with local administrator permissions

  • Tuesday, August 25, 2009 9:21 AMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    How to run the following script with local administrator permissions?

    Set oShell = CreateObject("Wscript.Shell")
    test = "CMD /c POWERCFG /X " & Chr(34)&"Alltid på"&Chr(34) & " /monitor-timeout-ac 0"
    oshell.Run test, 0

    I have tryed with an GPO but it only works if the user is admin:(
    • Edited bytp_tp Tuesday, August 25, 2009 9:24 AM
    •  

Answers

  • Friday, September 04, 2009 9:14 PMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I solved the problem by making the changes in registry with a VBScript.
    Made a .exe of the script that runs automaticly as an Domain User With Admin Rights.
    It makes changes in HKU insted of HKCU.

    • Marked As Answer bytp_tp Friday, September 04, 2009 9:14 PM
    •  

All Replies

  • Tuesday, August 25, 2009 10:54 AMperhof Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You could use it with a GPO if you run it as a startup script under computer configuration instead of a logon script under user configuration.
    Startup scripts run under the local system account which has administrative rights.
  • Tuesday, August 25, 2009 10:57 AMShuvava Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If you apply GPO to Mashne policy, then script will runing as SYSTEM account.
  • Tuesday, August 25, 2009 11:13 AMShuvava Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    or you can usage
    Set oShell = CreateObject("Wscript.Shell")
    test = "runas /user:wcfc\testuser cmd < input.txt"
    oshell.Run test, 0

    where input.txt - i's file whis password.

  • Tuesday, August 25, 2009 11:20 AMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    i tryd to run it under computer configuration but it din´t work at all.
    Is thera a way to give users permission to powercfg.exe with a GPO, can that help?
  • Tuesday, August 25, 2009 11:22 AMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    do i need to have the password in an tex file?
  • Tuesday, September 01, 2009 7:27 PMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You could use it with a GPO if you run it as a startup script under computer configuration instead of a logon script under user configuration.
    Startup scripts run under the local system account which has administrative rights.

    It das't work under computer configuration, It writes to HLCU and must therfore be rur as an logon script.
    It wont work to run the script as an local admin because then the chanes will e made in local admins HKCU(profile) and not the logged on users profile.

    How can I make this work?
  • Tuesday, September 01, 2009 8:26 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi tp_tp,

    What operating system are you trying to make this work on?

    Bill
  • Tuesday, September 01, 2009 10:03 PMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi tp_tp,

    What operating system are you trying to make this work on?

    Bill

    Im trying to do it on XP klients.
    Im trying to modify and create keys under HKEY_CURRENT_USER\Control Panel\PowerCfg.
  • Tuesday, September 01, 2009 11:36 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi tp_tp,

    That's what I expected you to say...I don't have a good answer other than to use a power management tool such as EZ_GPO.

    Regards,

    Bill
  • Wednesday, September 02, 2009 1:20 PMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi tp_tp,

    That's what I expected you to say...I don't have a good answer other than to use a power management tool such as EZ_GPO.

    Regards,

    Bill

    i have tryed to use EZ_GPO but it dont work on our klients.
    get som error on login.

    EZ_GPO is nor an option!
  • Wednesday, September 02, 2009 2:30 PMAbqBillModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sorry tp_tp, EZ_GPO is the only (free) way, that I know of, to do power management configuration through a GPO for XP clients (at least with a Server 2003 domain). I don't know what "some error on login" means, but I have found they do read and respond to trouble e-mails.

    Regards,

    Bill
  • Friday, September 04, 2009 9:14 PMtp_tp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I solved the problem by making the changes in registry with a VBScript.
    Made a .exe of the script that runs automaticly as an Domain User With Admin Rights.
    It makes changes in HKU insted of HKCU.

    • Marked As Answer bytp_tp Friday, September 04, 2009 9:14 PM
    •  
  • Tuesday, November 03, 2009 10:45 PMMtheriault Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello

    I think i got a similar problem, could you give more detail on how you resolve the problem

    I'm not a programmer and i got confuse.

    I'm trying to start an apllcation from a shell command line in Excel.  Work well with application that as not the "start as administrator" option

    Martin