-1

I have a vbscript file that has a username and password input box in it's own window with an OK and Cancel button stacked upon each other. When the user clicks OK to submit the password, I want a new file to open. Here's my code:

set objShell = WScript.CreateObject("WScript.Shell")

strUserName = inputBox("Username")
strPassword = inputBox("Password")
objShell.Run "runas /user:" & strUserName & " ""wscript.exe c:\path\myscript.vbs"" "

Can anybody help me?

If I replace the last line of code, when you click OK, the program closes and nothing happens. The current code opens a command prompt window with the title "C:\Windows\System32\runas.exe" and it just says enter the password for (username you typed) : ex Enter the password for dog :. Whenever you press enter, it closes.

  • Stop asking for `strPassword` separately and type it into the runas prompt that appears. That's the same amount of typing. – GSerg Oct 31 '22 at 00:13
  • Does this answer your question? [Is it possible to run a command headlessly (in a bat script) as another user on Windows?](https://stackoverflow.com/q/14862230/11683) – GSerg Oct 31 '22 at 00:15

1 Answers1

-3

I hope someone more knowledgeable than me answers your question. But in case no one does, here is my take.

I usually find myself pulling my hair out trying to figure out where to put the right number of double quotes, which (speaking from ignorance and therefore with great authority) I bet is why you're experiencing a problem.

So to avoid all that, I suggest either making wscript.exe a default in your system or putting the "wscript.exe c:\path\myscript.vbs" into a .cmd file that the left side of your script runs as an administrator. I bet that either approach will work. Let me know if it doesn't.

Btw, I have sometimes used a subroutine or function that creates a temporary .cmd file which the administrator shell then runs. I hope this helps.

Marc B. Hankin
  • 771
  • 3
  • 15
  • 31