1
votes

I'm trying to open a command prompt as Administrator AND run a .VBS file using CScript.

I found post for running cmd as Administrator:

Shell "powershell.exe -Command " & Chr(34) & "Start-Process cmd -Verb RunAs", vbNormalFocus

Also Found a post for running a VBS file:

SFilename = "Cscript " & Chr(34) & "C:\Temp\Run.vbs " & Chr(34) & " " & pParam1 & " " & pParam2

Shell SFilename, vbNormalFocus

However, Can someone help me to get both things done in single cmd window?

I tried merging both Shell statments and running one after the other but no luck.

1
Set oShell = CreateObject("Shell.Application"): oShell.ShellExecute "cscript.exe", "//nologo c:temp\run.vbs", , "runas", 1 change to for cmd oShell.ShellExecute "cmd.exe", "/k cscript //nologo c:temp\run.vbs", , "runas", 1user6017774
Awesome!! This works like a charm!! Thanks @NoodlesYogesh

1 Answers

0
votes

Copying @Noodles answer in order to mark this question as answered:

Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "cscript.exe", "//nologo c:temp\run.vbs", , "runas", 1 

or for cmd

oShell.ShellExecute "cmd.exe", "/k cscript //nologo c:temp\run.vbs", , "runas", 1