none
I am trying to stop a service and than start again with admin user running from a standard user account RRS feed

  • General discussion

  • As in the title I am trying to run a script from a standard user account but to act as admin. Here is the script:

    strComputer = "."
    strUser = "xxxxx.xxxxx"
    strPassword = "xxxx"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    ' Obtain an instance of the the class 
    ' using a key property value.
    Set objShare = objWMIService.Get("Win32_Service.Name='Spooler'")

    ' no InParameters to define

    ' Execute the method and obtain the return status.
    ' The OutParameters object in objOutParams
    ' is created by the provider.
    Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='Spooler'", "StopService")

    ' List OutParams
    Wscript.Echo "Out Parameters: "
    Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

    WScript.Sleep(1500)


    strComputer = "."
    strUser = "xxxxx.xxxxxx"
    strPassword = "xxxxxx"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    ' Obtain an instance of the the class 
    ' using a key property value.
    Set objShare = objWMIService.Get("Win32_Service.Name='Spooler'")

    ' no InParameters to define

    ' Execute the method and obtain the return status.
    ' The OutParameters object in objOutParams
    ' is created by the provider.
    Set objOutParams = objWMIService.ExecMethod("Win32_Service.Name='Spooler'", "StartService")

    ' List OutParams
    Wscript.Echo "Out Parameters: "
    Wscript.echo "ReturnValue: " & objOutParams.ReturnValue

    When I run the script i get value 2 (access denied)

    I tried to make it exe with vbs editor and run it with my user and password (you have that option to be built in the exe file) and I got the error 740 this operation requires elevation.

    I am administrator on that station but with my domain user not with the local one. I have tried even to put another line: strDomain before strUser same errors. On that machine is running win 10.

    Please help me tell me what am I doing wrong. Thank you in advance.

     

    Monday, April 8, 2019 3:19 PM

All replies

  • You cannot allow a user to act as an admin.  The user must run the script as an admin using "RiunAs".

    You should not be using VBScript. It is obsolete and not worth learning. If you want to learn Windows and how to script start with PowerShell.


    \_(ツ)_/

    Monday, April 8, 2019 3:41 PM
  • Hi there, for that service I prefer to let the user to act as admin as long they wont see nothing else than an exe file. I have a few station with many print jobs I don't want to wake up every night at 2 am to restart a service witch is not on server. 
    Monday, April 8, 2019 10:09 PM
  • If you have to restart this service on a regular base use a scheduled task.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Monday, April 8, 2019 10:20 PM
  • First fix the problem that is causing this.  You can also tell the user to restart the PC.

    Making the user an admin is just foolish.

    You can add the user to a spooler queue as an print admin and then they can manage the queue.

    I recommend that you contact someone trained in Windows administration to help you fix this.


    \_(ツ)_/

    Monday, April 8, 2019 10:59 PM