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 ...
-
21st January 2010, 02:52 PM #1 "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.
-
-
IDG Tech News
-
21st January 2010, 03:02 PM #2 @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.
-
-
21st January 2010, 03:05 PM #3
-
-
21st January 2010, 03:17 PM #4 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.
-
-
21st January 2010, 03:23 PM #5 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
-
-
21st January 2010, 03:35 PM #6 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
-
Thanks to box_l from:
storkyIV (21st January 2010)
-
21st January 2010, 03:58 PM #7 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?
-
-
21st January 2010, 04:08 PM #8 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!!!
-
-
21st January 2010, 04:12 PM #9 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)
-
-
21st January 2010, 05:02 PM #10 Fixed it myself - quotes in strings need to be doubled, "" to appear. At the beginning of a string you'll need """
-
-
21st January 2010, 05:40 PM #11 
Originally Posted by
box_l
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!
-
-
21st January 2010, 07:40 PM #12 no problem!
-
-
25th January 2010, 10:25 AM #13 May i also recomend encoding this to a VBE , so no one can see the account details
-
-
25th January 2010, 03:52 PM #14 i do mate, see my post at the bottom of the page
convert vbs to exe
BoX
-
-
27th January 2010, 10:39 PM #15 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:
Similar Threads
-
Replies: 3
Last Post: 11th September 2009, 09:01 AM
-
By m2d2 in forum MIS Systems
Replies: 2
Last Post: 28th December 2007, 09:54 PM
-
By Grommit in forum Windows
Replies: 4
Last Post: 4th September 2007, 12:33 PM
-
By _Bat_ in forum Windows
Replies: 8
Last Post: 6th July 2007, 09:42 AM
-
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
-
Forum Rules