+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
Scripts Thread, "Run as" VB Script in Coding and Web Development; Hi guys, I have a very annoying issue (either that or I'm being blonde!) I am trying to run this ...
  1. #1
    storkyIV's Avatar
    Join Date
    Oct 2008
    Location
    Bristol
    Posts
    41
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    "Run as" VB Script

    Hi guys,

    I have a very annoying issue (either that or I'm being blonde!)
    I am trying to run this script to map part of a piece of software to teacher laptops, however the script doesn't work and I can't see where I am going wrong, even after changing certain parts of it.

    Does anything look wrong with this?

    set WshShell = CreateObject("WScript.Shell")

    WshShell.Run "runas /user:exambase""\\hge-apps01\Packages\ExamWizard\Button_B.exe"""

    WScript.Sleep 1000

    WshShell.Sendkeys "Password1~"

    WScript.Quit


    Basically, the cmd prompt will appear, then within seconds a few lines of txt will appear and close the window before I can see what it says.

    Any help would be appreciated.

  2. #2

    bossman's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    3,914
    Thank Post
    1,189
    Thanked 1,063 Times in 754 Posts
    Rep Power
    329
    @storkyIV:

    Just to allow you to see what the cmd prompt is doing you could increase the sleep time to say 50000 which would be 50 seconds in essence. this might help you pin point what is actually happening.

  3. #3
    storkyIV's Avatar
    Join Date
    Oct 2008
    Location
    Bristol
    Posts
    41
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by bossman View Post
    @storkyIV:

    Just to allow you to see what the cmd prompt is doing you could increase the sleep time to say 50000 which would be 50 seconds in essence. this might help you pin point what is actually happening.
    Thanks Bossman. that was the 1st thing that I thought of - but it makes no difference. The cmd line flashes up, and i under a second disappears again!

  4. #4
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    181
    Thank Post
    18
    Thanked 37 Times in 29 Posts
    Rep Power
    20
    What you could do is bring up command prompt and try to run the script from there, that will leave the command prompt open after the script has finished. Thats what I do for debugging.

  5. #5
    soveryapt's Avatar
    Join Date
    Jan 2009
    Location
    Lancashire
    Posts
    2,402
    Thank Post
    648
    Thanked 277 Times in 244 Posts
    Rep Power
    78
    I don't know if it's of any use, but here is a "Run As" script I've pinched and hacked at to get it to run some flippin French software that refuses to just run under normal user conditions. You might be able to use something from it possibly?

    Code:
    Set WshShell=WScript.CreateObject("WScript.Shell")
    
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set Drives = FileSystemObject.Drives
    For Each DiskDrive in Drives
        DriveLetter = DiskDrive.DriveLetter
        DriveType = DiskDrive.DriveType
    
        If DriveType = "CD-ROM Drive" Then
    	CDDrive = DriveLetter
    	Exit For
        End If        
    Next
    
    Set Drives = nothing
    Set FileSystemObject = nothing
    
    strCmd="FileToRunAs.exe"
    strUser="YOURDOMAIN\UserToRunAs"
    strPass="P455W0RD!"
    set WshShell=CreateObject("WScript.Shell")
    WshShell.Run "runas.exe" & " /u:" & strUser & " " & CDDrive & strCmd
    WScript.Sleep 1000
    WshShell.Sendkeys strPass & "~"
    It's probably more the bottom part you would be interested in as the top part simply looks to see which what letter the CD Drive is.

    If I can help any from it, I'll do my best, but it's something I've found and hacked around a bit more than wrote from the bottom up!

    Andy

  6. #6
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    429
    Thank Post
    68
    Thanked 90 Times in 75 Posts
    Rep Power
    61
    Code:
    set WshShell = CreateObject("WScript.Shell")
    
    WshShell.Run "runas /user:administrator@******.hereford.sch.uk ""<unc path here>"""
    
    WScript.Sleep 1000
    
    WshShell.Sendkeys "**********~"
    
    WScript.Quit()
    mine is identical to yours.. pinched fron the testbase install!

    however, i have the full user@domain and a space at the end of the domain before the double quotes.

    i suspect the missing space is the issue.

    I hope this helps.

    BoX

  7. Thanks to box_l from:

    storkyIV (21st January 2010)

  8. #7
    Mr.Ben's Avatar
    Join Date
    Jan 2008
    Location
    A Pirate Ship
    Posts
    942
    Thank Post
    182
    Thanked 157 Times in 126 Posts
    Blog Entries
    2
    Rep Power
    65
    How would you do this and pass a switch command?

    Here's my script (It's to set a default pdf reader)

    On Error Resume Next
    strCmd="C:\PROGRA~1\FOXITS~1\FOXITR~1\FOXITR~1.EXE -register"
    strUser="me@there.local"
    strPass="Password"
    set WshShell=CreateObject("WScript.Shell")
    WshShell.Run "runas.exe" & " /user:" & strUser & " " & strCmd
    WScript.Sleep 1000
    WshShell.Sendkeys strPass & "~"

    The command works from the command line as

    runas.exe /user:me@there "C:\PROGRA~1\FOXITS~1\FOXITR~1\FOXITR~1.EXE -register"

    But I can't pass the quote marks in the script, how would I do that?

  9. #8
    storkyIV's Avatar
    Join Date
    Oct 2008
    Location
    Bristol
    Posts
    41
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Ok,

    I can run the script on a machine that I am logged onto if I remove the run as and send keys statements from the script, so it is definately those eliments that are causing me grief!!!

  10. #9
    soveryapt's Avatar
    Join Date
    Jan 2009
    Location
    Lancashire
    Posts
    2,402
    Thank Post
    648
    Thanked 277 Times in 244 Posts
    Rep Power
    78
    Try putting the .exe on the end of the runas so your script is something like follows:

    Code:
    Set WshShell=WScript.CreateObject("WScript.Shell")
    
    strCmd="\\hge-apps01\Packages\ExamWizard\Button_B.exe"
    strUser="exambase"
    strPass="P455W0RD!"
    set WshShell=CreateObject("WScript.Shell")
    WshShell.Run "runas.exe" & " /u:" & strUser & " " & strCmd
    WScript.Sleep 1000
    WshShell.Sendkeys strPass & "~"
    Dunno if that will work or not (obviously set the password to whatever your password is and if it's a domain user, make sure you call it using the standard DOMAIN\User call instead of just the username - this is because just the username looks for a local user on that machine, and not a user on the network)


  11. #10
    Mr.Ben's Avatar
    Join Date
    Jan 2008
    Location
    A Pirate Ship
    Posts
    942
    Thank Post
    182
    Thanked 157 Times in 126 Posts
    Blog Entries
    2
    Rep Power
    65
    Fixed it myself - quotes in strings need to be doubled, "" to appear. At the beginning of a string you'll need """

  12. #11
    storkyIV's Avatar
    Join Date
    Oct 2008
    Location
    Bristol
    Posts
    41
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by box_l View Post
    Code:
    set WshShell = CreateObject("WScript.Shell")
    
    WshShell.Run "runas /user:administrator@******.hereford.sch.uk ""<unc path here>"""
    
    WScript.Sleep 1000
    
    WshShell.Sendkeys "**********~"
    
    WScript.Quit()
    mine is identical to yours.. pinched fron the testbase install!

    however, i have the full user@domain and a space at the end of the domain before the double quotes.

    i suspect the missing space is the issue.

    I hope this helps.

    BoX
    Thank you very very much!
    That was it - finally!

    Cheers!

  13. #12
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    429
    Thank Post
    68
    Thanked 90 Times in 75 Posts
    Rep Power
    61
    no problem!


  14. #13

    Join Date
    Dec 2009
    Posts
    607
    Thank Post
    8
    Thanked 36 Times in 34 Posts
    Rep Power
    17
    May i also recomend encoding this to a VBE , so no one can see the account details

  15. #14
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    429
    Thank Post
    68
    Thanked 90 Times in 75 Posts
    Rep Power
    61
    i do mate, see my post at the bottom of the page

    convert vbs to exe

    BoX

  16. #15
    superfletch's Avatar
    Join Date
    Nov 2007
    Location
    South
    Posts
    434
    Thank Post
    146
    Thanked 77 Times in 61 Posts
    Rep Power
    31
    This seems to have been solved now but I had a very similar problem recently and it was a GPO not permitting me to access shared resources on the same server using more than one set of login credentials.

    Basically I had a mapped drive setup with my login, then I was trying to map another share using Runas with a different account.

    It wouldn't let m use two acccounts in the same session for mapped drives.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 11th September 2009, 09:01 AM
  2. Replies: 2
    Last Post: 28th December 2007, 08:54 PM
  3. NTBackup doesn't seem to have a "Run Now" cmd
    By Grommit in forum Windows
    Replies: 4
    Last Post: 4th September 2007, 12:33 PM
  4. Replies: 8
    Last Post: 6th July 2007, 09:42 AM
  5. Replies: 6
    Last Post: 28th September 2006, 07:06 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •