Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:07:58+00:00 2026-06-14T09:07:58+00:00

I have a batch script: test.bat echo first arg is %1 pause That I

  • 0

I have a batch script:

test.bat

echo first arg is %1
pause

That I want to invoke from a vbscript with admin rights like so:

test.vbs

Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "test.bat", "argument", "", "runas", 1

This works ok but I am unable to pass a path argument that contains spaces as a single argument. Basically, I need to enclose the argument in spaces but whatever I try, it doesn’t work. It looks like it invokes the batch, but the cmd window just flashes up and disappears so I don’t know what is going wrong.
I’ve tried:

UAC.ShellExecute "test.bat", """has spaces""", "", "runas", 1

and

UAC.ShellExecute "test.bat", Chr(34) & "has spaces" & Chr(34), "", "runas", 1

and

UAC.ShellExecute "test.bat", '"has spaces"', , "runas", 1

and

UAC.ShellExecute "cmd", "/c test.bat " & chr(34) & "has spaces" & chr(34), "", "runas", 1

But no luck. Any suggestions what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:07:59+00:00Added an answer on June 14, 2026 at 9:07 am

    The way to get this working is:

    UAC.ShellExecute "cmd", "/c """"c:\test.bat"" ""has spaces""""", "", "runas", 1
    

    The important thing to note when using runas to invoke admin user rights, is that the working directory will change to c:\windows\system32. Therefore, you need to specify the full path to the batch file so that it can be found.

    I’m still not sure why this only works when passing the bat file as an argument to "cmd", rather than executing it directly.

    All credit due to Alex K, from the comments.

    In this case you need to quote the entire set of arguments to cmd, and each of the arguments also. You also need to double up the quotes. It looks a bit mad, but this is the best solution because otherwise it will fail if you have a space in any arguments and the bat file path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a batch script that looks like this: Test.bat @echo off :: Starts
I have a batch file test.bat to start a powershell script: @pushd C:\myscripts powershell
I have created a script to run a test script on a batch of
I have a batch script that outputs a file, and I'm trying to ensure
I have a batch script that calls a process and currently it waits for
I have a batch script that checks if a registry key exists and if
I have a batch script that takes any number of arguments (list of files)
I have the following problem. I got a bat file that runs testcomplete test.
I have written a small batch script which copies files from the a folder
I have a test powershell V2 script that looks like this: function test_args() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.