Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: run as in VBS  (Read 15311 times)

0 Members and 1 Guest are viewing this topic.

wbrost

    Topic Starter


    Intermediate
  • Thanked: 11
    run as in VBS
    « on: December 05, 2008, 06:54:05 AM »
    I am trying to make a vbs that will prompt for a password and use the run-as command for a specific exe. so far I have this but it keeps giving me issues.

    Code: [Select]
    Option explicit
    Dim oShell
    set oShell= Wscript.CreateObject("WScript.Shell")

    oShell.Run "runas /noprofile /user:[domain\user]  ""[program]"""

    WScript.Sleep 1000

    objShell.SendKeys "PASSWORD"

    objShell.SendKeys "{enter}"

    Wscript.Quit

    I am new to vbs but trying to learn. any help would be awesome.

    thanks,
    Wayne

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: run as in VBS
    « Reply #1 on: December 05, 2008, 11:32:58 AM »
    Don't know your OS, but if you have XP Pro or above you can use the ScriptPW object:

    Code: [Select]
    Set objPassword = CreateObject("ScriptPW.Password")
    WScript.StdOut.Write "Please enter your password:"

    strPassword = objPassword.GetPassword()
    Wscript.Echo
    Wscript.Echo "Your password is: " & strPassword

    If you have access to a XP Pro machine, you can borrow a copy. It will work on any NT OS. File name is ScriptPW.dll. Put in a directory and register: regsvr32 ScriptPW.dll. Note: script must be run with cscript not wscript

    Code: [Select]
    Set oShell= Wscript.CreateObject("WScript.Shell")
    Set objPassword = CreateObject("ScriptPW.Password")
    WScript.StdOut.Write "Please enter your password:"
    strPassword = objPassword.GetPassword()

    oShell.Run "runas /noprofile /user:[domain\user]  ""[program]"""WScript.Sleep 1000
    oShell.SendKeys strPassword
    oShell.SendKeys "{enter}"

    Wscript.Quit

    The code will not work. The sendkeys does not get executed until the runas is complete. Too late to be of any use. Runas requests the password in a new window, by moving the sendkeys prior to the runas, the results are keystrokes sent to a non-existent window.

    You might try this workaround

    Good luck. 8)
    « Last Edit: December 06, 2008, 05:00:06 AM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    edox71

    • Guest
    Re: run as in VBS
    « Reply #2 on: October 13, 2010, 07:06:16 AM »
    Try with next code:


    strComputer = "."
    Set oShell = WScript.CreateObject ("WSCript.shell")
    usuario = "[email protected]"
    clave = "somepasswd"


    ' ejecuta modificacion Zona  en Registro
    WScript.echo "modificando reg"
    netsh1="regedit /s \\prestored.cl\NETLOGON\TZupdate_inv.reg"
    txtDNS1 = "runas /noprofile /user:"& usuario &" """& netsh1 &""""
    oShell.run txtDNS1, 2
    WScript.sleep 1000
    oShell.AppActivate "C:\Windows\system32\runas.exe"
    oShell.SendKeys clave & "{ENTER}"
    WScript.sleep 5000

    ' ejecuta carga de zona en pc
    WScript.echo "refrescando cambios"
    netsh1="cscript \\prestored.cl\NETLOGON\refreshTZinfo.vbs"
    txtDNS1 = "runas /noprofile /user:"& usuario &" """& netsh1 &""""
    oShell.run txtDNS1, 2
    WScript.sleep 1000
    oShell.AppActivate "C:\Windows\system32\runas.exe"
    oShell.SendKeys clave & "{ENTER}"
    WScript.sleep 5000

    WScript.Quit